How can I display a different layout with bootstrap 3? - css

I am trying to display a different layout for my mobile views. In the desktop view using the grid system I have 4 columns each with 2 columns an image and a label+value. In mobile I want to skip the image column and for the label and value I want them next to eachother so something like:
This is a label : this is a span.
1 column in the desktop version looks something like this:
<div class="col-md-3">
<div class="col-md-2">
<p>col-md-4</p>
</div>
<div class="col-md-10">
<div>This is a label</div>
<span>This is a span</span>
</div>
</div>
I tried to use col-sm-3 but it still displays in the desktop? How can I get the mobile view with the label and value next to eachother?
See also:codepen

you can use bootstrap css class :
<h2>Example</h2>
<p>Resize this page to see how the text below changes:</p>
<h1 class="visible-xs">This text is shown only on an EXTRA SMALL screen.</h1>
<h1 class="visible-sm">This text is shown only on a SMALL screen.</h1>
<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>

Using a media queries you can change the attributes of elements/classes/IDs based on screen size. You may be particularly interested in using display: none; as follows:
CSS
/*For smartphone and small devices*/
#media only screen and (min-width: 480px) {
.hide-me {
display: none;
}
}
/*For tablet sized devices and larger*/
#media only screen and (min-width: 748px) {
.hide-me {
display: block;
}
}
Of course you can double up the functionality of col-xs-3 (or any of your choosing) but using that as your class selector in the media query.
#media only screen and (min-width: 748px) {
.col-xs-3 {
display: block;
}
}
Check out some standard documentation responsive design - especially those provided by Twitter! Mobile first is common, where you start with the smaller media queries then get bigger.
http://getbootstrap.com/css/

Related

How to get divs to stack on mobile and inline on desktop screens?

I'm struggling to use Tailwind CSS to display inline on large sizes and block on small sizes.
Below is my code:
<div class="block md:flex md:justify-between md:text-left text-center">
<div class="order-2 md:order-1">Div 1</div>
<div class="order-1 md:order-2">Div 2</div>
</div>
On a large screen it should look like:
Div 1 Div 2
and on a small screen:
Div 2
Div 1
Media Queries
You can use media queries to change styling depending on certain conditions:
<div class="container">
<div>ONE</div>
<div>TWO</div>
</div>
.container {
/* Mobile by default as Roy pointed out */
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
/* For desktops */
.container {
flex-direction: row;
}
}
Here is a JSFiddle for you to play with.
If you really want to check whether it is a mobile device, there is probably a library for that in the framework you are working with.
Or you can check for it yourself with some JavaScript as explained here with some examples.
But the device type should not actually affect the decision of how to display items. You should just take into account screen size and ratio, and thus use the media-query.
Your code seems correct, but if default tailwind breakpoints don't fit your needs, you can define your own custom breakpoints.
https://tailwindcss.com/docs/screens

downsize width and margin-top

Responsive website with a red (left) column and a blue (right) column. The red column has a black element with margin-top:30px
When the website is resized and the blue column jumps down under the red column, the red column "inherits" the margin-top.. How can this this be avoid?
http://www.bluemachines.dk/_bootstrap/downsize/
It is due to media query used in Bootstrap!
You need to learn media queries for that or if you don't need media queries! Don't use classes of Bootstrap in navigation!
Put this into #media (min-width: 768px) and (max-width: 979px) and it works perfectly.
.nav-collapse, .nav-collapse.collapse {
overflow: visible;
}
.navbar .btn-navbar {
display: none;
}
or
You can also stop the navbar from stacking by changing the
#grid-float-breakpoint variable to 1px
or
Media queries works on browser width for mobile devices u can also specify your style in media query css
#media(max-width:767px){}
#media(min-width:768px){}
#media(min-width:992px){}
#media(min-width:1200px){}
Here is link for disabling media queries
Try this:
<div class="col-md-4 col-lg-4 col-xs-4 col-sm-4">
Your Content
</div>
<div class="col-md-8 col-lg-8 col-xs-8 col-sm-8">
Your Content
</div>
Give classes for all the screen size, the problem solves!!!!

Changing class style on smaller screen in boostrap 3?

I am trying sothing with class called .text-center in \boostrap 3?
But i want only on smaller screen to add that to container element.
Tried something like this
col-sm-text-center col-xs-text-center
But does not work ok, is it possible to make it so simple?
Here is the code that is not working
<div class="col-md-6 col-sm-text-center col-xs-text-center">
<h2 class="color-brand">Lorem Ipsum</h2>
<p class="color-grey">Lorem ispums dolor sit</p>
</div>
It doesn't work this way. Css prefixes (.col-xs-, .col-sm- etc ) in bootstrap 3 are only for defining what column size will be for different screen sizes while alignment classes are what it is - classes for aligning text within a block.
You could probably use just css3 media queries for that like:
/* Small devices (tablets, 768px and up) */
#media (min-width: #screen-sm-min) {
.my-fancy-block {
text-align:center;
}
}

How can I turn a span9 into a span12 on smaller browser windows?

I have a layout as follows:
<div class="container">
<div class="span9" ></div> <div class="span3" ></div>
</div>
I would like the span9 div and the span3 div to both become span12 divs when the user is viewing the page on a tablet or mobile device, and I would like them to become vertically stacked above on another.
Can this be accomplished and if so how? My current solution relies upon a second set of divs which I show on small browser windows and I hide the above divs.
Using Bootstrap 3, this is super easy:
<div class="col-md-9">...</div>
<div class="col-md-3">...</div>
At typical desktop resolution (> 992px), the divs will be 9/12 columns & 3/12 columns. On anything smaller, they will be 12/12.
Twitter Bootstrap 3 grids
Using Bootstrap 2.3.2, you can add a media query:
/* Landscape phone to portrait tablet */
#media (max-width: 767px) {
.span9, .span3 {
display: block;
float: none;
width: 100%;
}
}

Twitter Bootstrap: non-responsive row in responsive layout

I'm using a responsive fluid grid system on my site, and in most cases the responsive Bootstrap behaviour is what I want: on small screens, the grid columns become fluid and stack vertically.
However, using grid nesting, inside a nested row this is not always the desired behaviour. There are some rows that are not supposed to be stacked vertically, regardless how small the screen is. This is exactly the behaviour of the whole grid when I completely disable all responsive CSS code, but obviously this is no alternative if the responsive behaviour is required for the outer rows.
The relevant markup is:
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">This column should be stacked on small devices.</div>
<div class="span6">
<div class="row-fluid">
<div class="span6">Nested row. This column should NOT be stacked on small devices.</div>
<div class="span6">Nested row. This column should NOT be stacked on small devices.</div>
</div>
</div>
</div>
</div>
See this jsfidde for clarification.
How would one best solve this problem? Is there a way to do it with the native bootstrap functions?
[class*="span"] .span6 { display: inline-block; width: 48.61878453038674%}
example:
http://jsfiddle.net/NfTQ7/1/
What I have done to solve issues like this is the following:
<div class="row-fluid">
<div id="remove-mobile" class="span6">Nested row. This column should NOT be stacked on small devices.</div>
<div id="remove-mobile" class="span6">Nested row. This column should NOT be stacked on small devices.</div>
</div>
#media only screen and (max-width: 480px) {
#remove-mobile {
display:none;
}
}
That way, you get rid of that whole mess on smaller devices, and you can add code specifically targeted towards mobile sizes by simply doing the opposite:
<div class="row-fluid">
<div id="show-mobile" class="span6">Your Beautiful Code For Mobile Only</div>
</div>
#media only screen and (min-width: 481px) {
#show-mobile {
display:none;
}
}
#media only screen and (max-width: 480px) {
#show-mobile {
display:block;
}
#remove-mobile {
display:none;
}
}
It's not the simplest of solutions but I've found it suits my needs
https://github.com/twitter/bootstrap/blob/master/less/mixins.less#L572
If you dive into the source for bootstraps grid, it's relatively easy to pull out the less code used to generate the span[1-12] system.
So I just pulled out the basics and put them in my own file with a different selector. So now, when I want to use span's that don't wrap I just use .naps[1-12] (Span spelt backwards).
The responsive CSS looks for .span[1-12] selectors so it ignores my .naps elements.
It's not elegant, and it's not particularly scalable. It does work though :-/

Resources