Mediaquery for bootstrap grid - html

I'm not expert in styling, I'm using bootstap for small projects.
So, my problem is the grid system. I have two monitors, first has 1920x1080 resolution and second has 1366x768.
I want say with mediaquery if the resolution is 1366x768 use the grid system of md not lg
For example I have a div as in the below
<div class="col-lg-9 col-md-6">
....
</div>
div class="col-lg-3 col-md-6">
...
</div>
Is it possible?

In bootstrap3, you can use col-lg class for your devices that are equl to 1200px or more and col-md class for your devices that are equal to 992px or more. Similarly in bootstrap 4 you can use col-lg class for resolution that is equal to 992px and more and col-md class for col-md for 768px or more. You can find full bootstrap grid documentation on its official site https://getbootstrap.com/docs/3.3/css/#overview-container (for bootstrap 3).
In your case im going through boostrap version 3. If you want to use col-md class on resolution of 1366X768 or more obviously you want to use col-lg class on resolution of 1920x1080 or more as you said you have two monitors. If so simply go to customize section of bootstrap official site i.e. https://getbootstrap.com/docs/3.3/customize/ Then scroll down there you will find Media queries breakpoints section. You can customize your own breakpoints from there by simply fill #screen-lg labeled input box with 1920px and #screen-md labeled with 1366px. Now you can go to the bottom of this page then simply click commpile and download button. Now you can use this downloaded bootstrap file that might work for you. Similarly each and every thing you can customize as you want by editing these less variable.

If I understand the question correctly , you can do this with JQuery . Something like this :
if (window.matchMedia('(min-width: 1025px )').matches) {
high.css('height', maxheight - 3);
boxOne.css('height', maxheight);
boxTwo.css('height', maxheight);
boxThree.css('height', maxheight + 23);
}
else if (window.matchMedia('(min-width: 768px) and (max-width: 1024px)').matches) {
high.css('height', maxheight - 11);
boxOne.css('height', maxheight);
boxTwo.css('height', maxheight);
boxThree.css('height', maxheight + 23);
}

Related

Using responsive variations in bootstrap [duplicate]

What is the difference among col-lg-* , col-md-* and col-sm-* in Twitter Bootstrap?
Updated 2020...
Bootstrap 5
In Bootstrap 5 (alpha) there is a new -xxl- size:
col-* - 0 (xs)
col-sm-* - 576px
col-md-* - 768px
col-lg-* - 992px
col-xl-* - 1200px
col-xxl-* - 1400px
Bootstrap 5 Grid Demo
Bootstrap 4
In Bootstrap 4 there is a new -xl- size, see this demo. Also the -xs- infix has been removed, so smallest columns are simply col-1, col-2.. col-12, etc..
col-* - 0 (xs)
col-sm-* - 576px
col-md-* - 768px
col-lg-* - 992px
col-xl-* - 1200px
Bootstrap 4 Grid Demo
Additionally, Bootstrap 4 includes new auto-layout columns. These also have responsive breakpoints (col, col-sm, col-md, etc..), but don't have defined % widths. Therefore, the auto-layout columns fill equal width across the row.
Bootstrap 3
The Bootstrap 3 grid comes in 4 tiers (or "breakpoints")...
Extra small (for smartphones .col-xs-*)
Small (for tablets .col-sm-*)
Medium (for laptops .col-md-*)
Large (for laptops/desktops .col-lg-*).
These grid sizes enable you to control grid behavior on different widths. The different tiers are controlled by CSS media queries.
So in Bootstrap's 12-column grid...
col-sm-3 is 3 of 12 columns wide (25%) on a typical small device width (> 768 pixels)
col-md-3 is 3 of 12 columns wide (25%) on a typical medium device width (> 992 pixels)
The smaller tier (xs, sm or md) also defines the size for larger screen widths. So, for the same size column on all tiers, just set the width for the smallest viewport...
<div class="col-lg-3 col-md-3 col-sm-3">..</div> is the same as,
<div class="col-sm-3">..</div>
Larger tiers are implied. Because col-sm-3 means 3 units on sm-and-up, unless specifically overridden by a larger tier that uses a different size.
xs(default) > overridden by sm > overridden by md > overridden by lg
Combine the classes to use change column widths on different grid sizes. This creates a responsive layout.
<div class="col-md-3 col-sm-6">..</div>
The sm, md and lg grids will all "stack" vertically on screens/viewports less than 768 pixels. This is where the xs grid fits in. Columns that use the col-xs-* classes will not stack vertically, and continue to scale down on the smallest screens.
Resize your browser using this demo and you'll see the grid scaling effects.
This article explains more about how the Bootstrap grid
The bootstrap docs do explain it, but it still took me a while to get it. It makes more sense when I explain it to myself in one of two ways:
If you think of the columns starting out horizontally, then you can choose when you want them to stack.
For example, if you start with columns:
A B C
You decide when should they stack to be like this:
A
B
C
If you choose col-lg, then the columns will stack when the width is < 1200px.
If you choose col-md, then the columns will stack when the width is < 992px.
If you choose col-sm, then the columns will stack when the width is < 768px.
If you choose col-xs, then the columns will never stack.
On the other hand, if you think of the columns starting out stacked, then you can choose at what point they become horizontal:
If you choose col-sm, then the columns will become horizontal when the width is >= 768px.
If you choose col-md, then the columns will become horizontal when the width is >= 992px.
If you choose col-lg, then the columns will become horizontal when the width is >= 1200px.
From Twitter Bootstrap documentation:
small grid (≥ 768px) = .col-sm-*,
medium grid (≥ 992px) = .col-md-*,
large grid (≥ 1200px) = .col-lg-*.
Let's un-complicate Bootstrap!
Notice how the col-sm occupies the 100% width (in other terms breaks into new line) below 576px but col doesn't. You can notice the current width at the top center in gif.
Here comes the code:
<div class="container">
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
<div class="row">
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
</div>
</div>
Bootstrap by default aligns all the columns(col) in a single row with equal width. In this case three col will occupy 100%/3 width each, whatever the screen size. You can notice that in gif.
Now what if we want to render only one column per line i.e give 100% width to each column but for smaller screens only? Now comes the col-xx classes!
I used col-sm because I wanted to break the columns into separate lines below 576px. These 4 col-xx classes are provided by Bootstrap for different display devices like mobiles, tablets, laptops, large monitors etc.
So,col-sm would break below 576px, col-md would break below 768px, col-lg would break below 992px and col-xl would break below 1200px
Note that there's no col-xs class in bootstrap 4.
This pretty much sums-up. You can go back to work.
But there's bit more to it. Now comes the col-* and col-xx-* for customizing width.
Remember in the above example I mentioned that col or col-xx takes the equal width in a row. So if we want to give more width to a specific col we can do this.
Bootstrap row is divided into 12 parts, so in above example there were 3 col so each one takes 12/3 = 4 part. You can consider these parts as a way to measure width.
We could also write that in format col-* i.e. col-4 like this :
<div class="row">
<div class="col-4">col</div>
<div class="col-4">col</div>
<div class="col-4">col</div>
</div>
And it would've made no difference because by default bootstrap gives equal width to col (4 + 4 + 4 = 12).
But, what if we want to give 7 parts to 1st col, 3 parts to 2nd col and rest 2 parts (12-7-3 = 2) to 3rd col (7+3+2 so total is 12), we can simply do this:
<div class="row">
<div class="col-7">col-7</div>
<div class="col-3">col-3</div>
<div class="col-2">col-2</div>
</div>
and you can customize the width of col-xx-* classes also.
<div class="row">
<div class="col-sm-7">col-sm-7</div>
<div class="col-sm-3">col-sm-3</div>
<div class="col-sm-2">col-sm-2</div>
</div>
How does it look in the action?
What if sum of col is more than 12? Then the col will shift/adjust to below line. Yes, there can be any number of columns for a row!
<div class="row">
<div class="col-12">col-12</div>
<div class="col-9">col-9</div>
<div class="col-6">col-6</div>
<div class="col-6">col-6</div>
</div>
What if we want 3 columns in a row for large screens but split these columns into 2 rows for small screens?
<div class="row">
<div class="col-12 col-sm">col-12 col-sm TOP</div>
<div class="col col-sm">col col-sm</div>
<div class="col col-sm">col col-sm</div>
</div>
You can play around here: https://jsfiddle.net/JerryGoyal/6vqno0Lm/
I think the confusing aspect of this is the fact that BootStrap 3 is a mobile first responsive system and fails to explain how this affects the col-xx-n hierarchy in that part of the Bootstrap documentation.
This makes you wonder what happens on smaller devices if you choose a value for larger devices and makes you wonder if there is a need to specify multiple values. (You don't)
I would attempt to clarify this by stating that...
Lower grain types (xs, sm) attempt retain layout appearance on smaller screens and larger types (md,lg) will display correctly only on larger screens but will wrap columns on smaller devices.
The values quoted in previous examples refer to the threshold as which bootstrap degrades the appearance to fit the available screen estate.
What this means in practice is that if you make the columns col-xs-n then they will retain correct appearance even on very small screens, until the window drops to a size that is so restrictive that the page cannot be displayed correctly.
This should mean that devices that have a width of 768px or less should show your table as you designed it rather than in degraded (single or wrapped column form).
Obviously this still depends on the content of the columns and that's the whole point. If the page attempts to display multiple columns of large data, side by side on a small screen then the columns will naturally wrap in a horrible way if you did not account for it. Therefore, depending on the data within the columns you can decide the point at which the layout is sacificed to display the content adequately.
e.g. If your page contains three col-sm-n columns bootstrap would wrap the columns into rows when the page width drops below 992px.
This means that the data is still visible but will require vertical scrolling to view it. If you do not want your layout to degrade, choose xs (as long as your data can be adequately displayed on a lower resolution device in three columns)
If the horizontal position of the data is important then you should try to choose lower granularity values to retain the visual nature. If the position is less important but the page must be visible on all devices then a higher value should be used.
If you choose col-lg-n then the columns will display correctly until the screen width drops below the xs threshold of 1200px.
TL;DR
.col-X-Y means on screen size X and up, stretch this element to fill Y columns.
Bootstrap provides a grid of 12 columns per .row, so Y=3 means width=25%.
xs, sm, md, lg are the sizes for smartphone, tablet, laptop, desktop respectively.
The point of specifying different widths on different screen sizes is to let you make things larger on smaller screens.
Example
<div class="col-lg-6 col-xs-12">
Meaning: 50% width on Desktops, 100% width on Mobile, Tablet, and Laptop.
Device Sizes and class prefix:
Extra small devices Phones (<768px) - .col-xs-
Small devices Tablets (≥768px) - .col-sm-
Medium devices Desktops (≥992px) - .col-md-
Large devices Desktops (≥1200px) - .col-lg-
Grid options:
Reference: Grid System
.col-xs-$  Extra Small  Phones Less than 768px 
.col-sm-$  Small Devices  Tablets 768px and Up 
.col-md-$  Medium Devices  Desktops 992px and Up 
.col-lg-$  Large Devices  Large Desktops 1200px and Up 
One particular case : Before learning bootstrap grid system, make sure browser zoom is set to 100% (a hundred percent). For example : If screen resolution is (1600px x 900px) and browser zoom is 175%, then "bootstrap-ped" elements will be stacked.
HTML
<div class="container-fluid">
<div class="row">
<div class="col-lg-4">class="col-lg-4"</div>
<div class="col-lg-4">class="col-lg-4"</div>
</div>
</div>
Chrome zoom 100%
Browser 100 percent - elements placed horizontally
Chrome zoom 175%
Browser 175 percent - stacked elements
well it's used to tell bootstrap how many columns are to be placed in a row depending on the screen size-
col-xs-2
would show only 2 columns in a row in extra small(xs) screen, in the same way as sm defines a small screen, md(medium sized), lg(large sized),
but according to bootstrap smaller first rule, if you mention
xs-col-2 md-col-4
then 2 columns would be shown in every row for screen sizes from xs upto sm(included) and changes when it gets next size i.e. for md up to lg(included)
for a better understanding of screen sizes try running them in various screen modes in chrome's developer mode(ctr+shift+i) and try various pixels or devices

Can someone explain me Bootstrap's <div> grid "sequence"?

I see divs on projects like <div class="col-lg-8 col-xs-12 col-md-6> and I wanted to know why there's 3 grid classes instead of 1. Is it for mobile?? But how the browser will decode which one is for mobile? Is there a specific classes sequence <div class="(PC) col-lg-8 (LAPTOPS) col-xs-12 (MOBILE)col-md-6>?
And If I use the col-offset option, it will offset all the classes or
just the class before it?
Thanks in advance!
GO HERE FOR MORE INFORMATION
https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
Grid Classes The Bootstrap grid system has four classes:
xs (for phones)
sm (for tablets)
md (for desktops)
lg (for larger
desktops)
The classes above can be combined to create more dynamic and
flexible layouts.
Tip: Each class scales up, so if you wish to set the same widths for
xs and sm, you only need to specify xs.
According to your question, you see 3 classes used, there are 4 basic classes -
col-lg-x , 2. col-md-x , 3. col-sm-x , 4. col-xs-x.
-lg --> Large desktops.
-md --> laptops/desktops.
-sm --> tablets.
-xs --> mobile screens.
And "-x" stands for numeric value of width in terms of blocks, ranging between 1 and 12.
Our screen is basically divided into 12 parts by the bootstrap (in every screen size - lg, md, sm, xs)
12 being the whole screen in all the cases.
So, you can choose the amount of block space width you want to assign to some block based on the screen size.
So, if you choose -
<div> class="col-lg-8 col-xs-12 col-md-6">
you are telling your browser to allow the <div> to have
// col-lg-8 -- 8 blocks of space on large screens
// col-xs-12 -- 12 (whole screen) of space on small(mobile) screens
// col-md-6 6 blocks (half the screen) in medium sized screens (laptops/desktops)
ALSO
They are the classes , no sequence matter at all.
The browser won't decode that stuff, it's the Js's files of Bootstrap which will care of it, for the browsers.
// LG - larger computer
// MD - computer
// SM - tablet
// XS - smartphone
If you inspect with your inspector theses class, you'll see for example that col-8 correspond to :
.col-8 {
width: 50%;
max-width: 50%;
}
So it takes 50% width of his parent. And if your set a class at col-4, it will be at 50% less width than col-8, so :
.col-4 {
width: 25%;
max-width: 25%;
}
When you add "sm", it mean that it will be triggered only for mobile, "md" for tablet.

How to know which class is going to apply in Bootstrap

I have a div tag like as below.
<div class="col-xs-5 col-md-2 col-lg-1"></div>
With the current resolution of window / device how would I know if it is going to apply either col-xs-5 or col-md-2 or col-lg-1.
The reason for this question is I have to request number of items to the server. If the bootstrap applies col-xs-5 I'll request 10 Items. Otherwise 20 items, 30 items respectively.
Is there any way I'll know which class is going to apply to my DIV tag ?
you need to take a look at the info found on their website http://getbootstrap.com/css/#grid
but what is happening is that when the div has <div class="col-xs-5 col-md-2 col-lg-1"></div> these class names it will apply them based on screen size. bootstrap works on a 12 column grid system so if you use col-xs-5 then it will only fill up 5 of those columns when the width of the screen is xs(mobile) then once the screen hits a medium sized screen it will only fill up 2 of those columns if you are using the col-md-2.
This doesnt actually change anything within your html its just reajusting the size of it.
For example there is a way to hide everything within a div at a certain screen size usig hidden. so if you wanted to hide everything at screen size xs then you would use a div class called hidden-xs this doesnt actually delete what you have on the screen but like its name it "hides" it.
btw the screen sizes for each class are as follows:
Extra small devices Phones (<768px)
Small devices Tablets (≥768px)
Medium devices Desktops (≥992px)
Large devices Desktops (≥1200px)
Bootstrap will let you style content differently based on device width, but if you want to load different/more/less content, you can detect the width with jQuery. Probably best to use the same breakpoints as Bootstrap to keep things consistent. Then somehow load that content you want based on the if statement that is true:
var width = $(window).width();
if (width < 767){
// load your "xs" content
} else if ((width >= 768) && (width < 991)) {
// load your "sm" content
} else if ((width >= 992) && (width < 1200)){
// load your "md" content
} else {
// load your "lg" content
}
That being said, bootstrap also allows for show/hide at different device widths, which could also solve your problem, but with quite a bit of additional markup.

Bootstrap div resize class

I have div:
<div class="col-md-2 col-sm-4 col-xs-12 postaviborder">
When min-width is 992px and max-width is 1199px I need div has class col-sm-4.
After lower size, resizing need to continue to xs-12
I hope can somebody understand me.
Is that possible?
I would propose to check bootstap grid system - http://getbootstrap.com/css/#grid
If I understang you right you can use following:
1)for large screens (Large devices Desktops (≥1200px)) - you can use col-lg-4 => element width will be 1/3 of 100%
2) for lower sizes - you can use col-xs-12 => element width will be 100%
Also you can override grid media queries (#screen-sm-min, #screen-md-min, #screen-lg-min) - http://getbootstrap.com/css/#grid-media-queries

Bootstrap 'offset' created for lower screen resolutions is being displayed on larger screen as well

A HTML file, created using Twitter Bootstrap - 3, with a header containing 4 columns. Here's the URL -
http://jsfiddle.net/anujbhai/nuHX6/.
Problem is, inside
#module_signup_header
even in big-screen where
.col-md-offset-1
should be working, instead
.col-sm-offset-1
is taking over the layout, which i think should only be viewed in screens less than 750px width.
..someone please help!! the 'offset' created for lower screen resolutions is being displayed on larger screen,
Below 768px, col-xs-width works not col-sm-width.
For more than 768px but less than 992px, col-sm-width works.
For more than 992px but less than 1200, col-md-works.
For more than 1200 px, col-lg works.
For 750px, col-xs should work but since it is not there, next col-sm is in work.
I'm actually experiencing a similar problem where an offset at the sm size carries over to the md size, even though I'm using their suggested md-offset-0 option. Maybe a push is not considered an offset?
But for your example I would add offset-0, giving you this
<div class="col-sm-x col-sm-offset-1 col-md-offset-1 col-md-offset-0">