4

I want to to have content like below
1 for this first one I used line-height 40px

enter image description here for the second one I used line-height 120px

This means as content varies I have to change the line-heights Is there any way to make this type of centering in a fixed dimensional div without changing the class

Can I do this without Javascript ? If I use height as 120px I am getting div s like this ( I dont want this ) enter image description here

style of the div is

<style>
 .rectangle {
        postion:absolute;
    box-shadow: 10px #333;
    border-radius: 23px;
    border-top-right-radius: 0;
    border:6px solid;
    block:inline;
    line-height: 123.6px;
    width:200px;
    background-color: #444;
    float: left;
    margin: 5px;
    text-align: center;
    color:white;
   font-weight:900;

    text-decoration:none;
}
</style>
madhu131313
  • 7,003
  • 7
  • 40
  • 53

4 Answers4

2

Vertical centring is tricky. Chris Coyier at CSS tricks has a great article on this - http://css-tricks.com/centering-in-the-unknown/

My personal preference is the ghost pseudo element, but it's only viable in IE8+ so you may need to look at some of the other examples if legacy IE support is necessary.

Here's a working fiddle - http://jsfiddle.net/tommarshall/eGJQC/3/

tommarshall
  • 2,038
  • 5
  • 23
  • 36
1

Make .rectangle element to be displayed as table, and the inner text paragraph to be displayed as a table cell. Then you can easily vertical position your paragraph.

Here is a working example: http://jsfiddle.net/ktzUn/

alexbusu
  • 701
  • 4
  • 13
0

following css works properly even if height and the content in div varies

.rectangle 
      {
        height:auto;
        postion:absolute;
        box-shadow: 10px #333;
        border-radius: 23px;
        border-top-right-radius: 0;
        border:6px solid;
        block:inline;
        width:200px;
        background-color: #444;
        float: left; padding:20px 10px 20px 10px;
        margin: 5px;
        text-align: center;
        color:white;
        font-weight:900;
        text-decoration:none;
    }
vivek salve
  • 991
  • 1
  • 9
  • 20
  • block:inline is for changing the block element to inline element http://www.w3schools.com/cssref/pr_class_display.asp – madhu131313 Sep 06 '12 at 12:26
  • block:inline; ? There is no such property. Maybe display: block;, display: inline-block; – Jawad Sep 07 '12 at 15:24
0

Vertical alignment works perfectly only in table>tr>td. for others you can also try giving padding from top and bottom. that doesn't need any vertical alignment and would work simply best.

Thanks Rahul

Rahul
  • 928
  • 5
  • 8