Reputation: 21
Having some CSS related problem for layout issues.
firstly see this screenshot:
Here i have used css like this:
.image{float:right; padding-top:10px; padding-left:10px; padding-bottom:10px;}
.description{font-size:15px; font-style:italic; padding:10px; color:#5C5C5C; text-shadow:0px 0px 1px #A1A1A1;}
.image, .description{display:block;}
.main-article{clear:both;}
but what i want to do is to display description in the middle. Like this:
can you tell me the CSS, to position description class
div
in the middle like the second image. Thanks
Upvotes: 2
Views: 808
Reputation: 5737
Like GCyrillus said:
display: inline-block;
vertical-align: middle;
will work. However, you aren't defining a width. So what you will do is:
.image{ width: 300px; padding-top:10px; padding-left:10px; padding-bottom:10px; }
.description{ width: 600px; font-size: 15px; font-style: italic; padding: 10px; color: #5C5C5C; text-shadow: 0px 0px 1px #A1A1A1; }
.image, .description{ display: inline-block; vertical-align: middle; }
Once you change those widths to whatever you need, it will work just fine for you. For good measure, make sure you don't fall victim to the inline-block whitespace bug so either apply:
.image { margin-left: -4px; } //It works sometimes for me but I think it isn't cross-browser very well.
or don't allow any whitespace between your elements in the HTML like so:
<div class="description">
Lorem Ipsum
</div><div class="image">
<img />
</div>
Also, if you want to support IE7:
.image, .description { display: inline-block; vertical-align: middle; *display: inline; zoom: 1; } //Some people don't like the hacks and some people don't like supporting old IE ;-)
Upvotes: 0
Reputation: 8597
You can set the height of the container around the two items and then set the description to
top: 50%
Here's a fiddle of it
http://jsfiddle.net/andrewliu/mS4pB/1/
UPDATE:
I have modified a bit, you can do some kind of hack where you need do have containers and using margin-top: 50%;
and then another container having margin-top: -25%;
Upvotes: 0
Reputation: 1499
WARNING! This box model is under revision.
I'd use Flexible Box Model or Flexbox.
Just you must put the follow classes in the parent element:
p-flexbox and flex-hcc
Where:
And inside the style you have to put these CSS rules:
.p-flexbox {
display: -webkit-box;
display: -moz-box;
display: box;
}
And another these CSS rules
.flex-hcc {
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
-webkit-box-align: center;
-moz-box-align: center;
box-align: center;
}
Here is a example: http://jsfiddle.net/GnbZD/1/
Cheers, Leonardo
Upvotes: 1
Reputation: 427
Add a wrapper around the description and image and use display: table
#container {
display: table;
}
#container .image, #container .description {
display: table-cell;
vertical-align: middle;
}
Upvotes: 2
Reputation: 106008
Basicly it will be :
.description, .image {
display:inline-block;
vertical-align:middle;
}
Upvotes: 2