Make 4 responsive box in bootstrap - css

Hi I am trying to make this but my forth box goes to the bottom Here is my code.
Please help me to figure it out. Thanks everyone in advance.
<div class="offer">
<h2>Current Offers</h2>
<div class="container text-center">
<div class="row">
<div class="col-sm-3 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="images/img1.jpg" alt="Image 1">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
<div class="col-sm-3 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="images/img1.jpg" alt="...">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
<div class="col-sm-3 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="images/img1.jpg" alt="...">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
<div class="col-sm-3 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="images/img1.jpg" alt="...">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
</div>
</div>
and CSS
.thumbnail.checkout-thumbnail {
background: #eee;
border:none;
max-width: 220px;
}
.caption.checkout-caption {
margin-top: 2px;
}
.btn.btn-checkout {
border-radius: 0;
border: none;
background: none;
margin-top: 30px;
}
.btn.btn-orange {
border: 2px solid orange;
}
.btn.btn-teal {
border: 2px solid teal;
}
.btn.btn-red {
border: 2px solid red;
}
Please see the image here so that you can understand, I am trying to make it like this image

Your Code is working fine. Are you testing your code in small size screen (max 768px) or medium screen (min 769 and max 992). I have tested your code is in small screen and it is working fine. As you have divided 12 column into four col-sm-3.
But when it comes to medium screen you have divided your 12 column into only three col-md-4. According to your coding the fourth column definitely will go down in medium size screen. So If you want to maintain four columns in medium screen then you have to change your col-md-4 to col-md-3.

as i can see in you html code you have used col-md-4 instead of col-md-3,
i hope this resolves your query.
As you know bootstrap grid is of 12 columns so you have to use col-md-3 to get 4 columns in a row.

You should use
col-md-3
instead of
col-md-4
to show all four box in one row for Desktops having width ≥992px

Related

How do I have image ignore responsiveness until screen width is met?

I have a Bootstrap 4 project where whenever I minimize the screen a little bit, the image goes underneath the text column. How can I have it where when I minimize the screen it just clips out the image and doesn't send it to the bottom until the screen reaches a certain width? Right now it sends the image to the bottom way too soon.
<div class="container-xs" style="border:2px solid #cecece;">
<div class="row" style="border:2px solid #1ecbe1;">
<div class="core mx-auto">
<div class="BannerPosition">
<!--Banner Description-->
<p class="BannerText">
<div data-highlightword="Anything">
Anything Anything in Anything
</div>
</p>
<!--Download Badges-->
<img class="appleBadge" src="AppleBadge.jpg">
<img class="googleBadge" src="GoogleBadge.jpg">
</div>
</div>
//PROBLEM IS HERE
<div class="col">
<div class="d-flex flex-nowrap">
<img src="VampireCrew.jpg" style="border:2px solid #cecece;">
</div>
</div>
</div>
You can control when the image goes underneath the text by column by using Bootstrap’s columns with breakpoints.
I’ve modified your code to have two 12 column wide columns at the start (small screen) and then the columns switch to a 4 and an 8 from medium size displays and up. You can then use Bootstrap’s sizing utilities to adjust the margins if you want, and I added some CSS to adjust the text size from smaller screens to larger screens using Bootstrap’s normal breakpoints.
To keep the image fitting, I applied Bootstrap’s img-fluid class.
.orange {
color: #FD9B42;
}
.banner {
font-size: 1.25rem;
}
.apple-badge, .google-badge {
margin-bottom: 1rem;
}
#media (min-width:768px){
.banner {
font-size: 1.5rem;
}
}
#media (min-width:992px) {
.banner {
font-size: 2rem;
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-xs" style="border:2px solid #cecece;">
<div class="row" style="border:2px solid #1ecbe1;">
<div class="col-12 col-md-4 mb-5 mb-md-0">
<div class="BannerPosition text-center">
<!--Banner Description-->
<p class="banner orange">Anything</p>
<p class="banner">Anything</p>
<p class="banner">Anything in Anything</p>
<!--Download Badges-->
<img class="apple-badge" alt="Apple badge" src="http://via.placeholder.com/150x50.png?text=Apple">
<img class="google-badge" alt="Google badge" src="http://via.placeholder.com/150x50.png?text=Google">
</div>
</div>
<div class="col-12 col-md-8">
<img class="img-fluid" src="http://via.placeholder.com/1280x720.png?text=vampire" alt="Vampires" style="border:2px solid #cecece;">
</div>
</div>
</div>

Creating responsive materialize cards

We're using materialize cards to display images on our site. The images are user uploaded, so they come in all different sizes (though they have to be greater than 250px).
We're able to maintain the aspect ratio of the images, which is great, but we don't know how to do that while making the cards on each row the same height. That's our goal- to get the cards to be the same height (in a responsive way) while maintaining the aspect ratio of the images inside the cards.
We've been messing with this all day without getting very far. Any help is much appreciated.
HTML:
<div class="row text-center">
<div class="col-xs-12 col-md-4 col-sm-12 test">
<div class="card" ui-sref='forsaleitem({type:"interior"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://images.cdn.stuff.tv/sites/stuff.tv/files/Mercedes-AMG-GT-Interior-illuminated.jpg" class="img-rounded activator" alt="Cinque Terre">
</div>
<div class="card-content">
<h5 class='text-center'>Interior</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12 test">
<div class="card" ui-sref='forsaleitem({type:"drivetrain"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.revworksinc.com/assets/images/products/subaru/exedy/exedy_brz_twindisc.jpg" class="img-rounded activator" alt="Cinque Terre">
</div>
<div class="card-content">
<h5 class='text-center'>Drivetrain</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12 test">
<div class="card" ui-sref='forsaleitem({type:"performance"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.autonotas.tv/wp-content/uploads/2015/05/SHW_0323-1024x603.jpg" alt="Cinque Terre">
</div>
<div class="card-content">
<h5 class='text-center'>Performance</h5>
</div>
</div>
</div>
</div>
CSS:
.card {
position: relative;
background-color: #f4f4f4;
// margin: 10px auto;
height: 100%;
box-shadow: 1px 1px 10px 1px rgba(0, 0, 0, 0.7);
}
.card {
height: 100%;
}
.card .card-image img {
//object-fit: contain !important;
}
Use Media Queries to set the width/height depending on the size of the screen. Example in JS Fiddle: https://jsfiddle.net/3yegzwex/
HTML:
<div class="row text-center">
<div class="col-xs-12 col-md-4 col-sm-12">
<div class="card" ui-sref='forsaleitem({type:"interior"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://images.cdn.stuff.tv/sites/stuff.tv/files/Mercedes-AMG-GT-Interior-illuminated.jpg" class="img-rounded activator resizeimg" alt="Cinque Terre" height="226">
</div>
<div class="card-content">
<h5 class='text-center'>Interior</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12">
<div class="card" ui-sref='forsaleitem({type:"drivetrain"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.revworksinc.com/assets/images/products/subaru/exedy/exedy_brz_twindisc.jpg" class="img-rounded activator resizeimg" alt="Cinque Terre" height="226">
</div>
<div class="card-content">
<h5 class='text-center'>Drivetrain</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12">
<div class="card" ui-sref='forsaleitem({type:"performance"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.autonotas.tv/wp-content/uploads/2015/05/SHW_0323-1024x603.jpg" class="img-rounded activator resizeimg" alt="Cinque Terre" height="226">
</div>
<div class="card-content">
<h5 class='text-center'>Performance</h5>
</div>
</div>
</div>
</div>
CSS:
.card {
text-align: center;
}
#media (max-width: 990px) {
.resizeimg {
height: auto;
}
}
#media (min-width: 1000px) {
.resizeimg {
width: auto;
height: 350px;
}
}
Do the images really have to be inline? Or can they be set as background-image (since they are user uploaded)? If so, you can set the background-size property to cover to address the problem. Also because object-fit is not widely supported (yet).
cover
A keyword that is the inverse of contain. Scales the image as large as possible and maintains image aspect ratio (image doesn't
get squished). The image "covers" the entire width or height of the
container. When the image and container have different dimensions, the
image is clipped either left/right or top/bottom.
Source: MDN
See this updated JSFiddle for the demo. The padding-bottom can be altered to a percentage for your needs. Try to change it and see what it does.
Inline images
If the images do have to be inline, you can apply this solution:
.card-image {
width: 100%;
padding-bottom: 50%;
overflow: hidden;
position: relative;
}
.card-image img {
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
The image will be pushed inside the .card-image and stretched to its width that's needed. See this JSFiddle for the demo. The padding-bottom can be altered to a percentage to your needs.

create 3 responsive box with background color and Image [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hi guys I am using Bootstrap and trying to build 3 grey color boxes with background image at the top and a text at below and button. but I am unable to do this I need your help to make it successful This is what I am trying to achieve
<div class="col-sm-6 col-md-4">
<div class="media services-wrap wow fadeInDown">
<div class="pull-left">
<img class="img-responsive" src="images/img1.jpeg">
</div>
<div class="media-body">
<h3 class="media-heading">Text 1</h3>
<p>CHeck out Button</p>
</div>
</div>
</div>
You can do this with Bootstrap Custom Content as a base instead of the Media object you're currently using. Then just apply the styling you want.
*Note this is based of a specific image size so these rules will need to be adjusted based on the actual image size you end up using.
See working Example Snippet.
.thumbnail.checkout-thumbnail {
background: #eee;
border: none;
max-width: 370px;
margin: 5px auto;
}
.caption.checkout-caption {
margin-top: 20px;
}
.btn.btn-checkout {
border-radius: 0;
border: none;
background: none;
margin-top: 30px;
}
.btn.btn-orange {
border: 2px solid orange;
}
.btn.btn-teal {
border: 2px solid teal;
}
.btn.btn-red {
border: 2px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container text-center">
<div class="row">
<div class="col-sm-6 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="http://placehold.it/350x200" alt="...">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
<div class="col-sm-6 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="http://placehold.it/350x200" alt="...">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
<div class="col-sm-6 col-md-4">
<div class="thumbnail checkout-thumbnail">
<img src="http://placehold.it/350x200" alt="...">
<div class="caption checkout-caption">
<h3>House and Land Packages</h3>
<p>Check out Button
</p>
</div>
</div>
</div>
</div>
</div>

Bootstrap Thumbnails Leave gaps in between

I'm trying to make a grid of Boostrap unevenly sized thumbnails. But some thumbnails are uneven, resulting in huge gaps between some rows.
I don't have any styling on the thumbnails.
Is there a way to fix it without adding something like Masonry/Isotope/Salvattore?
You can use two <div> or two .row tags like this:
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<p>Thumbnail caption</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<p>Thumbnail caption</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<p>Thumbnail caption</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<p>Thumbnail caption</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<p>Thumbnail caption</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<img src="..." alt="...">
<div class="caption">
<p>Thumbnail caption</p>
</div>
</div>
</div>
</div>
For more info visit Example: Stacked-to-horizontal.
The cleanest way to fix your layout is to use a masonry type of layout. It will allow for the smoothest look and be a very fluid and responsive layout when dealing with mixed sized media. Though if you are in complete control of the data/images being placed on the site I would suggest creating each image to be identical in size and type. If you would like I can provide an example I have created using a masonry type of layout with thumbnails and Bootstrap.
Edit to add example code:
/* CSS styles */
.row {
-moz-column-width: 12em;
-webkit-column-width: 12em;
-moz-column-gap: 1em;
-webkit-column-gap:1em;
column-width: 12em;
column-gap: 1em;
column-fill: balance;
width: 100%;
}
/* Outer div block */
.section-block {
display: block;
padding: .25rem;
width: 100%;
}
/* Inner div block */
.section-item {
position:relative;
display: inline-block;
width: 100%;
}
.section-item img{
width: 100%;
}
//Wrapper for each img you are adding
<div class='section-block'>
<div class='section-item'>
<div>
<a href='#' class='thumbnail' data-toggle='modal' data-target='#id'>
<img src='/imgs/image.jpg'>
<p class='caption'>Image Caption</p>
</a>
</div>
</div>
</div>
I used this in conjunction with php to get all my images from a db then I looped over each image and echo'd to the page with the above syntax. This should work without having to use any additional js libraries beyond what you are using for bootstrap. This gives you a very responsive masonry style of layout that works in modern browsers.

Bootstrap, layout only works at small screen sizes

I have a jsfiddle here - http://jsfiddle.net/7psczxog/5/
It's just two blocks that contain an image and some text in two separate divs.
At smaller sizes the image and text sit on top of each other.
Each block also has a triangle that should site in the middle at the bottom of the block.
My problem is the blocks only work at smaller sizes when the image is on top of the text.
At larger sizes the block has no background color and the triangle moves to the top.
<div class="container">
<div class="row">
<div class="testimonialBlock triangle-section clearfix block0">
<div class="col-sm-4">
<img src="http://placehold.it/350x150" alt="image" class="img-responsive"/>
</div>
<div class="col-sm-8">
<h4>Trader Testimonial 1</h4>
<h5>Trader Testimonial By 1</h5>
<p>Trader Testimonial Text 1</p>
</div>
</div><!--testimonialBlock-->
</div>
<div class="row">
<div class="testimonialBlock triangle-section clearfix block1">
<div class="col-sm-4">
<img src="http://placehold.it/350x150" alt="image" class="img-responsive"/>
</div>
<div class="col-sm-8">
<h4>Trader Testimonial 2</h4>
<h5>Trader Testimonial By 2</h5>
<p>Trader Testimonial Text 2</p>
</div>
</div><!--testimonialBlock-->
</div>
Is this what you are looking for?
http://jsfiddle.net/prsne4a7/
HTML:
<div class="container">
<div class="triangle-section-row row">
<div class="testimonialBlock triangle-section block0">
<div class="col-xs-4">
<img src="http://placehold.it/350x150" alt="image" class="img-responsive"/>
</div>
<div class="col-xs-8">
<h4>Trader Testimonial 1</h4>
<h5>Trader Testimonial By 1</h5>
<p>Trader Testimonial Text 1</p>
</div>
</div><!--testimonialBlock-->
</div>
<div class="triangle-section-row row">
<div class="testimonialBlock triangle-section block1">
<div class="col-xs-4">
<img src="http://placehold.it/350x150" alt="image" class="img-responsive"/>
</div>
<div class="col-xs-8">
<h4>Trader Testimonial 2</h4>
<h5>Trader Testimonial By 2</h5>
<p>Trader Testimonial Text 2</p>
</div>
</div><!--testimonialBlock-->
</div>
</div>
CSS:
.triangle-section-row{
background: red;
margin: 0 0 50px 0;
position: relative;
}
.triangle-section:after{
border-style: solid;
border-width: 20px 20px 0 20px;
border-color: red transparent transparent transparent;
bottom: -20px;
left: 50%;
content: "";
height: 0;
margin-left:-20px;
width: 0;
position: absolute;
}
I just bumped the position: relative to the parent of .triangle-section and used col-xs-* instead of col-sm-* to keep the columns consistent across all client widths. col-sm-* only enforces the columns when the client area width is greater than 768px.
See the Bootstrap grid documentation for more information about the responsive grid:
http://getbootstrap.com/css/#grid-options

Resources