I'm using Foundation 5 with Sass. In _settings.scss you can change width of the row and gutter. By default row is set to 1000px but if you measure in Photoshop the width of the 12-column page it's just 970px wide. I also found out that width of the gutter is set to 30px.
My questions are: why 1000px row is in reality 970px wide? Do I have to worry about it? Or maybe if I want 1000px wide page I have to set row to 1030px?
To answer your question, you should know more about the grid and how the 'gutter' has been constructed.
The large grid (with the large-* classes) will be applied for viewports wider than 64.062 em (~1025px). On the large grid the '.row' got:
max-width: 62.5rem; // (~1000px)
width: 100%;
So on large screens your .row's are 1000px wide indeed.
Now the grid columns dive each row using percentage. So a large-12 column (spans 12 columns) got a width of 100%, a large-4 got 4/12 = 33,33% and a large-1 got 1/12 = 8,33%.
The above means that a large-12 has a width of 100% of the .row class, so on the large grid 62.5rem; (~1000px).
You can make the preceding visible as follows:
HTML:
<div class="row">
<div class="large-6 columns"><div>text</div></div>
<div class="large-6 columns"><div>text</div></div>
</div>
<div class="row">
<div class="large-4 columns"><div>text</div></div>
<div class="large-4 columns"><div>text</div></div>
<div class="large-4 columns"><div>text</div></div>
</div>
<div class="row">
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
<div class="large-1 columns"><div>text</div></div>
</div>
SCSS:
.row {
background-color: yellow;
div {
background-color: darkblue;
}
color: white;
}
In your browser the preceding will look like that shown in the picture below:
The box model of the .row will show you that it still got a width of 1000px:
Because of the blue background color of the columns totally overlaps the yellow background color of the row, you know the sum of the width of the columns should also be 1000px.
Now about the gutter. By default the gutter had been set to: $column-gutter: rem-calc(30px); (1.875rem)
To construct the gutter each column of the grid got a padding of gutter-size / 2 on each side. So a large-12 column has a width of 1000 pixels, but a padding of 15px on the left and a padding of 15px on the right. For that reason it seems that a row has a width of 1000 - 30 = 970 pixels.
You can make these gutters visible too by applying the following SCSS code on the HTML used before:
.row {
background-color: yellow;
div {
background-color: darkblue;
div {
background-color: red;
}
}
color: white;
}
Now you grid looks like that shown beneath:
Or by inspecting the box model of a large-12 column:
My questions are: why 1000px row is in reality 970px wide? Do I have to
worry about it?
I think you should not worry about it in the first place. See above.
Or maybe if I want 1000px wide page I have to set row to 1030px?
Well if you have a good reason to do so, you can use: $row-width: rem-calc(1030); and then indeed the box model of a large-12 will looks as follows:
Notice that you also have to change $medium-breakpoint: em-calc(1024); to a value equal or larger than 1030px to prevent a horizontal scroll bar for viewport >1024 and smaller than 1030pixels.
Or you can consider removing the gutter, by setting $column-gutter: 0;. See also: What's the point of gutters in CSS grid frameworks?
Related
In the Flexboxgrid framework I see a margin of -1rem on the .row class. In small viewports this creates a small horizontal scroll of the container.
Since I've seen this negative margin on other frameworks, what is its purpose? Inner columns have a padding of the same qty, reversed.
In the picture, red line is .container, dashed line is .row. Btw the margin is visible only on the right.
Because you're supposed to use them in combination with columns.
Columns generally have a padding to push the contents of them away from the border, in order to make it look nicer. However, when you are nesting columns within columns, the content keeps getting pushed inwards, which is mostly not a desired effect. To keep this from happening the rows have a negative margin, which pulls the columns back. In your case, it looks like you need to add a col-xs-12 around the column groups within the rows . This will prevent the content from being pulled too far.
Take a look here for a nicely explained introduction.
Here's a demonstration of how the .row class works:
.col1 {
background: red;
}
.col2 {
background: green;
}
body {
font-family: sans-serif;
}
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css" type="text/css">
<div class="row">
<div class="col-xs-12
col1">
<div class="col-xs-12
col2">
<div class="box">Without a row</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-12
col1">
<div class="row">
<div class="col-xs-12
col2">
<div class="box">With a row</div>
</div>
</div>
</div>
</div>
In general row is placed in container. container has padding of 15 and row has margin of -15
I am using a specific gutter size by doing this:
div[class^="col"]{padding-left:5px; padding-right:5px;}
.row{
margin-left:-5px;
margin-right:-5px;
border: 0px;
}
Basically, I want gutter to be 10px BUT ONLY BETWEEN columns.
However, row's width is coming out to be 2 px smaller than the container's width. I tried setting border to 0 as above to no avail.
Edit: I forgot to set padding of container to match gutter. That fixed it.
However, I am getting width of column as 118.2345 or something when it should have been exact 120. Why is that?
How about something like this:
.row {margin-left:0;margin-right:0;}
.row div[class^="col"]{padding-left:5px; padding-right:5px;}
.row div[class^="col"]:first-child{padding-left:0;}
.row div[class^="col"]:last-child{padding-right:0;}
Of course, this assumes that every row you want to display is actually decorated with a .row class. So something like the following will NOT work
<div class="row">
<div class="col-md-6">...</div>
<div class="col-md-6">...</div>
<div class="col-md-6">...</div>
<div class="col-md-6">...</div>
</div>
but something like the following will:
<div class="row">
<div class="col-md-6">...</div>
<div class="col-md-6">...</div>
</div>
<div class="row">
<div class="col-md-6">...</div>
<div class="col-md-6">...</div>
</div>
EDIT:
As far as why you are getting decimal width, that is because column widths are percentage based, depending on the total parent width. So check the width of the parent container.
I'm using angular and bootstrap-ui. I have two columns beside each other, the right one has a larger height then the the left due to the presence of controls. All I want to do is add some text in the right column that is aligned with the bottom of the left column, which should be easy. I will not admit how long I struggled with it.
It looks like the problem is that the left column itself is top aligned. so I have something like this:
*****************
* * * *
* col 1* * col 2 *
******** * *
* *
*********
I would like to cause col 1 to align with the bottom of col 2 within the row. From there aligning text in col 1 with the bottom of the col should be easy.
I've found many supposed solutions, but they don't seem to work. The most common involve overriding the display and vertical-align properties of the CSS, but doing this seems to screw up the rows alignment in odd ways. I've seen col 1 end up after col 2 or the row shrinking to not use it's full width of the page. The point being my attempts to override elements are messing with bootstrap. I believe this is because most suggestions are not actually for angular and bootstrap-ui.
The closest I got to something working was setting display:fluid for the row. This got the columns to be the same size without interfering with the rest of the look and feel. However, I then couldn't use text-right or verticle-align to position the text within col 1 on the bottom right of the column.
How can I get my text in my first column to align with the bottom of col 2?
There are issues that you can have if you try to use vertical-align within a bootstrap container. Even if you also try use (parent) display:table; and then in (child) with display:table-cell;. You lose the height control.
Your best option here is probably as I have set up in this Fiddle.
But saying that... because we use margin-top and when you resize the window to a smaller screen size you still have the problem with the top margin as you will see in the Fiddle.
But you can control this by using Bootstrap's lg, md, sm and xs to keep your text lined up, again this is also set up in the Fiddle to show how you can control this problem.
Resize the window, I have the large view setup in the fiddle.
<html !DOCTYPE html>
<head>
<link rel="stylesheet"href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" >
<style>
.block{
overflow: visible;
}
.block-a {
margin-top:200px;
height:100px;
}
.block-b {
height:300px;
padding-top:200px;
overflow: visible;
}
</style>
</head>
<body>
<div class="container col-lg-12"><br></div>
<div class="container col-lg-12 bg-warning block">
<div class="col-lg-3 col-lg-offset-2 bg-primary block-a "> Hello</div>
<div class="col-lg-3 col-lg-offset-1 bg-info block-b ">Great, lined up to the left.</div>
</div>
<div class="container col-lg-12"><br></div>
<div class="container col-lg-12 bg-success block">
<div class="col-lg-3 col-lg-offset-2 col-md-3 col-md-offset-2 col-sm-3 col- sm-offset-2 col-xs-3 col-xs-offset-1 bg-primary block-a "> Hello</div>
<div class="col-lg-3 col-lg-offset-1 col-md-3 col-md-offset-2 col-sm-5 col- sm-offset-2 col-xs-7 col-xs-offset-1 bg-info block-b ">Great, lined up to the left.</div>
</div>
</body>
</html>
Consider an unknown number of divs being created dynamically and styled using the bootstrap grid system. In this example, I'm using col-sm-4 so after every third block, we move to a new row. The blocks (divs) can be different heights, which is determined by the content within.
This is where I run into the layout problem. When moving to a new row, I want the fourth block to float to the left. This only happens when the left most div in the row above is also the shortest. I have pictures to illustrate.
Real Life:
The Dream:
The "correct" way to do this would be to wrap every three in a row class I beleive, but I'm not sure how to do this with dynamic content (could probably hack it) or if there's an easy css solution.
HTML:
<div class="row">
<div class="col-sm-12">
<div class="col-sm-4 block">
<div class="inner-block"></div>
</div>
<div class="col-sm-4 block">
<div class="inner-block"></div>
</div>
<div class="col-sm-4 block">
<div class="inner-block" style="height:150px"></div>
</div>
<div class="col-sm-4 block">
<div class="inner-block"></div>
</div>
</div>
</div>
CSS:
.block {
padding: 5px;
}
.inner-block {
height: 200px;
background-color: blue;
}
Plunker Example (expand preview to proper size)
If your system is unable to add first/last classes on every nth div, then you can use the nth-child css pseudo selector.
#media (min-width: 768px) {// For medium displays and above
.col-sm-4:nth-child(3n+1) { // We target every 3rd div but offset the count by 1 so that that 1st, 4th 7th etc divs are cleared
clear:both; // Clear the float
}
}
I want to create little panels/dashboard for my interface. In my case I want to have two panels like so
+-------------------------------+ +-------------------------------+
| | | |
| | | |
+-------------------------------+ +-------------------------------+
Generally it is easy with Bootstrap 3.
<div class="row">
<div class="col-md-5">
</div>
<div class="col-md-5 pull-right">
</div>
</div>
The problem is, the gap of col-md-2, as it is the case here, is way too big. I cannot use a col-md-1 gap, because then both sides do not have an equal size.
I also tried to add padding right and left, but that had not effect, too. What can I do here?
You could add a class which modifies the width of col-md-6. The width of this class is set to 50%. A smaller gap is achieved by reducing the width like so:
.dashboard-panel-6 {
width: 45%;
}
Add this to your div elements. This way the width rule of col-md-6 gets overriden.
<div class="row">
<div class="col-md-6 dashboard-panel-6">...</div>
<div class="col-md-6 dashboard-panel-6">...</div>
</div>
You can use another div inside and give padding to that.
<div class="row">
<div class="col-md-6">
<div class="inner-div">
</div>
</div>
<div class="col-md-6 pull-right">
<div class="inner-div">
</div>
</div>
</div>
.inner-div{
padding: 5px;
}
I posted this here already but it is still relevant the original question.
I have had similar issues with space between columns. The root problem is that columns in bootstrap 3 and 4 use padding instead of margin. So background colors for two adjacent columns touch each other.
I found a solution that fit our problem and will most likely work for most people trying to space columns and maintain the same gutter widths as the rest of the grid system.
This was the end result we were going for
Having the gap with a drop shadow between columns was problematic. We did not want extra space between columns. We just wanted the gutters to be "transparent" so the background color of the site would appear between two white columns.
this is the markup for the two columns
<div class="row">
<div class="col-sm-7">
<div class="raised-block">
<h3>Facebook</h3>
</div>
</div>
<div class="col-sm-5">
<div class="raised-block">
<h3>Tweets</h3>
</div>
</div>
</div>
CSS
.raised-block {
background-color: #fff;
margin-bottom: 10px;
margin-left: 0;
margin-right: -0.625rem; // for us 0.625rem == 10px
padding-left: 0.625rem;
padding-right: 0.625rem;
}
#media (max-width: 33.9em){ // this is for our mobile layout where columns stack
.raised-block {
margin-left: -0.625rem;
}
}
.row [class^="col-"]:first-child>.raised-block {
// this is so the first column has no margin so it will not be "indented"
margin-left: -0.625rem;
}
This approach does require an inner div with negative margins just like the "row" class bootstrap uses. And this div, we called it "raised-block", must be the direct sibling of a column
This way you still get proper padding inside your columns. I have seen solutions that appear to work by creating space, but unfortunately the columns they create have extra padding on either side of the row so it ends up making the row thinner that the grid layout was designed for. If you look at the image for the desired look, this would mean the two columns together would be smaller than the one larger one on top which breaks the natural structure of the grid.
The major drawback to this approach is that it requires extra markup wrapping the content of each columns. For us this works because only specific columns needed space between them to achieve the desired look.
Hope this helps
Here's another possibility:
Live view
Edit view
You will see that it uses 2 col-md-6, each with a nested col-md-11, and you position the nested row in the second div to the right.
The suggestion from Ken has clean HTML which I like. If your left and right panels use elements with widths defined by Bootstrap though (eg wells or form elements) the column padding could cause hassles and break the layout. This nested approach might be easier in this situation.
HTML
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-11">nested row col-md-11</div>
</div><!-- end nested row -->
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-11 col-md-offset-1">nested row col-md-11</div>
</div><!-- end nested row -->
</div>
</div>
</div>
Good luck!