Align textarea in form

陌路散爱 提交于 2019-12-12 02:46:45

问题


I was just wondering what shall I do to align the text area in a form so they can be all at the same level.

my code is:

    <form method="post" action="process.php" id="contactForm">
    <fieldset id="field1">
        <div class="subscribe">
            <label for="fName">First name:</label>
            <input type="text" name="fName" id="fName" required/>
        </div>
        <div class="subscribe">
            <label for="lName">Last name:</label>
            <input type="text" name="lName" id="lName" required/>
        </div>
        <div class="subscribe">
            <label for="title">Title:</label>
            <select name="title" id="title" required>
                <option value="1"> Mr. </option>
                <option value="2"> Ms. </option>
                <option value="3"> Mrs. </option>
                <option value="4"> Miss. </option>
                <option value="5"> Master. </option>
            </select>
        </div>  
        <div class="subscribe">
            <label for="hNumber">Health Authority Number:</label>
            <input type="text" name="number" id="hNumber" required/>
        </div>
        <div class="subscribe">
                <label  for="email">Email address: </label>
                <input type="email" name="email" id="email" required/>
        </div>
        <div class="subscribe">
            <label for="fNr">Telephone number:</label>
            <input type="text" name="fNr" id="fNr" required/>
        </div>
        <div class="button">
            <input id="btn1" type="button" value="Submit"> 
        </div>
    </fieldsed>
</form> 

This CSS code won't do it:

#contactForm {
    width: 46em;
    padding-top: 0.5em;
    padding-bottom: 0.5em;
}

#contactForm label {
    padding: 0.5em;
    display: inline;
    float: center;
}

Thank you for your answers. I know is noobies stuff but it will help me at the minute to get the answer rather then find it out by studying.


回答1:


Try that:

  1. use inline-block instead;
  2. set a fixed width
  3. delete your padding

I think that's it

#contactForm label {    
display: inline-block;
width: 200px;
text-align: left;
}


来源:https://stackoverflow.com/questions/24682823/align-textarea-in-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!