1

I'm using third party libraries like Kendo which output various types of HTML elements when they render.

So you might end up with a scenario such as this:

<ul>
    <li>
        <label>label text</label>
        <div>muli select widget</div>
        <span>date selector</span>
    </li>
</ul> 

NB! Assume I don't have control over the HTML rendered from these widgets/third party tools.

The problem is vertical alignment for the scenario above. I've created a JSFiddle which shows how the label doesn't vertically align properly. See here:

http://jsfiddle.net/tMJFF/

How would I get all three these elements to vertically align perfectly?

Jacques
  • 6,936
  • 8
  • 43
  • 102
  • possible duplicate of [Vertical align img and text inside

    ](http://stackoverflow.com/questions/5219324/vertical-align-img-and-text-inside-p)

    – Marc Audet Sep 23 '13 at 10:25

6 Answers6

2

Use inline-block property on all elements

label,
.div-input,
.span-input{
display: inline-block;
vertical-align: middle;
}

http://jsfiddle.net/6vQ4Q/

Anon
  • 2,854
  • 14
  • 18
1

You mentioned Kendo, so I'd recommend using whatever selectors they have decorating the ul and do something like :

ul.kendo-selector-class-of-choice li * {
    vertical-align: middle;
    display : inline; /* for lte IE7 only */
}

Since you aren't in control of the elements being created, this could change with different implementations/version updates of the decorating client side library (in this case Kendo). The * covers that and although arguably a hungry selector its scope is limited by the .kendo-selector-class

The below works in Chrome and IE10, but jsfiddle a bit tricky to browser test for IE8 since it doesn't render properly itself... but if you do test further you'd find you'll have to use something like display:inline if you're going down to the lovely land of IE7-.

http://jsfiddle.net/tMJFF/11/

Stephen James
  • 1,277
  • 9
  • 17
0

Simply add vertical-align:middle;

Here is referenced Fiddle

label {
    vertical-align:middle;
    line-height:20px;
    border:1px solid blue;
}
.div-input {
    vertical-align:middle;
    border:1px solid black;
    margin-right:20px;
    display:inline-block;
    height:20px;
    width:100px;
    box-model:collapse-box
}
.span-input {
    vertical-align:middle;
    border:1px solid black;
    display:inline-block;
    height:20px;
    width:100px;
}
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
0
label {
    line-height:20px;
    border:1px solid blue;
    vertical-align:top;
}
Ankit Agrawal
  • 6,034
  • 6
  • 25
  • 49
0

vertical align all elements in li to middle.

ul li *{
    vertical-align:middle;
}
gp.
  • 8,074
  • 3
  • 38
  • 39
0

vertical-align css property aligning your tags vertically so simply use :

label,div,span{
    vertical-align :middle
}

DEMO

Shirin Abdolahi
  • 1,047
  • 8
  • 18