Avatar of ucohockey
ucohockey
 asked on

collapse in & collapse

I have a collapsible div that I want open when someone is viewing on a desktop but when on smaller mobile device I want the div to be collapsed. I'm using the code below.

   <div class="col-xs-3">
			<div class="panel panel-default">
				<div class="panel-heading" data-toggle="collapse" data-target="#demo">
					<h3 class="panel-title">Panel 1</h3>
				</div>
				<div id="demo" class="panel-body collapse in">
                   box 1
				</div>
			</div>
		</div>
<div class="col-xs-3">
			<div class="panel panel-default">
				<div class="panel-heading" data-toggle="collapse" data-target="#demo1">
					<h3 class="panel-title">Panel 1</h3>
				</div>
				<div id="demo1" class="panel-body collapse in">
                   box 1
				</div>
			</div>
		</div>

Open in new window

CSSWeb FrameworksResponsive WebBootstrap

Avatar of undefined
Last Comment
Pravin Asar

8/22/2022 - Mon
Pravin Asar

Are you using jquery ?
ucohockey

ASKER
No, trying to just the collapse in & collapse in bootstrap.
Pravin Asar

<!DOCTYPE  html>
<html >
      <head>
            <title>Test</title>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
      </head>
      <body>
<div class="col-xs-3">
      <div class="panel panel-default">
            <div class="panel-heading" data-toggle="collapse" data-target="#demo" onclick='$("#demo").toggle()'>      
                  <h3 class="panel-title">Panel 1</h3>
            </div>
            <div id="demo" class="panel-body collapse in">
                  box 1
            </div>
      </div>
</div>
<div class="col-xs-3">
      <div class="panel panel-default">
            <div class="panel-heading" data-toggle="collapse" data-target="#demo1" onclick='$("#demo1").toggle()'>
                  <h3 class="panel-title">Panel 2</h3>
            </div>
            <div id="demo1" class="panel-body collapse in">
                  box 2
            </div>
      </div>
</div>
</body>
</html>
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Pravin Asar

okay. Set the class

class="panel-collapse collapse"
Pravin Asar

Here is complete example. Should work well with mobile devices.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  </head>
  <body>
        <div class="panel-group col-xs-12" id="accordion">             
            <div class="col-xs-12">
                  <div class="panel panel-default">
                        <div class="panel-heading" data-toggle="collapse" data-target="#demo2">      
                              <h3 class="panel-title">Panel 1</h3>
                        </div>
                        <div id="demo2" class="panel-body collapse in">
                              box 1
                        </div>
                  </div>
            </div>
            <div class="col-xs-12">
                  <div class="panel panel-default">
                        <div class="panel-heading" data-toggle="collapse" data-target="#demo1">
                              <h3 class="panel-title">Panel 2</h3>
                        </div>
                        <div id="demo1" class="panel-body collapse in">
                              box 2
                        </div>
                  </div>
            </div>
        </div>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
      <script type="text/javascript">
                $(".collapse").collapse();
      </script>
</body>
</html>
ucohockey

ASKER
Thanks for the help but let me see if I can explain a little better. In the code you just sent me works perfect but I want the div to be expanded and when its on a desktop so I used collapse in but then when I go to a smaller screen size I just want the div to be collapse like it would be if you just use collapse.

Thanks for the help.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Pravin Asar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.