I have closely followed the most popular example of how to add space between columns, but it doesn't work. You can view it in action at
codepen.io
What I've done is put a col-sm-12 inside of a col-sm-4 for each column. According to the most popular answer here this should automatically render some space between the 2 divs.
HTML:
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
</div>
CSS:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
background:#FFFFFC;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
Basically, I would think the result would look like the following photo, but it does not:
you can try this: Demo
Add your "item" class with "col-sm-12"
body {
background: #BEB7A4;
}
I made some changes on your code.
HTML
Note the subitem class added to col-sm-12 divs.
<div class="row blocks-grid">
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
</div>
LESS
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
.subitem {
background:#FFFFFC;
height: 100%;
padding-top: 50px;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
}
Take a look: http://codepen.io/anon/pen/KgzVRK
Hope it can helps you.
You can actually remove all the extra junk and let bootstrap do it for you... NEVER change margins / widths on the framework. This is all you need....
HTML
<div class="row">
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x250">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
</div>
CSS
img { width: 100%; }
You may try to move the class item from col-xs-6 to col-sm-12
The snippet:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<style>
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
</style>
</head>
<body>
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
</div>
</body>
Related
I am absolute newbee and wanna create 2 rows. One with 2 img col-4 size and col-8 size and the other row à 3 x col-4 size.
My problem is that the col-8 img is a little bit bigger (height) then the col-4 img.
How can I fix it? I tried a lot but nothing worked.
Thanks for your help.
[problem
.col-4 {
padding-left: 5px;
padding-right: 5px;
}
.col-8 {
padding-left: 5px;
padding-right: 5px;
}
.x1 {
border: 1px solid black;
}
.x2 {
border: 1px solid black;
}
.x1_pic {
width: 100%;
height: auto;
position: relative;
}
.x2_pic {
width: 100%;
height: auto;
position: relative;
}
.x1_header {
position: absolute;
margin-top: -95%;
text-align: center;
}
.x2_header {
position: absolute;
margin-top: -95%;
text-align: center;
}
<div class="container">
<div class="row">
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
<div class="col-8">
<div class="x2">
<img class="x2_pic" src="./img/maschine_2.jpg">
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
</div>
</div>
]1
Achieved
Want
as seen in the first picture the items are not properly aligned how can it be aligned like on the second picture? Here's the code I tried. Vertical-align attribute also doesn't seem to work, or may be i used it wrong.
.features{
background-color: #0375b4;
padding:40px 100px;
float: left;
width: 100%;
}
.features img{
width: auto;
}
.features-content{
text-align: center;
width: 100%;
display: inline-block;
margin:0 auto;
}
.features-content h1{
font-size: 24px;
color: #ffffff;
text-transform: uppercase;
margin-top: 10px;
}
<div class="features">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="features-content">
<img src="images/compass.png" alt="Compass Logo">
<h1>Adventure</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="features-content">
<img src="images/tube.png" alt="Compass Logo">
<h1>Fun & Safety</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="features-content">
<img src="images/diamond.png" alt="Compass Logo">
<h1>Impeccable Service</h1>
</div>
</div>
</div>
</div>
</div>
The problem is that your uploaded images are not the same height.
A. Make them the same either with CSS either before uploading them
See below example with changing height with css ( i changed the class col-xs-12 to col-xs-4 for example purposes only, so they will be 3 in row in the snippet )
.features {
background-color: #0375b4;
padding: 40px 100px;
float: left;
width: 100%;
}
.features img {
width: auto;
}
.features-content {
text-align: center;
width: 100%;
display: inline-block;
margin: 0 auto;
}
.features-content h1 {
font-size: 24px;
color: #ffffff;
text-transform: uppercase;
margin-top: 10px;
}
.features-content img{
height:150px;
width:auto;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="features">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x150" alt="Compass Logo">
<h1>Adventure</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x250" alt="Compass Logo">
<h1>Fun & Safety</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x200" alt="Compass Logo">
<h1>Impeccable Service</h1>
</div>
</div>
</div>
</div>
</div>
B. Or you can make the cols same height an position the text absolutely at the bottom if you don't want to change the height of the images ( if you want your images to have different heights )
.features {
background-color: #0375b4;
padding: 40px 100px;
float: left;
width: 100%;
}
.features img {
width: auto;
max-width:100%;
}
.features-content {
text-align: center;
width: 100%;
display: inline-block;
margin: 0 auto;
}
.features-content h1 {
font-size: 24px;
color: #ffffff;
text-transform: uppercase;
margin-top: 10px;
}
.features .row {
display: flex;
flex-wrap: wrap;
}
.features .row > div {
position: relative;
padding-bottom: 60px;
border: 1px solid green;
/*for visual example*/
}
.features .row > div h1 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: 0 auto
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="features">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x150" alt="Compass Logo">
<h1>Adventure</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x250" alt="Compass Logo">
<h1>Fun & Safety</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x200" alt="Compass Logo">
<h1>Impeccable Service</h1>
</div>
</div>
</div>
</div>
</div>
C. The least 'clean' solution would be to add specific padding-bottom or margin-bottom to the images until the h1 are aligned. ( same with margin-top or padding-top to the h1 )
.features {
background-color: #0375b4;
padding: 40px 100px;
float: left;
width: 100%;
}
.features img {
width: auto;
max-width: 100%
}
.features-content {
text-align: center;
width: 100%;
display: inline-block;
margin: 0 auto;
}
.features-content h1 {
font-size: 24px;
color: #ffffff;
text-transform: uppercase;
margin-top: 10px;
}
.features .col-md-4:first-child img {
padding-bottom: 100px;
}
.features .col-md-4:last-child img {
padding-bottom: 50px;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="features">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x150" alt="Compass Logo">
<h1>Adventure</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x250" alt="Compass Logo">
<h1>Fun & Safety</h1>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div class="features-content">
<img src="http://via.placeholder.com/150x200" alt="Compass Logo">
<h1>Impeccable Service</h1>
</div>
</div>
</div>
</div>
</div>
I have a list of items with a number and text stacked ontop of each other - I am struggling with trying to vertically align the text next to the number it is sitting along side. I have the number and text just floated left inside a div - possibly I need to take a different approach? See working exmaple here - https://codepen.io/ajmajma/pen/gRpxrQ?editors=1100
My html for the items is structured like so :
<div class="featured-posts wrapper">
<div class="featured-posts--posts row">
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">1</span>10 Tips to Avoid Dry Flaky Winter Skin, Safely</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">2</span>10 Ways to Spa at Home</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">3</span>13 Healthy Ways Winterize Your Routine</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">4</span>18 Things to Love About Our Follain Soap</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">5</span><3 at First Site</div>
</div>
</div>
</div>
</div>
And the CSS (SCSS) looks like so :
.featured-posts {
counter-reset: section;
.featured-posts--posts {
.featured-post {
margin-bottom: 40px;
width: 100%;
.featured-post--wrapper {
margin: 0 auto;
}
.featured-post--count {
width: 45px;
float: left;
color: red;
height: 100%;
display: block;
font-size: 30px;
}
.featured-post--body {
width: 350px;
max-width: 100%;
margin: 0 auto;
color: black;
a {
cursor: pointer;
text-decoration: none;
color: black;
transition: color 0.2s ease-in;
&:hover {
color: red;
}
}
}
}
}
}
I am trying to have so no matter what length the text is - it is vertically aligned against the "Count" (the left number). Any input would be welcome! Thanks.
I would use display: flex; align-items: center; on the parent
.wrapper {
margin: 0 auto;
max-width: 600px;
}
.featured-posts {
counter-reset: section;
}
.featured-posts .featured-posts--posts .featured-post {
margin-bottom: 40px;
width: 100%;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--wrapper {
margin: 0 auto;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--count {
width: 45px;
color: red;
height: 100%;
display: block;
font-size: 30px;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body {
width: 350px;
max-width: 100%;
margin: 0 auto;
color: black;
display: flex;
align-items: center;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body a {
cursor: pointer;
text-decoration: none;
color: black;
transition: color 0.2s ease-in;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body a:hover {
color: red;
}
<div class="featured-posts wrapper">
<div class="featured-posts--posts row">
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">1</span>10 Tips to Avoid Dry Flaky Winter Skin, Safely</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">2</span>10 Ways to Spa at Home</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">3</span>13 Healthy Ways Winterize Your Routine</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">4</span>18 Things to Love About Our Follain Soap</div>
</div>
</div>
<div class="featured-post col-12">
<div class="featured-post--wrapper">
<div class="featured-post--body"><span class="featured-post--count">5</span><3 at First Site</div>
</div>
</div>
</div>
</div>
I have a header it contains two divs [ left div and right div ] and offset 4-cols before them . What i want is to make the right div at the middle of the header .
.header
{
background-color: #FFF;
padding: 15px;
}
.header .left img { width: 90%; }
.header .right > div { display: inline-block; }
.header .right span { color: #0095AE }
.header .right > span:first-child { font-size: 22px; }
.header .right > div p
{
font-weight: bold;
font-size: 13px;
margin:0;
padding: 0;
color: #0095AE
}
.header .right > div p:first-child { text-align: right }
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class ="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png" >
<div>
<p> الهلال الأحمر الأردني </p>
<p> JORDAN RED CRESCENT </p>
</div>
</div>
</div>
</div>
</div>
This how it looks , I tried padding 50% but doesn't work as what i want.
enter image description here
Not sure how exactly you want it. But from what i understand ,you can make use of display:flex here
check this snippet
.header {
background-color: #FFF;
padding: 15px;
}
.row {
display: flex;
justify-content: center;
}
.col-md-4 {
display: flex;
}
.col-md-4:last-child {}
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png">
<div>
<p>الهلال الأحمر الأردني</p>
<p>JORDAN RED CRESCENT</p>
</div>
</div>
</div>
</div>
</div>
Hope this helps
I have 2 columns of numbers that I want them to appear side by side. It works when I try using float: left but I want them to appear in the center. Without the float they appear one row then next row downwards.
body {
color: #fff;
text-align: center;
}
#roll, #roll2, #roll3, #roll4 {
width: 40px;
height: 360px;
background: #0077ee;
margin: 0 auto;
}
.roll-h {
width: 40px;
height: 120px;
margin: 0 auto;
overflow: hidden;
}
.shadow {
height: 40px;
margin: 0 auto;
transform: translateY(40px);
}
.black,
.his-h {
width: 40px;
height: 40px;
font-size: 20px;
line-height: 40px;
font-weight: 700;
text-align: center;
float: left;
}
.black {
background: black;
}
.floatleft {
float: left;
}
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll3">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll4">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
you have to add a parent (container) div around all your html with following styles:
<div style="margin:0 auto; display:inline-block">
see it here:
body {
color: #fff;
text-align: center;
}
#roll, #roll2, #roll3, #roll4 {
width: 40px;
height: 360px;
background: #0077ee;
margin: 0 auto;
}
.roll-h {
width: 40px;
height: 120px;
margin: 0 auto;
overflow: hidden;
}
.shadow {
height: 40px;
margin: 0 auto;
transform: translateY(40px);
}
.black,
.his-h {
width: 40px;
height: 40px;
font-size: 20px;
line-height: 40px;
font-weight: 700;
text-align: center;
float: left;
}
.black {
background: black;
}
.floatleft {
float: left;
}
.container {
display:inline-block;
margin:0 auto;
}
<div class="container">
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll3">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll4">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
</div>
you can center and keep items side by side using inline-block like this
.floatleft {
display: inline-block;
}