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/
Related
I want to use css, bootstrap to align the first line align left, and the second line will center on the text length of the first line.
I tried many ways but not.
code follow
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<div class="col-md-2" style="padding:0">
<img src="/Content/images/logo.png" class="img-responsive" alt="">
</div>
<div class="col-md-10 tex-center" style="padding-right:0;">
<div style="padding:0">
<div class="line1-bold">THIS IS THE FIRST LONG HEADLINE</div>
<div class="line2">THIS IS THE SECOND HEADLINE</div>
</div>
</div>
</div>
</a>
</div>
Please check this..
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<div class="col-xs-2" style="padding:0">
<img src="https://www.tenforums.com/attachments/browsers-email/18558d1485951187t-microsoft-edge-logo-microsoft-edge-100582336-large.png" class="img-responsive" style="width:100px" alt="">
</div>
<div class="" style="float:left;">
<div class="line1-bold" style="color:#b63957; font-size:18px;">THIS IS THE FIRST LONG HEADLINE</div>
<div class="line2" style="color:#b63957; font-size:16px; text-align:center;">THIS IS THE SECOND HEADLINE</div>
</div>
</div>
</a>
</div>
Try adding the class text-center to your divs.
Here is a working pen.
Something like this?
I don't know about your task, but I deleted some tags.
CSS
.img-responsive {
width: 100px;
float: left;
}
span {
display: block;
}
HTML
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<img src="https://www.tenforums.com/attachments/browsers-email/18558d1485951187t-microsoft-edge-logo-microsoft-edge-100582336-large.png" class="img-responsive" alt="">
<span class="text-left">THIS IS THE FIRST LONG HEADLINE</span>
<span class="text-center">THIS IS THE SECOND HEADLINE</span>
</div>
</a>
</div>
Reference Link
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 know the proper way to put an image in the center of the page, and then beside the image vertical align 2 lines of text. should I put the image and text in one bootstrap coloumn or should i have the image in one coloumn and the text in a seperate coloumn. I know there are a few ways to do this, i just want to know the proper method.
<div class="row">
<div class="col-xs-9">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" style="vertical-align:middle" />
</div>
<div class="col-xs-3">
<span style="font-size:48px;">Test</span>
<span style="font-size:24px;">Test second line. </span>
</div>
</div>
https://jsfiddle.net/k90s5fec/
This is the right way to do this
div{
display: inline-block;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-8">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" style="vertical-align:middle" />
</div>
<div class="col-xs-4">
<p style="font-size:48px;">Test</p>
<p style="font-size:24px;">Test second line. </p>
</div>
</div>
This is the fiddle
NOTE : Use https:// when importing external resources,
use p tag instead of span if you want to use block texts.
use this
<div class="row">
<div class="col-xs-9">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" class="displa`enter code here`yed" />
</div>
<div class="col-xs-3">
<span style="font-size:48px;">Test</span>
<span style="vertical-align:middle; line-height: 30px;">Test second line. </span>
</div>
</div>
img.displayed
{
display: block;
margin-left: auto;
margin-right: auto
}
<div class="row">
<div class="col-md-8 col-sm-8 col-xs-8">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" style="vertical-align:middle" />
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<div style="font-size:48px;">Test</div>
<div style="font-size:24px;">Test second line. </div>
</div>
</div>
I have a basic thumbnail display using bootstrap. I want to have 3 images in a row and go down to 2 images when making the page smaller. I had this worked out until I added a margin-right to add some space in between thumbnails. Once I did this it pushed that third image down to the next line. I tried playing around with the padding and margin and I just cant get that third thumbnail to stay on the same line. I also tried changing it to col-sm-3 and that did not seem to work either.
HTML:
<div class="work">
<ul>
<li class="thumbnail col-sm-4 col-xs-6"><img src="thumbnails.png"/></li>
<li class="thumbnail col-sm-4 col-xs-6"><img src="thumbnails.png"/></li>
<li class="thumbnail col-sm-4 col-xs-6"><img src="thumbnails.png"/></li>
</ul>
</div>
CSS:
.work {
padding: 0px 40px 0px 0px;
max-width: 100%;
}
.thumbnail {
margin-right: 10px;
}
I'm not 100% if this what you mean, but here it goes:
HTML
<div class="work">
<ul>
<li class="thumbnail col-sm-4 col-xs-6"><img src="thumbnails.png"/></li>
<li class="thumbnail col-sm-4 col-xs-6"><img src="thumbnails.png"/></li>
<li class="thumbnail col-sm-4 col-xs-6"><img src="thumbnails.png"/></li>
</ul>
</div>
CSS
.thumbnail {
border:0;
}
.thumbnail a{
display:block;
padding:10px;
background:red;
}
.thumbnail img{
width:100%;
}
https://jsfiddle.net/ax7wcLo4/2
If you really want to separate the li elements, you should do that without bootstrap's default grid system.
<ul class="list-unstyled list-inline">
Use class .list-inline on th eul element and set the below css for them;
ul {
margin: 0;
padding: 0;
width: 100%
}
li {
width: calc(100% - 10px);
margin: 0 5px;
}
Be Aware: calc has some compatibility issues based on your browser support range.
Can I Use Link for CALC
You should put the thumbnail inside of a column, not combined. If you need this inside a list it can be change to that as well > See Default Bootstrap Example.
See working Snippet at Full Page.
body,
html {
padding-top: 50px;
}
.row.no-list-style {
list-style: none;
margin-left: -55px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<h3>Default</h3>
<div class="row">
<div class="col-sm-4 col-xs-6">
<div class="thumbnail">
<a href="#honey">
<img src="http://placehold.it/350x350/f00" />
</a>
</div>
</div>
<div class="col-sm-4 col-xs-6">
<div class="thumbnail">
<a href="#honey">
<img src="http://placehold.it/350x350/000" />
</a>
</div>
</div>
<div class="col-sm-4 col-xs-6">
<div class="thumbnail">
<a href="#honey">
<img src="http://placehold.it/350x350/f00" />
</a>
</div>
</div>
</div>
</div>
<hr>
<div class="container">
<h3>Inside a List</h3>
<ul class="row no-list-style">
<li class="col-sm-4 col-xs-6">
<div class="thumbnail">
<a href="#honey">
<img src="http://placehold.it/350x350/ff0" />
</a>
</div>
</li>
<li class="col-sm-4 col-xs-6">
<div class="thumbnail">
<a href="#honey">
<img src="http://placehold.it/350x350/000" />
</a>
</div>
</li>
<li class="col-sm-4 col-xs-6">
<div class="thumbnail">
<a href="#honey">
<img src="http://placehold.it/350x350/ff0" />
</a>
</div>
</li>
</ul>
</div>
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 :)