Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 3: how to use media queries?

I'm using Bootstrap 3 to build a responsive layout where I want to adjust a few font sizes according to the screen size. How can I use media queries to make this kind of logic?

like image 785
Rui Avatar asked Aug 25 '13 01:08

Rui


People also ask

Can I use media queries with Bootstrap?

Since Bootstrap is developed to be mobile first, we use a handful of media queries to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.

How do I create a media query in Bootstrap?

The general syntax of the media queries in the Bootstrap framework is @media (min-width: ~ breakpoint in pixels here ~) ~ some CSS rules to be applied ~ which narrows the CSS rules defined down to a specific viewport size but eventually the opposite query might be used like @media (max-width: ~ breakpoint in pixels ...

What are the Bootstrap 3 breakpoints?

Small devices (tablets, 768px and up): @media (min-width: @screen-sm-min) { ... } Medium devices (desktops, 992px and up): @media (min-width: @screen-md-min) { ... } Large devices (large desktops, 1200px and up): @media (min-width: @screen-lg-min) { ... }


2 Answers

Bootstrap 3

Here are the selectors used in BS3, if you want to stay consistent:

@media(max-width:767px){} @media(min-width:768px){} @media(min-width:992px){} @media(min-width:1200px){} 

Note: FYI, this may be useful for debugging:

<span class="visible-xs">SIZE XS</span> <span class="visible-sm">SIZE SM</span> <span class="visible-md">SIZE MD</span> <span class="visible-lg">SIZE LG</span> 

Bootstrap 4

Here are the selectors used in BS4. There is no "lowest" setting in BS4 because "extra small" is the default. I.e. you would first code the XS size and then have these media overrides afterwards.

@media(min-width:576px){} @media(min-width:768px){} @media(min-width:992px){} @media(min-width:1200px){} 

Bootstrap 5

@media(min-width:576px){} @media(min-width:768px){} @media(min-width:992px){} @media(min-width:1200px){} @media(min-width:1400px){} 

Update 2021-05-20: Info is still accurate as of versions 3.4.1, 4.6.0, 5.0.0.

like image 189
William Entriken Avatar answered Oct 02 '22 15:10

William Entriken


Based on bisio's answer and the Bootstrap 3 code, I was able to come up with a more accurate answer for anyone just looking to copy and paste the complete media query set into their stylesheet:

/* Large desktops and laptops */ @media (min-width: 1200px) {  }  /* Landscape tablets and medium desktops */ @media (min-width: 992px) and (max-width: 1199px) {  }  /* Portrait tablets and small desktops */ @media (min-width: 768px) and (max-width: 991px) {  }  /* Landscape phones and portrait tablets */ @media (max-width: 767px) {  }  /* Portrait phones and smaller */ @media (max-width: 480px) {  } 
like image 33
Chris Clower Avatar answered Oct 02 '22 16:10

Chris Clower