I developed a bootstrap card, inside that bootstrap card I am putting another one.
My problem is that when I reduce the screen size the text comes out of the card and also overlays the image, how can I solve this?
Demo
code
<div class="card-deck cardsZone">
<div class="card myCards">
<div class="card-body">
<div *ngFor="let pr of ProgressDashTasks">
<div class="card mysmallCcards">
<div class="card-body">
<div class="row">
<div class="col-sm-2">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgDash">
</div>
<div class="col-sm-8">
<span class="brandName">MY PERCENTAGE</span>
<p class="subtitledash">New percentage</p>
</div>
</div>
<hr class="solid">
<div class="row">
<div class="col-xs-6">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgusersDash">
</div>
<div class="col-xs-6">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgusersDash">
</div>
<div class="col-xs-6">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgusersDash">
</div>
</div>
Card link
Another link
</div>
</div>
</div>
</div>
</div>
</div>
Image Problem
On .cardsZone you have to use a relative width and not an absolute one. Use width: fit-content:
.cardsZone{
margin-top: 5%;
width: fit-content;
height: 70%;
margin-right: auto;
margin-left: auto;
}
.myCards{
background: #E7EAF180 0% 0% no-repeat padding-box;
box-shadow: 0px 3px 20px #BCBCCB47;
border-radius: 8px;
border: none;
}
.card-deck .card {
margin-left: 0px;
}
.mysmallCcards{
width: 100%;
background: #FFFFFF 0% 0% no-repeat padding-box;
box-shadow: 0px 3px 20px #BCBCCB47;
border-radius: 8px;
border: none;
margin-top: 20px;
}
.card-header:first-child {
border-radius: calc(9px - 1px) calc(9px - 1px) 0 0;
}
.mycardHeader{
background-color: white;
}
.imgDash{
width: 40px;
height: 40px;
border-radius: 8px;
}
.brandName{
text-align: left;
font-family: 'Noto Sans', sans-serif;
font-size: 22px;
letter-spacing: 0;
color: #4D4F5C;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: 0px;
font-weight: re;
}
.subtitledash{
text-align: left;
font-family: 'Noto Sans', sans-serif;
font-size: 13px;
font-weight: bold;;
letter-spacing: 0;
color: #4D4F5C;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.imgusersDash{
width: 24px;
height: 24px;
transform: matrix(1, 0, 0, 1, 0, 0);
border-radius: 8px;
margin-left: 15px;
}
hr.solid {
border-top: 1px solid #999;
width:100%
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="card-deck cardsZone">
<div class="card myCards">
<div class="card-body">
<div *ngFor="let pr of ProgressDashTasks">
<div class="card mysmallCcards">
<div class="card-body">
<div class="row">
<div class="col-sm-2">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgDash">
</div>
<div class="col-sm-8">
<span class="brandName">MY PERCENTAGE</span>
<p class="subtitledash">New percentage</p>
</div>
</div>
<hr class="solid">
<div class="row">
<div class="col-xs-6">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgusersDash">
</div>
<div class="col-xs-6">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgusersDash">
</div>
<div class="col-xs-6">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Circle-icons-tools.svg/1024px-Circle-icons-tools.svg.png" class="img-responsive imgusersDash">
</div>
</div>
Card link
Another link
</div>
</div>
</div>
</div>
</div>
</div>
I am making a grid system with Bootstrap 3.3.7. The width of the container is 1200px.
When I resize the browser window to < 768 px the columns on "Grid 1 + 2 + 3" are not reacting to the col-xs-xx i set. See the demo here.
When I set the columns to have a width on800 px instead of 600 px the width is correct on smaller screens, but the columns do not fit on bigger screens, unless I set a very big height on the columns.
How can I set the columns to get the correct width when the screen is below 768 px?
body {
background-color: #f5f5f5;
}
div {
background-color: #fff;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content {
/*margin-bottom: 20px;*/
/*padding: 50px 0px;*/
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
height: 350px;
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
.index-content .blue-button {
width: 100px;
-webkit-transition: background-color 1s, color 1s;
/* For Safari 3.1 to 6.0 */
transition: background-color 0.5s, color 0.5s;
min-height: 20px;
background-color: #002E5B;
color: #ffffff;
border-radius: 4px;
text-align: center;
font-weight: lighter;
margin: 0px 20px 15px 20px;
padding: 5px 0px;
display: inline-block;
}
.index-content .blue-button:hover {
background-color: #dadada;
color: #002E5B;
}
/* GRID ELEMENTS MEDIA QUERIES */
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
}
.margin_bottom{
margin-bottom:10px;
}
.row [class*="col-"]{
padding-right: 5px;
padding-left: 5px;
}
.row {
margin-left: -5px;
margin-right: -5px;
}
.card-img-bottom {
color: #fff;
height: 20rem;
background: url(images/img1.jpg) center no-repeat;
background-size: cover;
}
<div class="container">
<h3>Grid 1</h3>
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-6 margin_bottom">
<img src="http://placehold.it/600x600" alt="5" class="img-responsive"></img>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12 margin_bottom">
<img src="http://placehold.it/600x300" alt="5" class="img-responsive"></img>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
</div>
</div>
<h3>Grid 2</h3>
<div class="row">
<div class="col-xs-12 col-sm-4 margin_bottom">
<img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-12 col-sm-4">
<div class="row">
<div class="col-xs-6 col-sm-12 margin_bottom">
<img src="http://placehold.it/400x245" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-6 col-sm-12 margin_bottom">
<img src="http://placehold.it/400x250" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-4 margin_bottom">
<img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
</div>
</div>
<h3>Grid 3</h3>
<div class="row">
<div class="col-xs-3 col-sm-3 margin_bottom">
<!-- I can change the width to 800px to fit the xs viewport. But then the height on the column om sm viewport have to be 1020 px, which is way to high after my opnion -->
<img src="http://placehold.it/300x610" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-9 col-sm-6 margin_bottom">
<img src="http://placehold.it/600x600" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-12 col-sm-3 margin_bottom">
<div class="row">
<div class="col-xs-6 col-sm-12 margin_bottom">
<img src="http://placehold.it/300x300" alt="5" class="img-responsive"></img>
</div>
<div class=" col-xs-6 col-sm-12">
<img src="http://placehold.it/300x300" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
</div>
Grids are reacting as they should be. When col-xx-xx are nested, they assume their parent containers width to be 100%. You'll find more info on bootstrap doc page See Two columns with two nested columns.
Your html code has lot of redundant html divs. For ex. your grid 1 can be like this
<h3>Grid 1</h3>
<div class="row">
<div class="col-sm-6 margin_bottom">
<img src="http://placehold.it/600x600" alt="5" class="img-responsive"></img>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12 margin_bottom">
<img src="http://placehold.it/600x300" alt="5" class="img-responsive"></img>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
Your dont need both col-xs-6 col-sm-6, just col-xs-6 will get job done.
I am trying to make a grid containing a banner and 4 columns. The example can be seen here.
The space between the lines are 10px, but I cannot make the boxes fit so they are following the line in the grid. When I look at the code it is looking correct to me. So I was thinking it could be the size of the pictures the was to small. But changing the size does not solve my problem.
Does anybody knows how I can make my grid elements fit the below lines on the picture?
My code:
(I have cut away some HTML code there is not relevant for the question)
/* Card and Button */
body {
background-color: #f5f5f5;
}
div {
background-color: #fff;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content {
/*margin-bottom: 20px;*/
/*padding: 50px 0px;*/
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
height: 350px;
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
.index-content .blue-button {
width: 100px;
-webkit-transition: background-color 1s, color 1s;
/* For Safari 3.1 to 6.0 */
transition: background-color 0.5s, color 0.5s;
min-height: 20px;
background-color: #002E5B;
color: #ffffff;
border-radius: 4px;
text-align: center;
font-weight: lighter;
margin: 0px 20px 15px 20px;
padding: 5px 0px;
display: inline-block;
}
.index-content .blue-button:hover {
background-color: #dadada;
color: #002E5B;
}
/* Set width between block elements */
.small-padding.top {
padding-top:10px;
}
.small-padding.bottom {
padding-bottom:10px;
}
.small-padding.left {
padding-left:5px;
}
.small-padding.right {
padding-right:5px;
}
.row [class*="col-"] {
padding-left: 5px;
padding-right: 5px;
}
/* GRID ELEMENTS MEDIA QUERIES */
#media only screen and (max-width: 768px) {
.index-content .col-lg-4 {
margin-top: 20px;
}
.small-padding.bottom {
padding-bottom:10px;
}
div {
background-color: #fff;
padding-left: 2px;
padding-right: 2px;
}
.row [class*="col-"] {
padding-left: 5px;
padding-right: 5px;
}
}
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
}
#media (min-width: 991px) {
.medium-padding.top {
padding-top:10px;
}
.medium-padding.bottom {
padding-bottom:10px;
}
.medium-padding.left {
padding-left:5px;
}
.medium-padding.right {
padding-right:5px;
}
}
<div class="container">
<!-- Col md 3 - 3 - 3 - 3 + Col sm 6 -6 -->
<div class="row">
<div class="col-sm-6 col-md-3 small-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding bottom left medium-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding left bottom medium-padding right bottom left">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding left bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg" class="img-responsive"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 small-padding right bottom ">
<img src="http://placehold.it/600x400" alt="1" class="img-responsive center-block"></img>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-xs-6 small-padding right bottom">
<img src="http://placehold.it/300x205" alt="2" class="img-responsive"></img>
</div>
<div class="col-xs-6 small-padding right left bottom">
<img src="http://placehold.it/300x205" alt="3" class="img-responsive"></img>
</div>
<div class="col-xs-6 small-padding right bottom">
<img src="http://placehold.it/300x205" alt="4" class="img-responsive"></img>
</div>
<div class="col-xs-6 small-padding right left bottom">
<img src="http://placehold.it/300x205" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
Please don't use the class "col-" with the class "row" for same element.
Like this.
<div class="row col-sm-6">
Because class name "row" had margin-right:-15px; and margin-left:-15px; If you use class name "col-" it will affect the row style with padding-right:15px; and padding-left:15px;
This is the main reason for this issue, Please add one more div structure like following method
<div class="col-sm-6">
<div class="row">
</div>
</div>
Output:
Please remove all style you write for col-- and row. Use this style for that
.margin_bottom{margin-bottom:10px;}
.row [class*="col-"]{ padding-left: 5px; padding-right: 5px; }
.row { margin-left: -5px; margin-right: -5px; }
And use this html code
<div class="row">
<div class="col-sm-6 col-md-3 margin_bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 margin_bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 margin_bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 margin_bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg" class="img-responsive"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 margin_bottom">
<img src="http://placehold.it/600x400" alt="1" class="img-responsive center-block"></img>
</div>
<div class=" col-sm-6">
<div class="row">
<div class="col-xs-6 margin_bottom">
<img src="http://placehold.it/300x205" alt="2" class="img-responsive"></img>
</div>
<div class="col-xs-6 margin_bottom">
<img src="http://placehold.it/300x205" alt="3" class="img-responsive"></img>
</div>
<div class="col-xs-6 margin_bottom">
<img src="http://placehold.it/300x205" alt="4" class="img-responsive"></img>
</div>
<div class="col-xs-6 margin_bottom">
<img src="http://placehold.it/300x205" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
Output:
There are a bunch of problems with your code.
One of them is that you use BS3 and not 4. BS3 is using float which is a bad practice. Please use BS4 with flex. Everything is much easier.
Another one is that you use 2 completely different classes on the same element. row and col- should never be used on the same element. In your case you need row inside the column.
I changed that in your html and added some css at the top of the file. This should help you achieve what you want.
Again i stress out that you should use BS4.
/* Card and Button */
.row.mx-0 {
margin-left:0;
margin-right:0;
}
.row .col-sm-6.no-padding {
padding-right:0;
padding-left:0;
}
.row .col-sm-6.no-bottom {
padding-bottom:0;
}
body {
background-color: #f5f5f5;
}
div {
background-color: #fff;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content {
/*margin-bottom: 20px;*/
/*padding: 50px 0px;*/
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
height: 350px;
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
.index-content .blue-button {
width: 100px;
-webkit-transition: background-color 1s, color 1s;
/* For Safari 3.1 to 6.0 */
transition: background-color 0.5s, color 0.5s;
min-height: 20px;
background-color: #002E5B;
color: #ffffff;
border-radius: 4px;
text-align: center;
font-weight: lighter;
margin: 0px 20px 15px 20px;
padding: 5px 0px;
display: inline-block;
}
.index-content .blue-button:hover {
background-color: #dadada;
color: #002E5B;
}
/* Set width between block elements */
.small-padding.top {
padding-top:10px;
}
.small-padding.bottom {
padding-bottom:10px;
}
.small-padding.left {
padding-left:5px;
}
.small-padding.right {
padding-right:5px;
}
.row [class*="col-"] {
padding-left: 5px;
padding-right: 5px;
}
/* GRID ELEMENTS MEDIA QUERIES */
#media only screen and (max-width: 768px) {
.index-content .col-lg-4 {
margin-top: 20px;
}
.small-padding.bottom {
padding-bottom:10px;
}
div {
background-color: #fff;
padding-left: 2px;
padding-right: 2px;
}
.row [class*="col-"] {
padding-left: 5px;
padding-right: 5px;
}
}
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
}
#media (min-width: 991px) {
.medium-padding.top {
padding-top:10px;
}
.medium-padding.bottom {
padding-bottom:10px;
}
.medium-padding.left {
padding-left:5px;
}
.medium-padding.right {
padding-right:5px;
}
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<!-- Col md 3 - 3 - 3 - 3 + Col sm 6 -6 -->
<div class="row">
<div class="col-sm-6 col-md-3 small-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding bottom left medium-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding left bottom medium-padding right bottom left">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding left bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg" class="img-responsive"></img>
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 small-padding right bottom no-bottom">
<img src="http://placehold.it/600x400" alt="1" class="img-responsive center-block"></img>
</div>
<div class="col-sm-6 no-padding">
<div class="row mx-0">
<div class="col-xs-6 small-padding right bottom">
<img src="http://placehold.it/300x205" alt="2" class="img-responsive"></img>
</div>
<div class="col-xs-6 small-padding right left bottom">
<img src="http://placehold.it/300x205" alt="3" class="img-responsive"></img>
</div>
<div class="col-xs-6 small-padding right bottom">
<img src="http://placehold.it/300x205" alt="4" class="img-responsive"></img>
</div>
<div class="col-xs-6 small-padding right left bottom">
<img src="http://placehold.it/300x205" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
</div>
#MK-DK please never use row and col to-gether in a div. please check the below example for a working fix with minor changes to you html and css.
/* Card and Button */
.row.mx-0 {
margin-left: 0;
margin-right: 0;
}
.row .col-sm-6.no-padding {
padding-right: 0;
padding-left: 0;
}
.row .col-sm-6.no-bottom {
padding-bottom: 0;
}
body {
background-color: #f5f5f5;
}
div {
background-color: #fff;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
height: 350px;
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
.index-content .blue-button {
width: 100px;
-webkit-transition: background-color 1s, color 1s;
/* For Safari 3.1 to 6.0 */
transition: background-color 0.5s, color 0.5s;
min-height: 20px;
background-color: #002E5B;
color: #ffffff;
border-radius: 4px;
text-align: center;
font-weight: lighter;
margin: 0px 20px 15px 20px;
padding: 5px 0px;
display: inline-block;
}
.index-content .blue-button:hover {
background-color: #dadada;
color: #002E5B;
}
/* Set width between block elements */
.small-padding.top {
padding-top: 10px;
}
.small-padding.bottom {
padding-bottom: 10px;
}
.small-padding.left {
padding-left: 5px;
}
.small-padding.right {
padding-right: 5px;
}
.row [class*="col-"] {
padding-left: 5px;
padding-right: 5px;
}
/* GRID ELEMENTS MEDIA QUERIES */
#media only screen and (max-width: 768px) {
.index-content .col-lg-4 {
margin-top: 20px;
}
.small-padding.bottom {
padding-bottom: 10px;
}
div {
background-color: #fff;
padding-left: 2px;
padding-right: 2px;
}
.row [class*="col-"] {
padding-left: 5px;
padding-right: 5px;
}
}
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
}
#media (min-width: 991px) {
.medium-padding.top {
padding-top: 10px;
}
.medium-padding.bottom {
padding-bottom: 10px;
}
.medium-padding.left {
padding-left: 5px;
}
.medium-padding.right {
padding-right: 5px;
}
}
/* Custom css added to fix the margin */
#media (min-width: 768px) {
.row-small-gutters {
margin: 0 -5px !important
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<!-- Col md 3 - 3 - 3 - 3 + Col sm 6 -6 -->
<div class="row">
<div class="col-sm-6 col-md-3 small-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg">
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding bottom left medium-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg">
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding left bottom medium-padding right bottom left">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg">
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-3 small-padding left bottom">
<div class="index-content">
<div class="card">
<img src="https://image.ibb.co/iiWA2T/bmw_1.jpg" class="img-responsive">
<div class="card-content">
<h4>BMW NEW MODELS</h4>
Read More
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 small-padding right bottom ">
<img src="http://placehold.it/600x400" alt="1" class="img-responsive center-block">
</div>
<div class="col-sm-6">
<div class="row row-small-gutters">
<div class="col-xs-6 small-padding right bottom">
<img src="http://placehold.it/300x205" alt="2" class="img-responsive">
</div>
<div class="col-xs-6 small-padding right left bottom">
<img src="http://placehold.it/300x205" alt="3" class="img-responsive">
</div>
<div class="col-xs-6 small-padding right bottom">
<img src="http://placehold.it/300x205" alt="4" class="img-responsive">
</div>
<div class="col-xs-6 small-padding right left bottom">
<img src="http://placehold.it/300x205" alt="5" class="img-responsive">
</div>
</div>
</div>
</div>
</div>
Your HTML structure should be like
<div class="container">
<div class="row">
<div class="col-sm-6"><img/></div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-6"><img/></div>
<div class="col-sm-6"><img/></div>
<div class="col-sm-6"><img/></div>
<div class="col-sm-6"><img/></div>
</div>
</div>
</div>
</div>
Here is plunker code
https://plnkr.co/edit/KbUTxzDRvnQjNYsH4wpm?p=preview
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>
Hoping someone can help me figure out what I am missing. Right now, the rows are overlapping. I want the two rows to be spaced out appropriately, based off of the size of the images (they are all same size). I have no idea what I am missing to make this respond the way I want it to.
Code
img {
max-width: 100%;
-webkit-backface-visibility: hidden;
}
.gallery-project-thumb {
position: relative;
}
.vert-pad {
padding-top: 30px;
padding-bottom: 30px;
}
.gallery-project-thumb img:first-child {
border: 8px solid #fff;
-webkit-box-shadow: 0 0 6px 0.5px rgba(0,0,0,.5);
-moz-box-shadow: 0 0 6px .5px rgba(0,0,0,.5);
box-shadow: 0 0 6px 0.5px rgba(0,0,0,.5);
position: absolute;
z-index: 3;
-webkit-backface-visibility: hidden;
display: block;
}
.gallery-project-thumb img:nth-child(2) {
z-index: 2;
margin-bottom: 15px;
border: 8px solid #fff;
-webkit-box-shadow: 0 0 6px 1px rgba(0,0,0,.5);
-moz-box-shadow: 0 0 6px 1px rgba(0,0,0,.5);
box-shadow: 0 0 6px 1px rgba(0,0,0,.5);
position: absolute;
-ms-transform: rotate(-2deg);
-webkit-transform: rotate(-2deg);
transform: rotate(-2deg);
-webkit-backface-visibility: hidden;
}
.gallery-project-thumb img:nth-child(3) {
z-index: 1;
margin-bottom: 15px;
border: 8px solid #fff;
-webkit-box-shadow: 0 0 6px 1px rgba(0,0,0,.5);
-moz-box-shadow: 0 0 6px 1px rgba(0,0,0,.5);
box-shadow: 0 0 6px 1px rgba(0,0,0,.5);
position: absolute;
-ms-transform: rotate(2deg);
-webkit-transform: rotate(2deg);
transform: rotate(2deg);
-webkit-backface-visibility: hidden;
}
<div class="row vert-pad gallery-project-container" style="margin-left: 75px; margin-right: 20px;">
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
</div>
<div class="row vert-pad gallery-project-container" style="margin-left: 75px; margin-right: 20px;">
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="gallery-project-thumb"><img src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"> <img class="gallery-project-thumb-background" src="https://via.placeholder.com/840x560"></div>
</div>
</div>
Because the images are being absolutely positioned, the browser doesn't know how tall to make those element. If you set a height to the .gallery-project-thumb class as the height of the image you should be set
.gallery-project-thumb{
height: 300px;
}