Bootstrap3 .visible-* .hidden-* display inline

CssTwitter BootstrapResponsive DesignTwitter Bootstrap-3

Css Problem Overview


Bootstrap has some nice .visible-* (eg. .visible-lg) class utility for selecting what to show or hide depending on the screen size.

When using those classes, it applies the styling display: block !important; when in the correct screen size.

But sometimes, I'd like to use it for some elements that are displayed inline or inline-block.

How could I cleanly override some bootstrap rules to have the choice? Or should it be a feature request in bootstrap?


EDIT

Seems like I'm not the only one wondering about this issue. Here's the github issue.

Thanks for the latest answer!

Css Solutions


Solution 1 - Css

Update for Bootstrap v3.2.0

This is now natively solved in Bootstrap v3.2.0 with this commit

According to the new responsive classes documentation:

> As of v3.2.0, the .visible-- classes for each breakpoint come in three variations, one for each CSS display property value listed below:

Group of classes          | CSS display
.visible--block         |  display: block;
.visible--inline        |  display: inline;
.visible-*-inline-block  |  display: inline-block;

For example, you could use:

<p>Device is: <span class="visible-lg-inline">Large</span></p>


Other Instances

Asked about on Stackoverflow:

Reported in Bootstrap Issues:

Solution 2 - Css

This has been sort of fixed in v3.1.

.visible-lg or .visible-md will force display: block !important; but using .hidden-xs or .hidden-sm will display inline.

Solution 3 - Css

The following library extends the visible helper classes with inline & inline-block variations:

https://github.com/moappi/bootstrap.inline-responsive

Implements the following:

  • visible-inline-*
  • hidden-inline-*

and

  • visible-inline-block-*
  • hidden-inline-block-*

Solution 4 - Css

Updating to bootstrap 3.1 or above indeed solves the problem as from this point on the hidden- classes only hide the tag and don't set display: block anymore. This way you can use <div> for block context and <span> for inline-block context (the normal behavior of these tags)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAugustin RiedingerView Question on Stackoverflow
Solution 1 - CssKyleMitView Answer on Stackoverflow
Solution 2 - CssPratyushView Answer on Stackoverflow
Solution 3 - CssChad BrownView Answer on Stackoverflow
Solution 4 - Cssdhm80View Answer on Stackoverflow