Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS alignment of spans, inputs, and buttons

Tags:

css

alignment

I'm looking for a way to align a number of elements (spans, inputs, and buttons) such that despite their differing sizes, their vertical mid point is on the same horizontal line: Alignment

How do I achieve this in CSS? Here's the HTML file to play with:

<html>
<head>
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css">
    <style>
.content { font-size: 18px; border: 1px dotted blue;  }
.content input, .content button { font-size: 40px; float: left; }
.label { border: 1px dotted red; float: left; }
.clear { clear: both; }
    </style>
</head>

<body>
<div class="content">
    <span class="label">Label: </span><input type="text">
    <span class="label">More text: </span><input type="text">
    <button type="submit">Submit Me</button>
    <div class="clear"></div>
</div>

</body>

</html>
like image 225
Parand Avatar asked Nov 27 '22 18:11

Parand


1 Answers

Set the main div's line-height: height of tallest element in px, then set vertical-align: middle. You may have to set display:inline or display:inline-block on the subelements as well.

That should work.

like image 67
SickHippie Avatar answered Dec 09 '22 17:12

SickHippie