I am having an issue with a dynamic form I am creating on my page.
I have a Row that contains 1 or more Divs that are 4 col in length. I would expect that after ever 3, it moves the next one down as it hits the 12 col limit.
Looking at the picture below, after we hit the first three fields I would think it would move the others down to their own row.
Here id the HMLT that my data is in. As you can see, each one is its own col within the row.
Is there something I am doing incorrectly with the way I have this formatted? Just not sure what else to try.
I believe it is proper to create a .row for every row on the page:
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
</div>
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
</div>
I had the same problem yesterday, what I found is that the container should have the col length specified in order to fix the problem.
Also I found useful to add additional divs in order to fix better the length of the fields.
My example:
<div class="form-group col-md-12">
<div class="row">
<div class="form-group col-md-3">
your label data
</div>
<div class="form-group col-md-4">
your input data
</div>
</div>
<div class="row">
<div class="form-group col-md-2">
your label data
</div>
<div class="form-group col-md-3">
your input data
</div>
</div>
</div>
I hope it helps.
It's hard to tell from your screenshot, but it looks like you have the whole thing (rows, columns, and some form groups) inside of a span element. Try using a div instead.
The problem: http://jsfiddle.net/24doudo0/
This seems to be an issue with how bootstrap handles grid wrapping. It doesn't handle as nicely as we would like. I can think of two solutions to this problem. The first is to insert rows after every third column when you loop over them in the backend. For that you can use the modulus operator. I don't know what backend language you are using, but I'll illustrate this approach using PHP because I'm lazy.
Lets assume you have an array of input names that you want to loop over and create columns for each.
<div class="row">
<? foreach ($inputs as $count => $name) : ?>
<div class="col-md-4">
<input type="text" name="<?=$name?>">
</div>
<? if (($count + 1) % 3 == 0) : // $count is 0 based. We need an index that starts at 1 so that we don't trigger a new row on the first loop (0 / 3 = 0 which is a remainder of 0) ?>
</div>
<div class="row">
<? endif; ?>
<? endforeach; ?>
</div>
The other solutions is a CSS based one. Pretty simple but is CSS3 only, so it won't work in IE 8 or less. This approach just clears the float after every third column. Demo here: http://jsfiddle.net/j0dtng4t/
[class*="col-"] {
background: #C55;
border: 1px solid white;
color: white;
}
[class*="col-"]:nth-of-type(3n + 1) {
clear:left;
}
Actually there are at least other 2 alternative solutions you can consider without adding row divs.
The first is adding heights to all the .col* elements , in this way they'll get ordered progressively and stack when they don't fit next to each other.(checkout the pen).
The second is using display flex on the div containing the .col* elements; it's not a bootstrap feature but it seems to suite your situation quite well.
In the pens I made I modified the col-* selectors but I suggest you use a new selector so not to mess with Bootstrap's grid style.
There seems to be some confusion on how floats work especially in a bootstrap grid.
Here is a simple bit of code that demonstrates how floats work
.container-fluid {min-width:638px;}
.container-fluid p{margin:0;font-size:1.2rem}
[class*="col-"] {
background: #C55;
border: 1px solid white;
color: white;
}
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-4">
column 1 <p>we work because we are the same height</p>
</div>
<div class="col-xs-4">
column 2 <p>we work because we are the same height</p>
</div>
<div class="col-xs-4">
column 3 <p>we work because we are the same height</p>
</div>
<div class="col-xs-4">
column 1
</div>
<div class="col-xs-4">
column 2 <p>I'm tall, but my buddies aren't</p>
</div>
<div class="col-xs-4">
column 3
</div>
<div class="col-xs-4">
column 3
</div>
<div class="col-xs-4">
column 1
</div>
<div class="col-xs-6">
column 2 <p>I'm tall but because Fred is too wide he goes to the far left to fit</p>
</div>
<div class="col-xs-2">
column 3
</div>
<div class="col-xs-4">
Fred column 1
</div>
</div>
<div class="row">
<div class="col-xs-4">
inputs are taller than select
</div>
<div class="col-xs-4">
inputs are taller than select
</div>
<div class="col-xs-4">
selects are smaller
</div>
<div class="col-xs-4">
<input type="text" placeholder="i'm too tall" />
</div>
<div class="col-xs-4">
<input type="text" placeholder="i'm too tall" />
</div>
<div class="col-xs-4">
<select><option>i'm shorter</option></select>
</div>
<div class="col-xs-4">that's why i'm column 3</div>
</div>
</div>
Related
this is my page structure
HTML
<div class="container" style="padding-top:20px">
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-12" style="height:80px">
1st
</div>
<div class="col-md-12" style="height:50px">
3rd
</div>
<div class="col-md-12" style="height:50px">
5th
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12" style="height:50px">
2nd
</div>
<div class="col-md-12" style="height:40px">
4th
</div>
<div class="col-md-12" style="height:90px">
6th
</div>
</div>
</div>
</div>
</div>
I made a jsFiddle for it
https://jsfiddle.net/ytke8mn3/
I marked the columns with 1st,2nd,3rd,4th,5th,6th
The issue I'm facing is after resizing my page to a certain width in bootstrap below 992px.
I would like the columns to show in this order > 1st,2nd,3rd,4th,5th,6th
rather than 1st 3rd 5th 2nd 4th 6th
How to achieve this. Thanks
I found something that worked for me, it aligned the elements very well for me. I'm happy with it so far. it required a little bit of dom element restructuring(less written code) but that's okay.
<div class="container" style="padding-top:20px">
<div class="row">
<div class="col-md-8" style="height:80px">1st</div>
<div class="col-md-4" style="height:40px">2nd</div>
<div class="col-md-8" style="height:40px">3rd</div>
<div class="col-md-4" style="height:80px">4th</div>
<div class="col-md-8" style="height:80px">5th</div>
<div class="col-md-4" style="height:30px">6th</div>
</div>
</div>
https://github.com/desandro/masonry
I don't know how it is implemented but it's working. below is a jsfiddle
https://jsfiddle.net/p5u976mt/
The outer containers col-md-8 and col-md-4 make it impossible to reorder it the way you want to with https://getbootstrap.com/docs/4.0/layout/grid/#order-classes
You could hide the two outer containers and show a third one only for narrow device-widths with the 6 elements in the right order (would be very easy but a bad practice, because you repeat yourself).
I am not sure what exactly your actual requirement is. You can try the following bootstrap structure to get this ordering correctly.
Fiddle goes here
.row {
background: #f8f9fa;
}
.row > div {
border: solid 1px #6c757d;
}
So basically I'm still a begginer when it comes to doing interfaces on the web and trying to allign everything properly. I've decided to use the bootstrap library. I'm trying to make a modal dialog divided into multiple section but i'm really struggling to make some section stack on top of each other and have another section take up the entire space.
What I currently have :
https://i.gyazo.com/adeeb3cca0abb6dea4a5d002d3568afa.png
What I'm trying to achieve :
https://i.gyazo.com/e8513c243424cb71926ac838e8b1166e.png
This is the code I currently have with some sample text to try to delimiter each section :
<div class='container-fluid'>
<div class="row">
<div class="col-md-3" style='border:1px solid black;max-height:5vh;'>
STATUS
</div>
<div class="col-md-9" style='border:1px solid black;min-height:50vh;'>
L
</div>
<div class="col-md-3">
SOME TEXT ASDASDASDJLASDJKLASDJAD
ASDASDLASKD
aASDASDK:ASDKASDK
ASDASJDASDASDKASJDASDJ
</div>
<div class="col-md-9">
L
</div>
</div>
</div>
To match the image you've provided, you want two columns - one three wide with four rows, and one nine wide with one row.
The height of the rows in the left column will be determined by their contents. I've written an example with extra content in one row in the left column:
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="row">
3
</div>
<div class="row">
3<br>
wide<br>
but<br>
taller
</div>
<div class="row">
3
</div>
<div class="row">
3
</div>
</div>
<div class="col-sm-9">
9
</div>
</div>
</div>
JSFiddle for a live example.
You keep two main columns (3/9) and inside the first column you can add more container. You can also add styles or classes to them.
<div class="container-fluid">
<div class="row" >
<div class="col-md-3" style='border:1px solid black;min-height:50vh;'>
<div style="min-height:10vh">10vh</div>
<div style="min-height:20vh">10vh</div>
<div style="min-height:10vh">10vh</div>
<div style="min-height:10vh">10vh</div>
</div>
<div class="col-md-9" style='border:1px solid black;min-height:50vh;'>L</div>
</div>
</div>
I try to divide a page in 2 rows with bootstrap and when I do that, there comes up a line in between. Can I remove/hide it somehow?
<div class="container-fluid">
<div class="row">
<div class="col-md-12 panel">
<div class="col-md-2">
<button class="btn btn-primary" type="submit" style="margin-top: 10px">Button1</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 panel">
<div class="col-md-4">
<input type="text" class="form-control" placeholder="..." />
</div>
<div class="col-md-2">
<button class="btn btn-primary" type="submit">Button2</button>
</div>
</div>
</div>
</div>
The .panel adds a box-shadow. Either don't use it or remove it with..
.panel {
box-shadow: initial;
}
http://www.codeply.com/go/fNXo7yZu2T
You should place your 2 main .col-md divs inside one common .row, not two different rows.
see bootstrap guide
And then play with your .col-md divs.
I suggest the following:
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<button class="btn btn-primary" type="submit" style="margin-top: 10px">Button1</button>
</div>
<div class="col-md-6 panel">
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" placeholder="..." />
</div>
<div class="col-md-6">
<button class="btn btn-primary" type="submit">Button2</button>
</div>
</div>
</div>
</div>
Columns need to be wrapped in rows and that is ALL the columns at the same level - you have created 2 rows with just single columns inside.
IE you have created 2 panels - panels need to differentiate between each other - therefore the line! (If you want to use panels properly check out http://getbootstrap.com/components/#panels and/or http://www.w3schools.com/bootstrap/bootstrap_panels.asp.)
You should be living at getboostrap.com until u get happy with BS!
Basic BS layout is
row
col col col
row
col
row - a row of columns inside another row (this sorts out the padding etc).
col
col
row
col
col
etc.
All wrapped in a container (containers should NOT be nested but they can be stacked one after the other).
Hope that makes sense (think it is clearer than HTML)
Columns always (well almost always - there are a couple of weird exceptions) need to be wrapped in rows otherwise padding, margins etc. go all over the place (took me ages to work out this simple rule).
It takes a while to get BS into your system.
One tip if you are using an IDE: Set up an insert (live template in PHPStorm) to do -
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
</div>
<!-- end row -->
</div>
<!-- end col next to row -->
I do this 100 times a day now! Saves sooooo much time.
If I have two column in desktop, can I convert this two column into four column in tablet view.
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
if it is not possible with bootstrap, Is it possible with Tables?
change your div class to "col-xs-3" and allocate a width and height.
JSFiddle here
Full code:
HTML
<div class="row">
<div class="col-xs-3">div</div>
<div class="col-xs-3">div</div>
<div class="col-xs-3">div</div>
<div class="col-xs-3">div</div>
</div>
CSS
div {border: 2px black solid; width:100%;}
Have a look at a technique called 'Scaffolding'
Boostrap 3 also offers a whole new range of features for the grid system and media queries, check out this blog post
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-3"></div>
<div class="col-sm-3"></div>
<div class="col-sm-3"></div>
</div>
I haven't found any working solution for my problem so I really hope you can help me.
Here is my jsfiddle.
#import url('http://getbootstrap.com/dist/css/bootstrap.css');
<!-- snippet 1 -->
<div class="col-md-12 col-sm-12">
<div class="col-md-6 col-sm-6" style="padding:0;">
<div class="well" style="border-right:1px solid black;">
Test
</div>
</div>
<div class="col-md-6 col-sm-6" style="padding:0;">
<div class="well">
srewdf<br>srewdf<br>srewdf<br>srewdf<br>
</div>
</div>
</div>
<!-- snippet 2 -->
<div class="col-md-12 col-sm-12">
<div class="col-md-9 col-sm-9" style="padding:0;">
<div class="well" style="border-right:1px solid black;">
srewdf<br>srewdf<br>srewdf<br>srewdf<br>
srewdf<br>srewdf<br>srewdf<br>srewdf<br>
</div>
</div>
<div class="col-md-3 col-sm-3" style="padding:0;height:50%;">
<div class="well">
Test
</div>
</div>
<div class="col-md-3 col-sm-3" style="padding:0;height:50%;">
<div class="well">
Test
</div>
</div>
</div>
In snippet 1 I need multiple nested elements to have the same height based on the largest element.
In the second snippet it's similar. The two elements on the right side should have together the same height as the element on the left.
How is it possible to solve this without losing the responsibility?
Thanks for your time and help!
Equal height columns is a famous problem in the CSS model, and Bootstrap can do very little to help you.
The best you can do is read the broad amount of literature out there (I recommend starting with http://css-tricks.com/fluid-width-equal-height-columns/) and work out which of the various hacks and limitations are the correct fit for your purposes. This will differ based on the target browsers, the amount of time you want to invest, your experience with Javascript and the devices you're targeting.
Thanks for all your answers / comments.
This is how I solved it now:
$( document ).ready(function() {
var heights = $(".equalize").map(function() {
return $(this).height();
}).get(),
maxHeight = Math.max.apply(null, heights);
$(".equalize").height(maxHeight);
});
I hoped that I can do it with plain HTML/CSS but yeah, this is the simple way.