开发者

Aligning labels below text input

I am trying to align labels in a form to go below a text input box. I have adapted my CSS from here.

It displays perfectly in IE 9, but I am havi开发者_运维百科ng trouble with firefox, chrome and others.

Here's what it looks like in IE:

Aligning labels below text input

And this is what it looks like in firefox:

Aligning labels below text input

It looks much worst in chrome, but I would like to get it working in firefox first.

The main concerns are:

  • The text input should be centered above the labels.
  • The colons should be vertically aligned with the text inputs.
  • The drop-down should be vertically aligned with the text inputs.

Here's my markup:

<form action="" method="post">

    <label for="time">Time settings</label>

    <div class="description">
        Description goes here
    </div>

    <span><label for="time">Hour</label> <input type="text" id="time" name="time" maxlength="2" size="2"></span>
    <span>:</span>
    <span><label for="time-minute">Minute</label> <input type="text" id="time-minute" name="time-minute" maxlength="2" size="2"></span>
    <span>:</span>
    <span><label for="time-seconds">Seconds</label> <input type="text" id="time-seconds" name="time-seconds" maxlength="2" size="2"></span>

    <span>
        <select id="time-ampm" name="time-ampm">
            <option value="am">AM</option>
            <option value="pm">PM</option>
        </select>
    </span>
    </form>

And here is the CSS style:

<style>
    span{
        display: inline-block;
    }

    span input { 
        display: block; 
        position: relative; 
        top: -3em; 
        text-align: center;
    } 

    span label { 
        display: block; 
        padding-top: 1.5em; 
        text-align: center;
    } 
</style>

I am also using the HTML 4.01 strict doctype.

Here's the form live in jsfiddle: http://jsfiddle.net/VuShK/

Can anyone give me some pointers as to how to fix this?

Solution: Thanks to everyone who replied.

Here is my final solution with the text inputs being centered. Thanks to AVD for his help.

<style> 
    span{ 
        display: inline-block; 
        position: relative;
        top: -1em;
        text-align:center;
    } 

    span select input {  
        display: block;  
        position: relative;  
        top: -3em;  
    }  

    span label {  
        display: block;  
        position: relative;  
        top:2.7em; 
        text-align: center; 
    }  
</style> 


Try this,

<style>
    span{
        display: inline-block;
    }

    span select input { 
        display: block; 
        position: relative; 
        top: -3em; 
    } 
    span input { text-align:center;}
    span label { 
        display: block; 
        position: relative; 
        top:3em;
        text-align: center;
    } 
</style>


Check this

    <form action="" method="post">  
<table>
    <tr>
        <td colspan="4">
           <label for="time">Time settings</label> 
        </td>
    </tr>
    <tr>
        <td colspan="4">
            <label for="Description">Description goes here</label>  
        </td>
    </tr>
    <tr>
        <td>
            <span><input type="text" id="time-minute" name="time-minute" maxlength="2" size="2"><label for="time">:</label></span>
        </td>
        <td>
            <span><input type="text" id="time-minute" name="time-minute" maxlength="2" size="2"><label for="time-minute">:</label></span>
        </td>
        <td>
            <span>  <input type="text" id="time-seconds" name="time-seconds" maxlength="2" size="2"><label for="time-minute">:</label></span>
        </td>
        <td>
            <span><select id="time-ampm" name="time-ampm"><option value="am">AM</option><option value="pm">PM</option></select></span>
        </td>
    </tr>
    <tr>
        <td>
            <label for="time">Hour</label>
        </td>
        <td>
            <label for="time-minute">Minute</label>
        </td>
        <td>
            <label for="time-minute">Seconds</label>
        </td>
        <td>&nbsp;</td>
    </tr>
</table>     


    <div style="overflow:hidden;border:1px blue solid;">

    <div style="float:left;width:120px;border:1px lime solid;text-align:center;">
        <input style="width:80%;"> :
        <div style="border:1px red solid;">Hours</div>
    </div>
    <div style="float:left;width:120px;border:1px lime solid;text-align:center;">
        <input style="width:80%;"> :
        <div style="border:1px red solid;">Minutes</div>
    </div>
    <div style="float:left;width:120px;border:1px lime solid;text-align:center;">
        <input style="width:80%;"> :
        <div style="border:1px red solid;">Seconds</div>
    </div>
    <div style="float:left;width:120px;border:1px lime solid;text-align:center;">
        <select style="width:90%;"></select>
    </div>

    </div>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜