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?
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.
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 ...
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) { ... }
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>
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){}
@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.
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) { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With