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 :)
Related
How can i set div with photos on all available space (now in div .row have big margins) and set one height for all photos in all rows (i have vertical and horizontal photos) and keep responsiveness? Margins in row are the same all the time. Ofc the middle photo will be wider to keep the proportions.
HTML:
<main>
<div class="container">
<div class="row justify-content-sm-center">
<div class="col-lg-4 col-md-6 col-sm-12">
<figure class="description">
<img src="img/projects/home/1.jpg" class="img-fluid img home-photos">
</figure>
</div>
<div class="col-lg-4 col-md-6 col-sm-12">
<figure class="description">
<img src="img/projects/home/2.jpg" class="img-fluid img home-photos">
</figure>
</div>
<div class="col-lg-4 col-md-6 col-sm-12">
<figure class="description">
<img src="img/projects/home/3.jpg" class="img-fluid img home-photos">
</figure>
</div>
</div>
</div>
If I'm understanding the question properly this CSS should work.
.row {
display: flex;
justify-content: space-around;
}
.img {
height: 100vh;
width: 45vh; //play with this to get the effect you desire. You may need to target the middle picture individually.
}
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
I want to put these two images next to each other but also if the screen gets too small want them to stack on top of each other. So this is what I have in Razor:
<div class="row">
<div class="col-sm-12">
#if (Model.ThumbnailUrl != null)
{
<span><img class="thumbnail" src="#Model.ThumbnailUrl" /></span>
}
#if (Model.SignatureUrl != null)
{
<span><img class="thumbnail" src="#Model.SignatureUrl" /></span>
}
</div>
</div>
And this is what was generated:
<div class="row">
<div class="col-sm-12">
<span style="display: inline"><img class="thumbnail" src="something.jpg;width=200&height=200"></span>
<span style="display: inline"><img class="thumbnail" src="whatever.jpg;width=200&height=200"></span>
</div>
</div>
And this is how it looks:
They are stacking too early. Screen was full size. Maybe just in Small or Extra Small I want them to stack, otherwise I want them side by side.
How should I fix this?
Here is a solution:
1/ Make 2 columns with Bootstrap responsive classes for different screen sizes.
2/ Use img-responsive class on images to adapt the img size to the content when resizing.
.row.row-no-margin {
margin-left: 0px;
margin-right: 0px;
}
.col-no-padding {
padding-left: 0 !important;
padding-right: 0 !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row row-no-margin">
<div class="col-xs-12 col-sm-6 col-no-padding">
<img class="thumbnail img-responsive" src="http://placehold.it/600x400">
</div>
<div class="col-xs-12 col-sm-6 col-no-padding">
<img class="thumbnail img-responsive" src="http://placehold.it/600x400">
</div>
</div>
Try something like this:
<div class="row">
<div class="col-sm-6">
#if (Model.ThumbnailUrl != null)
{
<span><img class="thumbnail" src="#Model.ThumbnailUrl" /></span>
}
</div>
<div class="col-sm-6">
#if (Model.SignatureUrl != null)
{
<span><img class="thumbnail" src="#Model.SignatureUrl" /></span>
}
</div>
</div>
Basically, you need to use Bootstrap's columns to arrange your images. Right now you are creating a column of size 12, the entire width of the row, for each image.
For more information:
https://getbootstrap.com/examples/grid/
I'm using a template with Bootstrap.
The following code:
<div class="row mix-grid thumbnails wrapper white" id="pictures_placeholder">
<div class="col-md-3 col-sm-4 mix ">
<div class="mix-inner">
<img class="img-responsive" src="../../../assets/admin/pages/media/works/img1.jpg"
alt="">
<div class="mix-details picture-bottom-label">
<div class="row">
<div class="col-md-12 col-xs-12">
<div class="col-md-4 col-xs-3">
<img src="../../../assets/admin/pages/media/profile/profile_user.jpg"
class="img-responsive img-circle profile-pic"
alt=""
/>
</div>
<div class="col-md-8 col-xs-8 text-left user-name">Asaf Nevo</div>
</div>
</div>
</div>
</div>
</div>
</div>
does this:
How can I make the name (Asaf Nevo) to be entered to the image ?
try adding this to CSS:
div.user-name{height:92px;line-height:92px;}
hope that helps.
Put the name in the same div as the image. Make both inline.
<img src="../../../assets/admin/pages/media/profile/profile_user.jpg"
class="img-responsive img-circle profile-pic" alt="" />Asav Nevo
Now play with the CSS property vertical-align. Something like vertical-align: middle could work and yes, this property should be applied to the surrounding div if not mistaken, potentially also to the inline content itself. I cannot try it right now.
Add this to the css:
.user-name {
margin-top:50%;
}
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.