Last element in a row is not aligning - html

I am using bootsrap 3 as my CSS framework to style my website.
<div class="row">
<div class="col-lg-4">...</div>
<div class="col-lg-4">...</div>
<div class="col-lg-4">...</div>
<div class="col-lg-4">...</div>
.
.
.
</div>
The idea is to add the col-lg-4 div into one row, and the col-lg-4 div will automatically move to the next row when it has exceed the width of the row.
In general, it works fine. However, the last col-lg-4 div of the first row is not aligning correctly. The demo address is: http://imaboy.cn/blog/forums/
Do you have any idea why this is happening?
Here is the screenshot:
http://www.imaboy.cn/screenshot.jpg

very easy. In your first column, last row, you have a col-lg-4 element which has an additional row of text, making it higher. This causes to interrupt the normal float of columns. See images below:
as you may see, that beige zone is about to collide with the column in the left. See image below for a better view of the issue:
I have added a transparency so you can see the collision and how that rocket column blocks all floats.
The solution
just add this to your CSS:
.col-md-6.col-xs-6.col-sm-6.col-lg-4{min-height:70px; margin-top:20px; }
Now you make sure those columns will have the appropriate height to float with ease (adjust that height if needed). Also, I have added the margin-top declaration to your CSS instead of inline since it's better to have it all in the style-sheet. Also, you should consider giving those columns a name, like myCol so you don't risk to affect columns anywhere in your site and you can target them as easy as
.myCol{min-height:70px; margin-top:20px; }

Related

Bootstrap - Background Color on Row

I have a work in progress
www.codepen.io/anon/pen/yMmjZb
The issue I am having is that my 3rd row (the one with the 3 columns) has a background colour set but this is bleeding beyond the boundary I would like. I am suspecting due to a row being the full page width. I have tried applying the background to the columns individually but when the page is resized each column becomes a different height so the bottom of the fill isn't consistent.
Any solutions?
I have checked your code and here is the solution. Just bind the col-md-4 with a col-md-12 to occupy the padding and give your class col-homepage to it.
Here is pen to it-
http://codepen.io/sahildhir_1/pen/BWXVoz
Just remove the margins from the row. Currently you have -15px; in margins. Make it 0 and row wont span the entire width.
Add <div class="col-md-12"> after the row. In bootstrap, we always wrap columns in a row. Just like you did in second row, you need to add col-md-12 class after the .row
So the code will looks like -
<div class="row">
<div class="col-md-12">
<div class="container-fluid col-homepage">
....

Bootstrap v4 push and pull grid classes aren't working as expected

I am trying to use Bootstrap v4 (alpha 3) to create a responsive layout for a web application that i'm working on.
Everything works for the most part but what i'm really struggling with is reordering my cards using the push and pull classes. It was to my understanding that the push and pull classes reordered the cards when used correctly while the rest of the layout responded to the change of order as mentioned in the Grid system section of the docs under 'column ordering':
Easily change the order of our built-in grid columns with .push-md-*
and .pull-md-* modifier classes.
which can be found here: http://v4-alpha.getbootstrap.com/layout/grid/#example-column-ordering
However, when using these classes it seems to, instead of reordering the cards, just move them left and right (to the point where they can even overlap or go off screen, this functionality is also suggested by their css). This also implies that they have the exact same functionality as the offset functions, who's purpose is to move a card by x number of columns.
I have managed to get them working as expected in the past before, but have no idea how. So can someone please tell me what i'm doing wrong?
HTML:
<div class="container">
<div class="row">
<div class="card card1 col-lg-4 col-md-6"></div>
<div class="card card2 col-lg-4 col-md-6"></div>
<div class="card card4 col-lg-8 col-md-12 push-lg-4"></div>
<div class="card card3 col-lg-4 col-md-6 pull-lg-8"></div>
</div>
</div>
CSS:
.card{height: 150px;}
.card1{background-color:red;}
.card2{background-color:blue;}
.card3{background-color:green;}
.card4{background-color:yellow;}
JSFIDDLE:
https://jsfiddle.net/61yoqkjk/5/
The expected behavior is that at large sizes and higher, the green box will be moved up to be on the same line as the red and blue boxes. However, instead the green and yellow boxes swap places but there's now a gap to the right of the blue box where the green box could fit.
This has been tried with Bootstrap 3 as well so I don't think this is a bug.
I have also checked through other similar questions but none of their answers seem to fix my problem.
I think you might be misunderstanding, how bootstrap works. You want, that the elements some sort of "switch their position" by pulling/pushing them (which is very hard to achieve with css only). What bootstrap does, instead, is that the helper classes push-xx and pull-xx move the elements visually around. E.g. the code for pull-lg-8 is:
.pull-lg-8 {
right: 66.666667%;
}
...and this does NOT affect the other elements. Imagine, that the browser first calculates the layout box for each element by using properties like width, height, float, display, ... and afterwards, after every element has a certain place where it belongs, the relative positioned elements are visually moved to a different place (if right, top, bottom or left was used). From a structural point of view, they still take the same space, though and don't affect the other elements.
Therefore your yellow element (which is too big for the first line) is in the second row taking 2/3 of the space, whereas your green element has its box in the second row at the very right and is afterwards pushed 2/3 to the left.

Bootstrap Two Column Layout Misalignment

I am trying to create a simple two column layout which has one big image followed by two columns, left one for image right one for text.
But I'm not able to align the image column with the top big image.
I can add a class with -15px margin but then there is misalignment in XS screen size.
I can add another -15px margin for xs screen also then I might have to fix something else. This is such a basic layout issue, I have a feeling I am doing something wrong.
Can you guys suggest what I am doing wrong and how should I approach two column layout in Bootstrap 3?
Here is the Bootply Link
The <div class="col-sm-12"> in the lower box causes the trouble. You have two options here:
Just delete the div
Add an additional <div class="row"> after the <div class="col-sm-12">
You were essentially creating a nested grid and bootstrap requires you to begin every new nesting level with a new <div class="row">
See: http://www.bootply.com/sh13QtYpFP
#bspellmeyer is correct. When nesting columns in Bootstrap, you need to add a row and then your nested columns.
HERE IS WHY
The grid works with 3 parts: a container, a row and column(s)...
The container has 15px of padding. The row negates the container padding with -15px of margin. Columns have 15px of padding, which pull the content away from the edges of the container and create a consistent 30px gutter.
The purpose for adding 15px of padding that is only negated by the negative row margins seems silly, but it is essential to allow for nesting columns inside of other columns! Note in the diagram below how the nested columns indicated by the red outline fits neatly into the enclosing column without getting additional padding applied.
I promise that once this sinks in, making the grid behave exactly how you want every time will be a breeze.
You need to add :
.custom-left {
padding: 0;
}
to your .custom-left class. Add the same to your .custom-right class if you want to align this div with the top image as well.
Updated Bootply: http://www.bootply.com/iQYEpYqXJZ

How to get the righthand div to fall above the left div in Foundation when collapsing to one column

I'm building a site in Zurb's Foundation 4. And I have a row that has two columns. The left column is a paragraph and the right column is an image. When I reduce the browser to mobile dimensions so that the layout will collapse to one column I would like the right div, the image, to be ABOVE the left div, the paragraph, when it transforms to one column.
By default the image is going to fall below the paragraph since the div is later in the order.
Thanks!
Foundation has push and pull classes you can use for this. In your situation, you would set it up like:
<div class="row">
<div class="large-6 push-6 columns">Image</div>
<div class="large-6 pull-6 columns">Text from paragraph</div>
</div>
You can find out more on this by reviewing the docs at http://foundation.zurb.com/docs/components/grid.html and look for 'Source Ordering'

Right edge of divs not lining up when removing margin from middle columns

When using the Blueprint CSS framework, I wanted to remove the margin between all columns. Unfortunately, when I remove these margins, any div that spans all columns now appears wider than the total combined width of the divs on those rows that have had margins removed. The effect is worse on those rows that have many columns.
For those rows in which I'm using all 24 columns, I want the right edge of the divs to line up. Can this issue be resolved without resorting to a bunch of Blueprint hacks, or without manually resizing a container or something by just the right number of pixels to account for the missing margins?
Code in Head:
<style type="text/css">
.topnav{background-color:blue;}
.logo{background-color:yellow;}
.icons{background-color:orange;}
.search{background-color:red;}
</style>
Code in Body:
<div class="container">
<div class="span-24 first last top topnav">Top Nav</div>
<div class="span-5 first logo">Logo</div>
<div class="span-3 append-8 icons">Icons</div>
<div class="span-8 last bottom search">Search</div>
</div>
If you really need to remove the margins between the columns (I doubt that's the case, but without more info I cannot provide more help) then the best thing would be to redo the entire grid. Here is a generator for blueprint, where you can specify all needed variables, including the gutter (margin between columns): http://ianli.com/blueprinter/