Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap visible and hidden classes not working properly

I tried to use the Bootstrap visible and hidden classes to create content only visible on mobile/desktop. I noticed the classes weren't working properly (and I have noticed a lot of people had this problem and solved it this way) so I created a mobile stylesheet to set which of the divs to show on mobile.

This is my current code:

<div class="containerdiv hidden-sm hidden-xs visible-md visible-lg">
  <div class="row">
    <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 logo">
    </div>
  </div>
</div>

<div class="mobile">
  test
</div>

Now the .mobile should be visible on mobile screens, 900px width, and smaller. I used the Bootstrap classes for the other div, .containerdiv, and that works so far, but only when I added a value for hidden-xs in my own mobile CSS sheet, like so;

.hidden-xs {
  display:none !important;
}
.mobile {
  display:block !important;
}

The .mobile div should now show up on screens 900px or smaller but it still doesn't. I'm not sure why it doesn't, display:block is the right thing to use right? Adding visible-xs and visible-sm does nothing.

What is the proper way to do this and why is my version not working?

like image 239
Jane Avatar asked Dec 03 '13 15:12

Jane


People also ask

How do I use hidden class in Bootstrap 4?

To hide elements simply use the . d-none class or one of the . d-{sm,md,lg,xl}-none classes for any responsive screen variation.

What is visible MD in Bootstrap?

<h1 class="visible-md">This text is shown only on a MEDIUM screen.</ h1> <h1 class="visible-lg">This text is shown only on a LARGE screen.</ h1>

What is D inline block in Bootstrap?

Use the d-inline-block class to make an element display inline block. Use any of the d-*-inline-block classes to control WHEN the element should be inline block on a specific screen width. Resize the browser window to see the effect. Inline block DIV.


4 Answers

Your .mobile div has the following styles on it:

.mobile {
    display: none !important;
    visibility: hidden !important;
}

Therefore you need to override the visibility property with visible in addition to overriding the display property with block. Like so:

.visible-sm {
    display: block !important;
    visibility: visible !important;
}
like image 200
Graham Langdon Avatar answered Oct 15 '22 03:10

Graham Langdon


No CSS required, visible class should like this: visible-md-block not just visible-md and the code should be like this:

<div class="containerdiv hidden-sm hidden-xs visible-md-block visible-lg-block">
    <div class="row">
        <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 logo">

        </div>
    </div>
</div>

<div class="mobile hidden-md hidden-lg ">
    test
</div>

Extra css is not required at all.

like image 31
Adarsh Gowda K R Avatar answered Oct 15 '22 03:10

Adarsh Gowda K R


Your mobile class Isn't correct:

.mobile {
  display: none !important;
  visibility: hidden !important; //This is what's keeping the div from showing, remove this.
}
like image 27
Jop Avatar answered Oct 15 '22 01:10

Jop


If you give display table property in css some div bootstrap hidden class will not effect on that div

like image 41
simranjit Avatar answered Oct 15 '22 01:10

simranjit