horizontally align image/content with media query - css

I have a row of images with title and descriptions, that when the window is downsized to 991px or fewer in width, the list should be vertical, with the title and description to the right of the image, not below it.
<div class="row">
<div class="col-md-2">
<img src="http://placehold.it/150x150">
<h5 class="story-title">Title of the store goes here</h5>
<h6>Description</h6>
</div>
<div class="col-md-2">
<img src="http://placehold.it/150x150">
<h5 class="story-title">Title of the store goes here</h5>
<h6>Description</h6>
</div>
<div class="col-md-2">
<img src="http://placehold.it/150x150">
<h5 class="story-title">Title of the store goes here</h5>
<h6>Description</h6>
</div>
<div class="col-md-2">
<img src="http://placehold.it/150x150">
<h5 class="story-title">Title of the store goes here</h5>
<h6>Description</h6>
</div>
<div class="col-md-2">
<img src="http://placehold.it/150x150">
<h5 class="story-title">Title of the store goes here</h5>
<h6>Description</h6>
</div>
<div class="col-md-2">
<img src="http://placehold.it/150x150">
<h5 class="story-title">Title of the store goes here</h5>
<h6>Description</h6>
</div>
#media (max-width: 991px), (max-height: 460px) {
.col-md-2:hover {
background-color: transparent;
}
.col-md-2 {
display: inline-block;
float: left;
}
}
JSFIDDLE

JSFiddle
You're targeting the wrong elements. Your container doesn't need to be pushed to display: inline-block or floated. The elements within it do:
#media (max-width: 991px), (max-height: 460px) {
.col-md-2:hover{
background-color: transparent;
}
.col-md-2 img {
float: left;
}
.col-md-2 {
overflow: auto;
}
}

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.

Make 4 responsive box in bootstrap

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

How to create a 5 equal columns in Bootstrap 3?

I am creating a selection link that has 10 containers. And what I want is to divide them into 5 equal columns. Now my problem is I want to expand the width of the columns. Means I dont have a container class in my parent row.
Here's my sample code:
<div id="categories-selections">
<div class="col-md-2 no-padding">
<img src="public/images/cat1.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat2.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat3.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat4.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat5.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat6.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat7.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat8.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat9.png" class="img-responsive" />
</div>
<div class="col-md-2 no-padding">
<img src="public/images/cat10.png" class="img-responsive" />
</div>
</div>
Here's what should be the output:
And here's what I have:
That's all guys I hope you can help me.
Here's the sample fiddle:
https://jsfiddle.net/mk7bdyey/
You could just create a whole new column all together
.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
position: relative;
min-height: 1px;
padding-right: 10px;
padding-left: 10px;
}
Next you need to define width of new classes in case of different media queries.
.col-xs-15 {
width: 20%;
float: left;
}
#media (min-width: 768px) {
.col-sm-15 {
width: 20%;
float: left;
}
}
#media (min-width: 992px) {
.col-md-15 {
width: 20%;
float: left;
}
}
#media (min-width: 1200px) {
.col-lg-15 {
width: 20%;
float: left;
}
}
then you can just use like this
<div class="row">
<div class="col-md-15 col-sm-3">
...
</div>
</div>
Adjust the padding from left and right as per your requirement to the div in which you have given id="categories-selections". you can put in-line css like style="padding-left:30px; padding-right:30px;"

Bootstrap modal width

I am trying to make a modal popup change it's width so that it matches col-lg-8, col-xs-10
But I just found that modal is fixed width.
So, then I found a css styling that can change the width:
<div class="modal fade" id="mdlBudgets" role="dialog">
<div class="modal-dialog">
<div class="modal-content modal-graph col-lg-8 col-xs-10 well well-sm">
<div class="row">
<div class="col-xs-12">
<span class="glyphicon glyphicon-align-left debit_colour"></span> <strong>Budgets</strong>
</div>
</div>
#if (Model.BarDescriptions.Length == 0)
{
<small><span class="glyphicon glyphicon-info-sign debit_colour"></span> You have no Budgets setup yet.</small>
}
else
{
<div id="budgets"></div>
}
<div class="row">
<div class="col-xs-12 text-right"><span class="glyphicon glyphicon-list"></span> View Budgets</div>
</div>
</div>
</div>
</div>
CSS:
body .modal-graph {
/* new custom width */
width: 700px;
/* must be half of the width, minus scrollbar on the left (30px) */
margin-left: 350px;
}
However, firstly, it's off centre, but my biggest issue is - it's a fixed size. Is there a way to make my modal-graph act like col-lg-8, col-xs-10 ?
As you said .modal-dialog has fixed width so you have to overwrite it. Then to use col-xx-xx class, you have to center them. Something like:
<div class="modal fade" id="mdlBudgets" role="dialog">
<div class="modal-dialog as-container">
<div class="modal-content modal-graph col-lg-8 col-xs-10 well well-sm">
<div class="row">
<div class="col-xs-12">
<span class="glyphicon glyphicon-align-left debit_colour"></span> <strong>Budgets</strong>
</div>
</div>
#if (Model.BarDescriptions.Length == 0)
{
<small><span class="glyphicon glyphicon-info-sign debit_colour"></span> You have no Budgets setup yet.</small>
}
else
{
<div id="budgets"></div>
}
<div class="row">
<div class="col-xs-12 text-right"><span class="glyphicon glyphicon-list"></span> View Budgets</div>
</div>
</div>
</div>
</div>
and css:
#media (min-width: 768px) {
.modal-dialog.as-container {
width: 750px;
}
}
#media (min-width: 992px) {
.modal-dialog.as-container {
width: 970px;
}
}
#media (min-width: 1200px) {
.modal-dialog.as-container {
width: 1170px;
}
}
.modal-dialog.as-container .modal-content {
float: none;
margin: auto;
}

Resources