Reordering divs on responsive - css

I am aware of the col-md/xs/sm/lg, as well as push/pull capabilities of Bootstrap.
I have the following issue:
<div class="row">
<div class="col-md-7">
..content here..
</div>
<div class="col-md-5">
<div class="row">
<div class="col-md-12">
..content that when on responsive needs to be rendered first..
</div>
</div>
<div class="row">
..rest of the content..
</div>
</div>
</div>
Online version: http://codepen.io/anon/pen/wJijn
I want the the col-md-12 content to be pulled first when we're on small screen sizes, WITOUT the "..rest of the content.." also being pulled first.
Requirements:
dont' use position absolute
use a bootstrap way to do this
worst case scenario: use minimal extra css
if you suggest an HTML re-ordering make sure it will work
I am attaching two sketches the before/after how I want it to order to make things easier to understand. After:

Your graphics are a little hard to decipher, but I think I understand what you're going for...
DEMO http://www.bootply.com/rwwiuNalrr
<div class="row">
<div class="col-md-12 bg-warning">Header</div>
<div class="col-xs-12 col-md-5 pull-right bg-danger">Column 1</div>
<div class="col-xs-12 col-md-7 bg-success">Column 2</div>
<div class="col-xs-12 col-md-5 pull-right bg-info">Column 3</div>
</div>
Some notes:
When you say "goes responsive" I assume you mean "on mobile", in which case, it's good to start your HTML with that in mind, since BS3 is "mobile first". Doesn't always work, but usually, and this time it did.
Your graphics and markup suggest you want column1 and column3 to be within the same div. From a layout POV that's not necessary and makes it difficult to separate them on mobile. Here I have connected them visually without embedding one in the other.
You don't normally have to declare col-xs-12 since it's the default, but because we've messed with the layout by using pull-right, we have to be explicit.

Related

Creating dynamic bootstrap contact page

This picture should help sum up what I want done.
The code for this can be found here: https://codepen.io/MatteCrystal/pen/xxXpLmK
<div class="container">
<div class="row">
<div class="row gy-2">
<div class="col text-end minWidth200 maxWidth200">
<b>Title: </b>
</div>
<div class="col minWidth350">
Info that spans <br />
multiple lines
</div>
</div>
<div class="row gy-2">
<div class="col text-end minWidth200 maxWidth200">
<b>Title 2: </b>
</div>
<div class="col minWidth350">
More info, that gives lots of details about somthing to the user
</div>
</div>
<div class="row gy-2">
<div class="col text-end minWidth200 maxWidth200">
<b>Title 3: </b>
</div>
<div class="col minWidth350">
Even more info. To give the user a very detailed overview of somthing super important and relevant to their task. This info is integral if you want you're users to have a good user experince.
</div>
</div>
</div>
</div>
Basically, I want the contact page to be made of two pieces of content each. The title portion and then info portion to the right of the title. But on small screens instead of having the title take up valuable width I would prefer to just place the info portion underneath the title.
the title elements are forced to be the same size so they all look uniform, The text portion has a minimum size it can be but it can also grow larger to fit the page.
The problem is the title elements have the bootstrap text-end class to align the title right. But when the minimum size constraints are met the two columns will be stacked on top of each other. When this happens the title element needs to be aligned left otherwise it looks awkward. You can see what I mean in this image.
So is there any elegant or built in class for bootstrap that can achieve the results I want? I want a solution that will be flexible and not require additional changes if I decide to increase or decrease the min or max width allowed for the title or info elements. Ideally I need an option that can detect when a bootstrap row with two or more cols becomes sized small enough that each col becomes stacked on top of each other instead of side by side. Due to various factors this can't be a hard coded value since the moment this happens could differ depending on the circumstances.
This is a classic stacked to horizontal bootstrap layout.
You just need to use the responsive .col-* classes.
Remember BS uses the "mobile first" scheme, so start with .col-12 to ensure full-width on the smallest screens. Then add the appropriate col class(es) for the width(s) you want above each particular breakpoint i.e. .col-md-2 to be 2/12 of the width for medium and above. You can combine this with the responsive text alignment class .text-md-end to only right-align above medium.
Also, note in the example below there is no need to nest multiple .row.gy-2s (unless you have another requirement), columns will automatically wrap to a new line at 12 columns so, I have simplified your markup.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="container">
<div class="row gy-2">
<div class="col-12 col-md-2 text-md-end">
<b>Title: </b>
</div>
<div class="col-12 col-md-10">
Info that spans <br /> multiple lines
</div>
<div class="col-12 col-md-2 text-md-end">
<b>Title 2: </b>
</div>
<div class="col-12 col-md-10">
More info, that gives lots of details about somthing to the user
</div>
<div class="col-12 col-md-2 text-md-end">
<b>Title 3: </b>
</div>
<div class="col-12 col-md-10">
Even more info. To give the user a very detailed overview of somthing super important and relevant to their task. This info is integral if you want you're users to have a good user experince.
</div>
</div>
</div>

Bootstrap 4 div padding issue

I am using this structure but
<div class="row">
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
<div class="col-sm-4">
<div class="card">
Your card
</div>
</div>
</div>
For some reason the has as much padding as it would take to "match" the next div in the horizontal row. For example, if the first div is text, then the second is text, and the third is an image...the first two divs "grow" to be the size of the third. I thought with this Bootstrap 4 it was supposed to be flexible? Thanks.
Bootstrap 4 utilizes flexbox (display: flex) for a lot of it's layout, including it's cards. That is the reason that all the cards grow in accordance to it's siblings. You can learn more about flexboxes here:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
and
https://demos.scotch.io/visual-guide-to-css3-flexbox-flexbox-playground/demos/
You're using col-sm-4 which will make all the columns be the same size which may be what you're referring to as the first two divs grow. If you mean something else, I would look into how Bootstrap 4 works with flexbox which may also help you understand how the columns act in Bootstrap 4
Sometimes the images can push out the divs. Set a style to the image to be width: 100% and see if that makes any difference
Ok this works. Thanks everyone above for your help, I took many things from it to get the answer. It turns out if I'm reading this correctly flex itself won't allow for "three columns with shrunken divs" so one div can be bigger than the others but they all shrink to their own respective sizes around their content. So I used Masonry. I just included the .js in my head section as a script reference then added the below. If you aren't using .NET (meaning you're using PHP) just erase out the itemtemplate and repeater stuff...the code is the same for you.
<div class="row" style="display:flex;" data-masonry='{ "gutter": 0, "itemSelector": ".col-4" }'>
<asp:repeater id="ItemsList" runat="server">
<div class="card">

how to up the col grid in bootstrap

i have 3 col in medium view in bootstrap shown in above image ie.
i want to achieve this type of view in small view is col-sm-*
my code is
<div class="col-md-8">
<div class="col-md-12">A</div>
<div class="col-md-12">C</div>
</div>
<div class="col-md-4">
<div class="col-md-12">B</div>
</div>
IN THIS way i can achieve my target in medium view but cant achieve in small view.how can i achieve the both view as well as in medium and small view as shown in image.
I suggest reading bootstrap css doc also this
But try this:
<div class="row">
<div class="all a col-sm-12 col-md-6">A</div>
<div class="all b col-sm-12 col-md-6">B</div>
<div class="clearfix"></div>
<div class="all c col-sm-12 col-md-6">C</div>
</div>
You can remove the <div class="clearfix"></div> if you don't care about the height mismatch
Here's a working jsfiddle
It's a bit of a stretch, but you could try this:-
<div class="col-md-8">
<div class="col-md-12">A</div>
<div class="col-md-12 visible-sm visible-xs">B</div>
<div class="col-md-12">C</div>
</div>
<div class="col-md-4 hidden-sm hidden-xs">
<div class="col-md-12">B</div>
</div>
Frankly, I can't think of any other solution using just HTML and CSS. Although, if scripts were involved, it would be a different case.
First of all, you shouldn't assign columns without rows, so you should have something like:
<div class="row">
<div class="col-md-8 col-xs-12">A</div>
<div class="col-md-4 pull-right col-xs-12">B</div>
<div class="col-md-8 col-xs-12">C</div>
</div>
So you pull right your B Div (therefore not clearing the next div, and spacing it out). And with col-xs-12 you assure that float won't be present in mobile.
Heres a pen
Now, if you want to remain with your code, I guess Shan answer is the best one.
Well, you could have the height of B and work with margins so the positioning go right, but that isn't considered best practices and could cause some bugs.

Panel in grid causes horizontal overflow

I'm using Twitter Bootstraps grid system and inside that I use their panels. I have two cols and in each col I have one panel. But this creates a horizontal scrollbar on my page.
I could probably disable the horizontal overflow. But I'd rather "fix" the problem in a cleaner way that Bootstrap is causing.
What would be a good way to solve this problem?
Example: http://www.bootply.com/iPdjlxuexk
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Form widgets</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Selected page widgets</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
</div>
If I wrap a <div class="container"></div> around the row div, then the panels inside are really small. A big margin-left and margin-right apprears on the container. Not really what I'm after either.
http://www.bootply.com/BWMTAFeO8x
The problem is occurring because of the following HTML class:
col-md-6
Specifically, with Bootstrap, this means that whatever is currently in this column will extend to be 6 column spaces wide. This is not good if you are looking to only have something, let's say, 3 column spaces wide because it actually stretches what you are trying to do.
How do we fix it?
Use a smaller width space and then use Bootstraps ability to push/pull things. I will demonstrate what I mean via a JsFiddle, which is found here.
Basically, I altered your HTML to become the following:
<div class="row">
<div class="col-lg-3 col-md-3 col-lg-push-3 col-md-push-3">
<div class="panel panel-default">
<div class="panel-heading">Form widgets</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-lg-push-3 col-md-push-3">
<div class="panel panel-default">
<div class="panel-heading">Selected page widgets</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
</div>
NOTE
In my demonstration, I added the ability to view the panels in both a large screen setting and a medium screen setting versus just having it in a medium setting. I also had to push the columns according to the screen sizes. You can see this in effect with the JSFiddle by changing the width of the portion of the output screen in the demo. This is useful because you can see the difference between a large/medium sized screen to a small/extra-small sized screen.
More Information:
You can find more information on the grid system via the actual website. It will show you how the grid system is laid out and how you can use the push/pull aspect as well.
http://getbootstrap.com/examples/grid/

Bootstraps extra small size of window

I've been trying to adapt my website to extra small window sizes with Bootstraps but I didn't found any solution for myself.
I want to shown one column when the window is too small and keep the left version otherwise. At this point, the code is something like:
<div class="container-fluid">
<div class="row">
<div class="col-md-3" id="divLeft">
<div class="panel panel-success" id="divChart">
<!-- Some progress bars -->
</div>
</div>
<div class="col-xs-12-offset-6 col-sm-6" id="divMain">
<h2>Observations</h2>
<div class="list-group" id="observations">
<!-- Some panels -->
</div>
</div>
What I have to do? I tried to add multiple classes to my divs divLeft and divMain but it doesn't work as I want.
Thanks in advance fellas! : D
Each row should always add up to 12 columns.
Have a look at the Bootstrap Docs which tell you about how to work with their grid system:
http://getbootstrap.com/css/#grid
I'd suggest something like the below for your example:
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-md-3"></div>
<div class="col-xs-12 col-md-9"></div>
</div>
</div>
The above should result in the two columns displaying one above the other on extra small devices.

Resources