문제

I want to vertically align "text" with the select element. They both need to be inside separate divs. Is this possible?

<fieldset>
<div style="display:inline-block;float:left;vertical-align:middle">
    text
</div>
<div style="display:inline-block;float:left">
    <select>
        <option>select
        </option>
    </select>
    properly aligned
</div>
</fieldset>    

http://jsfiddle.net/ATN8n/1/

도움이 되었습니까?

해결책

Because your texts are both in separate divs, these 2 divs should have the same height, then we have to change the vertical-align accordingly like this:

<div style="display:inline-block; float:left; height: 30px;">
    text
</div>
<div style="display:inline-block; float:left; height:30px;">
    <select>
        <option>select
        </option>
    </select>            
</div>

div:before {
 content:'';
 display:inline-block;
 height:100%;
 vertical-align:middle;
}

Here is the fiddle

다른 팁

Wrap your text in a span tag like this:

<span>text</span>

then style it like this:

span {
    display: inline-block; 
    vertical-align: middle;
}

edit: Fiddle

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top