This question already has answers here:
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
Currently my grid image were aligned like this
But my goal is to make the grid image like this, notice the "img 1" were aligned on the center. How to achieve this?
HTML
<div class="container">
<div class="row imagetiles">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
<img src=https://i.imgur.com/nXSiWbw.jpg class="img-responsive">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
<img src=https://i.imgur.com/0dXOdvZ.jpg class="img-responsive">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
<img src=https://i.imgur.com/nXSiWbw.jpg class="img-responsive">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
<img src=https://i.imgur.com/0dXOdvZ.jpg class="img-responsive">
</div>
</div>
</div>
CSS
div.imagetiles div.col-lg-3.col-md-3.col-sm-3.col-xs-6{
padding: 0px;
}
jsfiddle can be view here
Here is the Bootstrap 4 way to do so.
You can just add d-flex align-items-center class to the row:
<div class="container">
<div class="row imagetiles d-flex align-items-center">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 p-0">
<img src=https://i.imgur.com/nXSiWbw.jpg class="img-fluid">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 p-0">
<img src=https://i.imgur.com/0dXOdvZ.jpg class="img-fluid">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 p-0">
<img src=https://i.imgur.com/nXSiWbw.jpg class="img-fluid">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 p-0">
<img src=https://i.imgur.com/0dXOdvZ.jpg class="img-fluid">
</div>
</div>
</div>
Also, you used an incorrect version of Bootstrap 4 in your initial JSFiddle. Updated to the latest version at this moment. Also, the jQuery version used is also incorrect (you should notice an error in Developer Console).
To set a particular DIV to have zero padding, you can use Bootstrap layout help class p-0; you don't need to set it specifically in CSS.
Last, img-responsive is for Bootstrap 3, img-fluid is for Bootstrap 4. Don't mix them up.
JSFiddle: https://jsfiddle.net/shivanraptor/bq8covg5/7/
Change your CSS to:
div.imagetiles div.col-lg-3.col-md-3.col-sm-3.col-xs-6{
padding: 0px;
align-self: center;
}
div.imagetiles{
display: flex;
}
here's the jsfiddle
Simply add this to your CSS:
.imagetiles {
align-items: center;
display: flex;
}
jsfiddle here: https://jsfiddle.net/7snfxL4d/
You can use different approaches but the flex one is really easy like this :
.imagetiles{
display: inline-flex;
align-items: baseline;
}
Try to add class my-auto to your img tag
If 1st dont work try to make the whole row a flex-wrap with classes d-flex align-content-center flex-wrap
You can find more here.
Related
This question already has answers here:
Bootstrap columns not working on mobile
(3 answers)
Bootstrap 4 column order not working on mobile [duplicate]
(1 answer)
`col-xs-*` not working in Bootstrap 4
(6 answers)
Bootstrap Column Not Showing on Mobile
(4 answers)
Closed 12 months ago.
I'm trying to quite simply turn a single row of 4 images (sizes are accurate in the snippet) into two columns on tablet and mobile. The issue is that it breaks into a single column with all 4 stacked.
Basically, anything smaller than desktop I want these to be two columns, so the images would scale down to accomodate the 2 column structure.
What am I doing wrong?
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="team-icons row">
<div class="col-lg-3 col-sm-6 col-xs-6">
<img src="https://via.placeholder.com/300x70">
</div>
<div class="col-lg-3 col-sm-6 col-xs-6">
<img src="https://via.placeholder.com/300x70">
</div>
<div class="col-lg-3 col-sm-6 col-xs-6">
<img src="https://via.placeholder.com/300x70">
</div>
<div class="col-lg-3 col-sm-6 col-xs-6">
<img src="https://via.placeholder.com/300x70">
</div>
</div>
UPDATE:
Tablet seems to work for 2 columns but mobile shows this:
Updated the code to be col-6 (no size modifier needed), and added img-fluid class on the images so they scale with the container.
The snippet works as expected - two columns up until 992px window width.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="team-icons row">
<div class="col-lg-3 col-6">
<img src="https://via.placeholder.com/300x70" class="img-fluid">
</div>
<div class="col-lg-3 col-6">
<img src="https://via.placeholder.com/300x70" class="img-fluid">
</div>
<div class="col-lg-3 col-6">
<img src="https://via.placeholder.com/300x70" class="img-fluid">
</div>
<div class="col-lg-3 col-6">
<img src="https://via.placeholder.com/300x70" class="img-fluid">
</div>
</div>
Using Bootstrap's Grid System, you can use col-6 to start at 50% of the screen width on mobile and then col-lg-3 to bump up to 25% on desktop. I have also added the img-fluid class to your tag to make sure the images automatically adjust to your screen.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="team-icons row">
<div class="col-6 col-lg-3">
<img class="img-fluid" src="https://via.placeholder.com/300x70">
</div>
<div class="col-6 col-lg-3">
<img class="img-fluid" src="https://via.placeholder.com/300x70">
</div>
<div class="col-6 col-lg-3">
<img class="img-fluid" src="https://via.placeholder.com/300x70">
</div>
<div class="col-6 col-lg-3">
<img class="img-fluid" src="https://via.placeholder.com/300x70">
</div>
</div>
This question already has answers here:
Equal height rows in a flex container
(13 answers)
Closed 6 years ago.
Please read my question before marking duplicate
I have bootstrap container in which i have few columns. I want to fix same height for all div.
What i got is this, however it will break the structure while resizing means not use full with responsiveness.
I know there are 2 main solution for them :
1. Flex
2. Table/table-cell
But both are not useful for me. I have also used overflow:hidden and margin-bottom: -99999px;padding-bottom: 99999px; solution but not useful for me.
Solution i have tried : This, this, and this but none of them is useful for me.
I have simply created fiddle(by some answer) but when i try to use the same way in my fiddle then its not giving the same output, don't know why.
I have read this tutorial and went through this too to know more about flex but none of them is useful for me.
So my final fiddle is this. Please check this one and let me know how can i make it responsive while keeping same height.
css
.bg-gray {
color: #666;
background: #efefef;
}
.mrg10T {
margin-top: 10px !important;
}
.mrg10A {
margin: 10px !important;
}
.csT
{
display: flex;
flex-wrap: wrap;
justify-content: center;
text-align: center;
}
.csT div div{height:100%;}
Html
<div class="row mrg10T csT">
<div class="text-left col-md-4 thisclass">
<div class="row bg-gray pad5A mrg10A">
<div class="col-md-6 col-sm-6 col-xs-6 font-bold">Current subscription</div><div class="col-md-6 col-sm-6 col-xs-6">: Student Demo</div>
</div>
</div>
<div class="text-left col-md-4 thisclass">
<div class="row bg-gray pad5A mrg10A">
<div class="col-md-6 col-sm-6 col-xs-6 font-bold">Start date</div><div class="col-md-6 col-sm-6 col-xs-6">: 1st-Jan-2016</div>
</div>
</div>
<div class="text-left col-md-4 thisclass">
<div class="row bg-gray pad5A mrg10A">
<div class="col-md-6 col-sm-6 col-xs-6 font-bold">Expiry date</div><div class="col-md-6 col-sm-6 col-xs-6">: 31st-Dec-2016</div>
</div>
</div>
<div style="clear:both;">
</div>
</div>
<div class="row mrg10T csT">
<div class="text-left col-md-4 thisclass">
<div class="row bg-gray pad5A mrg10A">
<div class="col-md-6 col-sm-6 col-xs-6 font-bold">Renewal pricing</div><div class="col-md-6 col-sm-6 col-xs-6">: $100</div>
</div>
</div>
<div class="text-left col-md-4 thisclass">
<div class="row bg-gray pad5A mrg10A">
<div class="col-md-6 col-sm-6 col-xs-6 font-bold">Offers 1</div><div class="col-md-6 col-sm-6 col-xs-6">: 20% cash incentive (will be credited to your account)</div>
</div>
</div>
<div class="text-left col-md-4 thisclass">
<div class="row bg-gray pad5A mrg10A">
<div class="col-md-6 col-sm-6 col-xs-6 font-bold">Renewal pricing</div><div class="col-md-6 col-sm-6 col-xs-6">: $100</div>
</div>
</div>
<div style="clear:both;">
</div>
</div>
Does this work for you..
.csT
{
display: inline;
flex-wrap: wrap;
justify-content: center;
text-align: center;
}
.csT div div{height:100%;}
.thisclass{height:100px;}
DEMO https://jsfiddle.net/norcaljohnny/jeaxycv8/2/
Consider this case
<div class="row">
<div class="col-md-3 col-sm-3 col-xs-3"></div>
<div class="col-md-6 col-sm-6 col-xs-6"></div>
<div class="col-md-3 col-sm-3 col-xs-3"></div>
</div>
In this case, suppose if I need to fill the first div (first column) within the parent div with a background of #FF0000 how can I do it? If I can do it in a regular way, that is by specifying the style="background-color:red", the background changes only for the content written within it. Not if I create another div inside it and set its height and width to 100% nothing happens. Why is it so? And how can I do it the correct way?
Use a
<div class="col-md-3 col-sm-3 col-xs-3"> </div>
And set the background color as you wish.
Simple and elegant.
Empty div has no height. Use height, min-height, padding-top or padding-bottom to make empty div visible. You may do it
by class for column
by class for row with :first-child
Bootstrap uses col-xs- for screens of any width if there are no other conditions. Therefore col-md-3 col-sm-3 col-xs-3 is equivalent to col-xs-3.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
.make-first-div-red > div:first-child,
.make-it-red {
background-color: #f00;
min-height: 30px;
margin-bottom: 10px;
)
<div class="row make-first-div-red">
<div class="col-xs-3"></div>
<div class="col-xs-6"></div>
<div class="col-xs-3"></div>
</div>
<div class="row">
<div class="col-xs-3 make-it-red"></div>
<div class="col-xs-6"></div>
<div class="col-xs-3"></div>
</div>
<div class="row">
<div class="bg col-md-3 col-sm-3 col-xs-3">adadadadada</div>
<div class="col-md-6 col-sm-6 col-xs-6"></div>
<div class="col-md-3 col-sm-3 col-xs-3"></div>
</div>
and use this css
.bg{background:#FF0000}
and it will work
Yes folks, it's another vertical-alignment question! I'm trying to do something pretty simple with Bootstrap 3, but hitting a wall on it. I'm building on the answer to this related question, but hitting the problem described below.
Here's the markup:
<div class="container">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://www.vectortemplates.com/raster/batman-logo-big.gif">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://www.vectortemplates.com/raster/superman-logo-012.png">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://2.bp.blogspot.com/-91OnmwoX5t0/T8reMB25ReI/AAAAAAAACQQ/D_jlmi6vWTw/s1600/GREEN+LANTERN+LOGO.png">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://ecx.images-amazon.com/images/I/41biZJowGyL._SY300_.jpg">
</div>
</div>
</div>
And the CSS:
.vcenter {
display: inline-block;
vertical-align: middle;
float: none;
}
img {
max-width:200px;
}
When "float:none;" is included on .vcenter, the images are vertically-aligned as desired. However, the fourth column wraps underneath the other three.
When "float:none;" is commented out, the 4-column layout is achieved, but the images aren't vertically-aligned.
Bootply example so you can see what I mean.
Any idea how to get a four-column layout and vertically-aligned images?
The issue is that display:inline-block takes the white space into account. If you stack the column divs right next to each with no new paragraph spaces it will line up correctly. So it would end up like this:
<div class="container">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://www.vectortemplates.com/raster/batman-logo-big.gif">
</div><div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://www.vectortemplates.com/raster/superman-logo-012.png">
</div><div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://2.bp.blogspot.com/-91OnmwoX5t0/T8reMB25ReI/AAAAAAAACQQ/D_jlmi6vWTw/s1600/GREEN+LANTERN+LOGO.png">
</div><div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 vcenter">
<img src="http://ecx.images-amazon.com/images/I/41biZJowGyL._SY300_.jpg">
</div>
</div>
</div>
For more info see:
Stackoverflow: css - two inline-block, width 50% elements don't stack
CSS-Tricks: Fighting the Space Between Inline Block Elements
The float on columns in Bootstrap 3 helps to account for the few pixels too large they are. To fix this you just need to play around with the margin a little:
.vcenter .col-xs-3, .vcenter .col-sm-3, .vcenter .col-md-3, .vcenter .col-lg-3 {
margin: 0px -2px;
}
Hope this helps!
I am using Bootstrap and trying to achieve the following with thumbnails.
I the div #demo reaches its max height then make anything after this height overflow horizontally and enable a scrollbar horizontally. I tried overflow-x:auto and other tricks but the div overflows vertically. Any ideas on how to do this?
<div class="row">
<a class="col-md-6 col-xs-12" href="http://i1.ytimg.com/vi/Tm0FAcMQdzg/mqdefault.jpg">
<div class="thumbnail">
<img src="http://i1.ytimg.com/vi/Tm0FAcMQdzg/mqdefault.jpg" alt="...">
</div>
</a>
<div id="demo" style="overflow-y: auto; max-height: 430px;">
<a class="col-md-4 col-xs-4" href="http://i1.ytimg.com/vi/Tm0FAcMQdzg/mqdefault.jpg">
<div class="thumbnail">
<img src="http://i1.ytimg.com/vi/Tm0FAcMQdzg/mqdefault.jpg" alt="...">
</div>
</a>
.....
</div>
</div>
Have a look here: Create horizontally scrolling List Item view using Bootstrap Columns
And also look this sample: http://jsfiddle.net/V5zWT/10/
<div class="DocumentList">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 DocumentItem">aaa</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 DocumentItem">aaa</div>
</div>
</div>