I am currently having a problem where the bootstrap img-responsive class isn't working as it should due to me needing the image to be as far right in the div box as possible. I have two identically sized arrows which surrounds titles of my site. When the browser is scaled down to mobile size, the left arrow appears smaller and more distorted than the right counterpart.
Full Sized Title
Phone Sized Title
HTML:
<div class="row">
<div class="col-lg-3"> </div>
<div class="col-xs-3 col-lg-2 arrow-right">
<img class="img-responsive img-right" src="img/arrow-right.png" alt="">
</div>
<div class="col-xs-6 col-lg-2 text-center">
<h2 class="section-heading">RSVP</h2>
</div>
<div class="col-xs-3 col-lg-2 arrow-left">
<img class="img-responsive img-left" src="img/arrow-left.png" alt="">
</div>
<div class="col-lg-3"> </div>
</div>
CSS:
.arrow-right {
padding-top: 12px;
}
.arrow-left {
padding-top: 12px;
padding-left: 0;
}
#media (min-width: 768px) {
.img-right {
display: block;
margin: auto;
margin-left: 34px;
}
.img-left {
margin: auto;
margin-right: 30px;
}
}
My question would be, is there an easier way to get these arrows as close to the titles as possible and have them scale down to phone sized perfectly?
Change the XS and make 4/4/4
<div class="row">
<div class="col-lg-3"> </div>
<div class="col-xs-4 col-lg-2 arrow-right">
<img class="img-responsive img-right" src="img/arrow-right.png" alt="">
</div>
<div class="col-xs-4 col-lg-2 text-center">
<h2 class="section-heading">RSVP</h2>
</div>
<div class="col-xs-4 col-lg-2 arrow-left">
<img class="img-responsive img-left" src="img/arrow-left.png" alt="">
</div>
<div class="col-lg-3"> </div>
</div>
I think the blurry image is due to display: block, for getting the image as close to the text as possible you could consider using ::after or ::before pseudo-elements. Also you could try the following HTML:
<div class="col-xs-3 col-lg-2 arrow-right">
</div>
<div class="col-xs-12 col-lg-6 text-center">
<img class="img-responsive img-right" src="img/arrow-right.png" alt="">
<h2 class="section-heading">RSVP</h2>
<img class="img-responsive img-left" src="img/arrow-left.png" alt="">
</div>
</div>
</div>
Also, could you post a fiddle or http://www.bootply.com/?
EDIT -- (after bootply response)
using a little CSS i got it working (without the use of media queries etc.). The CSS is now a lot less and I hope this is what you are looking for (because the images are as close as possible to the text). Using float: left to the img, h2 and a little padding-top: 24px for the images got it lined up. See bootply:
http://www.bootply.com/2Hp6stSs9B
Related
I am struggling with creating a responsive image gallery. I am using CSS and bootstrap, i tried with tag and as background, I couldnt get it to work.
so, this is what I want to achieve:
https://www.socialprintstudio.com/products/
image grid without image warp or overlapping
When you make your browser smaler, image aspect ratio stays the same, only the size changes and later on you get 2 per row, that I can do with col-lg-4 col-md-6 etc...
I would also prefer if I could do this with img tag as I think it is easier to fade one image to another on hover.
this is my HTML
<div class="item " data-categoryid="2">
<div class="item-image">
<div class="img-bg" style="background: url("http://laravel.dev/images/bon2.jpg"); display: none;"></div>
<div class="img-bg" style="background: url("http://laravel.dev/images/bon.jpg");"></div>
</div>
<div class="item-name">Some name</div>
<div class="item-price">price €</div>
<div class="item-button">
Button.
</div>
</div>
As you said, using bootstrap's .col classes is the way to go here:
Here's a resizable jsfiddle: https://jsfiddle.net/aL1ndzgg/1/
Images, by default, will keep their aspect ratio, unless you specify both the width and the height.
For the hover effect you can have only one of the images for each box set as as position: absolute;; that way, the other image will set the size of the box.
.single-image-container {
margin-bottom: 20px;
position: relative;
}
.single-image-container img {
width: 100%;
}
.blocker {
position: relative;
overflow: hidden;
}
.hover-image {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 125ms ease-in-out;
}
.single-image-container:hover .hover-image {
opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
</div>
</div>
To make your images responsive add the following CSS:
.item img {
max-width: 100%;
width: 100%;
height: auto;
}
So as long as the image source is square the image will resize to its bootstrap grid
You can also try the following: CSS Tricks: Responsive Images
I am building a website in Twitter bootstrap. Using the grid system, I have 2 rows of 4 images which I have given the classes col-xs-12,col-sm-6 and col-md-3 respectively. In order to have a gap between the top row and bottom row I have given the top row an id and styled it in css as img-responsive {margin-bottom: 30px}. This is fine in desktop view, but on smaller devices it creates additional space once the images stack upon each other. Is there a way that this additional margin can be prevented using the media query function? Many thanks in advance, Jon.
Here is the link to my website
<div class="row" id="toprow">
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/ id="image3">
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/ id="image4">
</div>
</div>
<div class="row" id="bottomrow">
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/ id="image7">
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<img src="images/about1_700x700.jpg" class="img-responsive" height="700" width="auto" alt=""/ id="image8">
</div>
</div>
Mobile First
While the other answers are perfectly fine, Bootstrap is a mobile-first framework. This probably shouldn't be it's own answer but I feel it needs a mention.
Adding to #Majid's code...
#toprow {
margin-bottom: 30px;
}
#media screen and (max-width: 768px) {
#toprow {
margin-bottom:0;
}
}
Doing this is fine. The margin will be set to 30px regardless of screen size and then removed for mobile screens. The mobile-first approach would be more like this...
#media screen and (min-width: 769px) {
#toprow {
margin-bottom: 30px;
}
}
Notice how we're targeting min-width and we don't have to set the margin twice? We're adding it as we need it instead of overriding an existing rule. In a lot of situations this can save you from redundant code and make your projects a bit easier to maintain.
ey, try somthing like this:
#media (max-width: 768px) {
.col-xs-12{
margin: 0;
padding: 0;
}
}
adjust if necessary :)
I wanted to create a layout with one image on the left taking up 6 columns and 2 'rows' and 4 squares on the right taking up the other half, i.e/ each one taking up 3 columns, 2 on top and 2 below.
This all works fine, except that 1 image gets pushed down. When the screen is made smaller, it pops back up, and then drops back down again at other smaller sizes.
Here it is on bootply
and here is my code:
<div class="container">
<div class="container-fluid">
<div class="row-fluid">
<div class="box1 col-md-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/Sheep-002-Wm.jpg">
</div>
<div class="box1 col-md-3 col-sm-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/roseveal.jpg">
</div>
<div class="box1 col-md-3 col-sm-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/roseveal5.jpg">
</div>
<div class="box1 col-md-3 col-sm-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/Sheep-002-Wm.jpg">
</div>
<div class="box1 col-md-3 col-sm-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/tentego_wagen.jpg">
</div>
</div>
</div>
</div>
My CSS is:
.box1 img {
width:100%;
}
.container {
width:100%;
padding:0px;
max-width: 1265px;
overflow: auto;
}
.row {
margin-left: 0px;
margin-right: 0px;
}
.col-md-3, .col-md-6, .col-sm-6 {
padding-left: 0px;
padding-right: 0px;
}
Please excuse the images - I'm meant to be designing a sort of farming website!
Any help or insight would be so much appreciated.
I have determined that it has to do with your images not being consistent.
Basically, your images are all different sizes, and you make no effort to enforce a standard upon them. You do put them in bootstrap columns, which is keeping them the proper widths, but the heights are still messing up and differing just slightly, which sometimes kicks your last image down to the next row.
I changed this css by adding a height:auto, which helped.
.box1 img{
width:100%;
height: auto;
}
I then tried making all four images on the right the same image, and the problem went away completely. I forked your bootply over here if you want to see the whole thing.
I have to say, It's looking pretty neat, you should be proud of yourself. It flows really well other than this hiccup. You might consider setting the max-height, or setting height to auto if you make sure that your pictures are all identical aspect ratios. They are already close to the same aspect ratio, but it's giving you these subtle difference that were difficult to detect visually, but are screwing up your layout.
Rufus, Try doing it like this.
Here is the full size Fiddle.
Using 3 sets of rows looks to help what you are looking to to here.
The extra classes also help keep the layout that you are looking for too.
<div class="container-fluid col-lg-12">
<div class="row-fluid col-sm-6 col-md-6 col-lg-6">
<div class="box1 col-sm-12 col-md-12 col-lg-12">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/Sheep-002-Wm.jpg">
</div>
</div>
<div class="row-fluid col-sm-6 col-md-6 col-lg-6">
<div class="box2 col-xs-6 col-sm-6 col-md-6 col-lg-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/roseveal.jpg">
</div>
<div class="box2 col-xs-6 col-sm-6 col-md-6 col-lg-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/roseveal5.jpg">
</div>
</div>
<div class="row-fluid col-sm-6 col-md-6 col-lg-6">
<div class="box2 col-xs-6 col-sm-6 col-md-6 col-lg-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/Sheep-002-Wm.jpg">
</div>
<div class="box2 col-xs-6 col-sm-6 col-md-6 col-lg-6">
<img src="http://www2.buit.ie/wp-content/uploads/2015/06/tentego_wagen.jpg">
</div>
</div>
</div>
I want to align different size images to the bottom of a div but the images are also in their own divs so the other answers don't work.
I have the following HTML:
<div class="row footer-links">
<section>
<div class="col-md-4">
<p>
Proudly presented and sponsored by
</p>
</div>
<div class="col-md-8 col-xs-12 logo-links">
<div class="row logo-bottom">
<div class="col-md-2 col-xs-12 logo-border col-md-offset-1">
<img id="rasv" class="center-block" src="img/rasv.png" alt="RASV logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/victoria-farmers.png" alt="Victoria Farmers logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/anz.png" alt="ANZ logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/pwc.png" alt="PWC logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/vac.png" alt="VAC logo">
</div>
</div>
</div>
</section>
</div>
I used the following CSS:
.logo-border {
border-right: 1px solid #d1d3d4;
height: 54px;
vertical-align: bottom;
display: table-cell;
}
Here is a Code Pen for more information.
You were really close.
The reason it wasn't working was because the columns are floated. Due to this, the elements weren't behaving like a table-cell, therefore rendering vertical-align: bottom useless.
You could simply add float: none and it will work as desired.
Updated Example
.logo-bottom .logo-border {
border-right: 1px solid #d1d3d4;
height: 54px;
vertical-align: bottom;
display: table-cell;
float: none;
}
As a side note, I increased the specificity of the selector .logo-border to .logo-bottom .logo-border so that float: left was overridden.
I have a section that includes three images. It looks perfectly fine on every display except mobile, where the images float right. They seem to align with a starting point at the center. Every other section on my site aligns perfectly as the boostrap rows tell them to.
<section id="press" class="parralax-window img-responsive" data- parallax="scroll" data-image-src="img/dawn.jpg">
<div class="row text-center">
<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
<h2><strong>Omtale</strong></h2>
</div>
<div class="companies">
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-12">
<img src="http://i.imgur.com/0ETpuAx.png" class="img-responsive" alt="Iphoneguide - SvampeGuide">
</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-12">
<img src="http://i.imgur.com/8W49tLt.png" class="img-responsive" alt="Politiken - SvampeGuide">
</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-12">
<img src="http://i.imgur.com/pax4KwJ.png" class="img-responsive" alt="Spisesvampe - SvampeGuide">
</div>
</div>
</div>
</section>
I'm using a parralax plugin but I tried it without it and it doesn't seem to be causing anything.
My css:
#press {
color: white;
padding: 8em;
}
#press h2 {
padding-bottom: 5%;
font-size: 5vmax;
}
#press img {
min-height: 30px;
min-width: 150px;
display: inline !important;
}
I also tried removing the img-responsive class but that didn't help.
Do you any idea what's causing this?
http://jsfiddle.net/wyLqa8w5/1/
#press {
padding: 15%;
}
I think you should look into bootstrap a bit more.
For example,
<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
can be shortened to just
<div class="col-xs-12">
Also, remember to self-close your image tags:
<img src="" />
<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
<h2><strong>Omtale</strong></h2>
</div>
Hej,
I am pretty sure above code is incorrect and you should wrap the div for the col-md-12 around all 3 cols containing the img's - try it. Furthermore can you supply me with the .img-responsive class?
I'd like to see it.