I’m trying to teach myself how to effectively center things using bootstrap. Centering is something I really struggle with, even after reading a ton of other SO posts asking the same question.
Why do we have to wrap the cols in a row, and then wrap that row in a container? What does this actually do?
body {
background-color:pink;
}
.container {
overflow: hidden;
background-color: yellow;
}
.col-sm-6 {
float: left;
height: 100px;
width: 100px;
background-color: blue;
padding: 10px;
margin: 1%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class = "container">
<div class = "row">
<div class = "col-sm-6"></div>
<div class = "col-sm-6"></div>
</div>
</div>
4
Answers
1 row have 12 cols for you’re first code :
That means you’re second div is after the first who takes 6 cols. So you push the second after the first (col-sm-push-6)
This is for the web-responsive, when you’re website is on a computer or in a mobile phone, the screen have different size. Bootstrap adapt you’re div to the screen.
They’re is sm : for small screen, lg : for large screen and md : for middle screen like a tab for exemple.
Let me explain for you. I love to teach beginners 🙂
right and left. in this way our column looks like ’15px’ inside from
wall of container.
occupy whole container space.
If you use bootstrap, there is class ready made to build your layout :
If you need cols of a fixed width, you might need to create your own class here .
example:https://jsfiddle.net/cLw2ajro/7/
Try this
CSS:
HTML
Fiddle
Source: This question