Forum Moderators: not2easy

Message Too Old, No Replies

Centre text horizontally on dropdown menu

         

terrybarnes

5:52 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



This is probably a really easy thing but if I specify the height a dropdown menu should be (I've used a ridiculous 30px in this example) is there then any way to specify that the text sits in the middle rather than at the top of the dropdown?

I've also included a normal dropdown with no specific height given.

Any help would be much appreciated.

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Untitled Page</title>
<style type="text/css" media="screen"><!--
.text { font-size: 12px; font-family: arial; }
.text2 { font-size: 12px; font-family: arial; height: 30px; }
--></style>
</head>

<body>
<form id="FormName" action="(EmptyReference!)" method="get" name="FormName">
<select class="text2" name="selectName" size="1">
<option value="one">Choose from this list</option>
<option value="two">second</option>
<option value="three">third</option>
</select><br />
<br />
<select class="text" name="selectName" size="1">
<option value="one">Choose from this list</option>
<option value="two">second</option>
<option value="three">third</option>
</select>
</form>
</body>

</html>

Stomme_poes

10:07 am on Feb 16, 2008 (gmt 0)

10+ Year Member



I kinda answered this at the thread called "How to vertically align a piece of text in a button" but your situation is a little different cause forms are weeeeeeird.

You could give this a go:

select {
line-height: 30px;
other stuff;
}

Since you said you've made the selects in this example 30px. This looks like crapola if there are two lines, but I don't think I've ever seen that in a dropdown.

Forms are notorious for being difficult to style-- anything you try, test and double test against every browser, esp. Safari, which really is kinda anal about its forms and does not allow a lot of styling tricks to be used.

As a side note, you don't have to use size="1" as that's apparently the default in every browser anyway.

*edit, I hope there was a doctype at the top of that example. IE6 is bad enough in "Standards" mode (and watch out, it thinks line-height is height!), let alone Quirks mode.

[edited by: Stomme_poes at 10:09 am (utc) on Feb. 16, 2008]