This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to make an image center (vertically & horizontally) inside a bigger div
HTML code:
<div class="promo_tumbs col_12">
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
</div>
CSS part:
.promo_tumbs {
height: 155px;
background: #058;
}
.promo_tumb {
height: 75px;
width: 125px;
background: #990000;
float: left;
margin: 0 10px;
text-align: center;
}
How can I vertically center .promo_tumb?
Read this article on vertical centering.
http://www.jakpsatweb.cz/css/css-vertical-center-solution.html
If you dont wanna support IE7 or lesser then you can use vertical-align : middle.
Otherwise:
Set display to table in .promo_tumbs col_12
Set vertical-align to middle & display to table-cell for
.promo_tumb
and it should work.
Will the heights (155px and 75px respectively) always be fixed? In that case it'd be as simple as changing the .promo_tumb margin:
margin: 40px 10px
use the vertical-align: middle; in the css/style for promo_thumbs.
css part insert in head section..........
<style type="text/css">
.promo_tumbs {height: 155px; background: #058; }
.promo_tumb {height: 75px; width: 125px; background: #990000; float: left;
margin: 40px 50px;
text-align: center; }
</style>
body part coding......
<div class="promo_tumbs col_12">
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
<div class="promo_tumb"></div>
</div>
.promo_tumbs {height: 155px; background: #058;
vertical-align: middle;
display:table-cell;
}
Related
This question already has answers here:
How to Create Grid/Tile View? [duplicate]
(8 answers)
Closed 5 years ago.
I am creating a responsive dashboard with a fixed header and sidebar nav. I am trying to create the template depicted below but am having issues with div stacking:
Instead, I can only get them to stack like in this image here:
I have a wrapper around the divs that has the following styles:
width: 100%;
padding: 15px;
The divs themselves are wrapped in a container with the following styles:
display: inline-block;
width: 50%;
padding: 15px;
float: left;
vertical-align: top;
Apparently, vertical-align: top is supposed to solve this issue but I haven't been able to get the yellow div to the right position.
Any ideas?
.wrapper{
width: 100%;
padding: 15px;
height:100%;
}
.floating_div{
margin:10px;
float:left;
width: 45%;
height:300px;
display:inline-block;
vertical-align:top;
}
.m-t{
margin-top:15px;
}
.blue_bg{
background:blue;
}
.green_bg{
background:green;
}
.yellow_bg{
background:yellow;
}
.floating_div .inner_div{
height:150px;
}
<div class="wrapper">
<div class="floating_div">
<div class="inner_div blue_bg">Inner Div 1</div>
<div class="inner_div yellow_bg m-t"> Inner DIv 2</div>
</div>
<div class="floating_div green_bg ">
Left Div 2
</div>
</div>
Is this the same that you are looking for?
Here is JSFiddle
Hope this helps.
This should do it for you:
https://jsfiddle.net/hncuyy6o/1/
`<div class="wrapper">
<div class="hai">
<div class="one"></div>
<div class="three"></div>
</div>
<div class="two"></div>
</div>`
CSS:
.wrapper{
width: 100%;
padding: 15px;
}
.hai{
display: inline-block;
}
.one{
vertical-align: top;
width: 200px;
height: 300px;
background-color: blue;
display: inline-block;
}
.two{
vertical-align: top;
width: 200px;
height: 400px;
background-color: red;
display: inline-block;
}
.three{
width: 200px;
height: 300px;
background-color: yellow;
display: block;
position: absolute;
}
Hope that helps.
You can Javascript Masonry Grid Layout to achieve that.
Masonry is a JavaScript grid layout library. It works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall. You’ve probably seen it in use all over the Internet.
Using Masonry Library, its simple as this.
<div class="grid">
<div class="grid-item">...</div>
<div class="grid-item">...</div>
<div class="grid-item">...</div>
</div>
Jquery:
$('.grid').masonry({
// options
itemSelector: '.grid-item',
columnWidth: 200
});
Simplest way to achieve that is wrapping yellow and blue box with another div.
It works unless You have media queries changing layout much. Another thing is to use flexbox with colums.
This question already has answers here:
How to vertical align an inline-block in a line of text?
(2 answers)
Closed 6 years ago.
I have text and image content/divs that are aligned. But I want them to be centred vertically with each other as well.
html
<div class="cell"><a href="...'</a></div>
<div class="separate"></div>
<div class="cell"><a href="...'</a></div>
<div class="separate"></div>
<div class="cell"><a href="...'</a></div>
css
.cell, .separate {
display: inline-block;
margin: 0 5px;
}
.separate {
width: 2px; height: 25px;
background-color: red;
}
To this rule, add vertical-align: middle;:
.cell, .separate {
display: inline-block;
margin: 0 5px;
vertical-align: middle;
}
One way to vertically align content is using line height. This method only works for one line of text though:
HTML
<div id="parent">
<div id="child">Text here</div>
</div>
CSS
#child {
line-height: 200px;
}
This can be extended for images too:
HTML
<div id="parent">
<img src="image.png" alt="" />
</div>
CSS
#parent {
line-height: 200px;
}
#parent img {
vertical-align: middle;
}
You can read about other methods to vertically center content here: http://vanseodesign.com/css/vertical-centering/
You can vertically align inline content with vertical-align
.cell, .separate {
display: inline-block;
margin: 0 5px;
vertical-align: middle;
}
.separate {
width: 2px; height: 25px;
background-color: red;
}
<div class="cell">asdf</div>
<div class="separate"></div>
<div class="cell">asdf</div>
<div class="separate"></div>
<div class="cell">asdf</div>
All right so I have a bit of an odd request to try and fulfill. I have a page that has a listing of divs, inside of which are an image and a link. Each row has 3 divs max. Sometimes, though, the last row may have just 1 or 2 divs. What I need to try and do is set things up so that if the last row only has 1 or 2 divs, then those divs need to be centered horizontally within their row.
Is this something that is possible? Would I need to use JavaScript/jQuery to count the number of divs in the final row? Or could I do this all with just CSS?
Here is how the divs are setup right now:
<div class="About-Categories clearfix">
<div class="About-Category clearfix">
<img src="[image url]" class="image">
[link text]
</div>
<!--Additional About-Category divs go here as needed-->
</div>
There could be any number of About-Category divs, but the css is setup to ensure that there are only 3 About-Category divs within the width of the page (until a screen size of 460px is reached).
CSS as it is now:
.About-Categories{
text-align: center;
}
.About-Category{
float: left;
height: auto;
margin-left: 0%;
margin-top: 0px;
display:inline-block;
padding: 30px;
width: 33%;
&:nth-of-type(1){
clear: both;
}
}
#wrap {
width: 600px;
text-align: center;
}
.tile {
width: 198px;
height: 100px;
border: 1px solid #000;
display: inline-block;
margin: 0;
padding: 0;
}
<div id="wrap">
<div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div>
</div>
If you display the divs as inline-block, they'll respect the text-align attribute. In combination with a wrapper sized to fit three divs, you should get the result you're looking for.
Example:
#wrap {
width: 600px;
text-align: center;
}
.tile {
width: 198px;
height: 100px;
border: 1px solid #000;
display: inline-block;
vertical-align: top;
margin: 0;
padding: 0;
}
<div id="wrap">
<div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div>
</div>
UPDATE: The answers have got me close, but they still don't align vertically as the text div is larger, how can I make them both the same height and therefore align?
I would like to have two DIVs next to each other, one containing an image and one containing text, both sitting in a container DIV.
The image should be 15% of the width of the container div, with the text using the remaining 85%
The image and text should be aligned vertically within their respective DIVs, so it looks like they are aligned with each other.
I've tried to work this out but can't seem to do it! Can anyone help?
#picture {
float: left;
width: 15%;
line-height: auto;
}
#text {
width: auto;
padding-left: 16%;
line-height: auto;
vertical-align: middle;
margin-top: auto;
margin-bottom: auto;
}
#text p {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
and
<div id="quotes">
<div id="picture">
<img style="width: 100%; vertical-align: middle" src="tom.jpg" >
</div>
<div id="text">
<p>"Christiaan was one of the stand out candidates throughout, therefore there was no hesitation in offering him a place on this highly sort after scheme..."</p>
</div>
</div>
Here's a fiddle with your code in it: http://jsfiddle.net/hQ6Vw/1/
The only changes I made was to assign matching top/bottom margins to the img and p tags. I think that will give you the effect you're looking for.
If you use float and verticl-align, those two won'nt work together.
Float extract itself from regular flow and go slide on one side or the other on top of next line right after any content within the regular flow.
Vertical-align works:
in betweem inline-boxes (inline-block-level element or displayed so with display:inline-block;)
inside td or it's CSS default display : display:table-cell;
here jsfiddle #TXChetG updated
Using display:inline-block; http://jsfiddle.net/GCyrillus/hQ6Vw/2/
Using display:table/* table-cell*/;
http://jsfiddle.net/GCyrillus/hQ6Vw/3/
This should get you close:
<div>
<div style="background: grey; width: 15%; float:left"></div>
<div style="background: blue; width: 85%; float:left"></div>
</div>
Replace the grey background div with your image and the blue with your text.
Check this out
HTML:
<section>
<div id="one"></div>
<div id="two"></div>
</section>
CSS:
section {
width: 80%;
height: 200px;
background: aqua;
margin: auto;
padding: 10px;
}
div#one {
width: 15%;
height: 200px;
background: red;
float: left;
}
div#two {
margin-left: 15%;
height: 200px;
background: black;
}
Is this what you mean?
html
<div class="container">
<div class="images">
<img src="http://jsfiddle.net/img/logo.png" style="background-color:black">
</div>
<div class="text">
Example
</div>
</div>
<div class="container">
<div class="images">
<img src="http://jsfiddle.net/img/logo.png" style="background-color:black">
</div>
<div class="text">
Example
</div>
</div>
css
.container {
clear: both;
}
.images {
width: 15%;
float: left;
vertical-align: text-top;
}
.text {
width: 85%;
float: right;
vertical-align:text-top;
}
Why not just set the #text p display to display: inline or display:block; or use margins to align them?
<div id="quotes">
<div id="picture">
<img src="tom.jpg" />
</div>
<div id="text">
<p>"Christiaan was one of the stand out candidates throughout, therefore there was no hesitation in offering him a place on this highly sort after scheme..."</p>
</div>
</div>
Display the container div as table and the text and image divs as table-cell to make them the same heights. You can then centre the image vertically through vertical-align:middle.
#quotes {
display:table;
}
#picture {
width: 15%;
display:table-cell;
vertical-align: middle;
}
#text {
display:table-cell;
width:85%;
padding-left: 16%;
}
#picture img {
width: 100%;
}
http://jsfiddle.net/X3WsV/1/
i'm attempting to create an header which is divided into 3 divs
they will all be set to display: inline-block
the left header part will contain a slogan and a logo which i wan't the slogan to be at
the right of the logo
the problem is my logo div and my slogan div are always placed one on top of the other .
to my understanding an inline element would be placed next to the last inline element
with in the same block , notice that the header-left div has 250px width and each of the
child div's have 100px width so why are they not placed one next to the other ?
my markup :
<div id="header">
<div id="header-left">
<div id="logo" />
<div id="slogan">
<span> Buy For U</span>
</div>
</div>
</div>
my css :
div#header
{
border: 1px solid black ;
height: 200px;
}
div#header div#header-left
{
display: inline-block;
height: 100%;
width: 250px;
}
div#header div#header-left div#logo
{
display: inline-block;
background: url("Google-Desktop-64.png") no-repeat center;
background-size: 25%;
height: inherit;
width: 100px;
}
div#header div#header-left div#slogan
{
display: inline-block;
height: inherit;
width:100px;
}
everything's fine. just close the logo's <div> properly. "self-closing" tags.
<div id="header">
<div id="header-left">
<div id="logo"></div>
<div id="slogan">
<span> Buy For U</span>
</div>
</div>
</div>
i also suggest using an <img> for the logo (and make it a link to homepage) rather than just a background. empty <div> tags are prone to errors during validation.
It is stange that your #header has a width of 200 pixels and the child #header-left 250 pixels, but apart from that I think it's better to use a float. This means that the two divs are next to each other:
div#header div#header-left div#logo
{
float: left;
background: url("Google-Desktop-64.png") no-repeat center;
background-size: 25%;
height: inherit;
width: 100px;
}
div#header div#header-left div#slogan
{
float: left;
height: inherit;
width:100px;
}
And you nead a clear in your html/css:
.clear_left { clear: left; }
And the html:
<div id="header">
<div id="header-left">
<div id="logo" />
<div id="slogan"><span> Buy For U</span></div>
<div class="clear_left"></div>
</div>
</div>