How to align my label and input field

风格不统一 提交于 2019-12-05 19:31:20

I had checked your HTML form it has some unwanted columns. Now I have updated the form and I created two demos and I used form elements and grid layout for two columns form.

Semantic-UI Basic Form:

<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet"/>
<div class="example">
   <h4 class="ui header">Semantic UI Form</h4>
   <form class="ui form">
      <div class="field">
         <label>First Name</label>
         <input type="text" name="first-name" placeholder="First Name">
      </div>
      <div class="field">
         <label>Last Name</label>
         <input type="text" name="last-name" placeholder="Last Name">
      </div>
	  <div class="field">
            <label>Categories</label>    
      </div>
	  <div class="field">
		  <div class="inline fields">
				<div class="field"> 
					<div class="ui radio checkbox">
					   <input type="radio" name="frequency" checked="checked">
					   <label>A</label>
					</div>
				</div>
				 <div class="field">
					<div class="ui radio checkbox">
					   <input type="radio" name="frequency">
					   <label>B</label>
					</div>
				 </div>
				 <div class="field">
					<div class="ui radio checkbox">
					   <input type="radio" name="frequency">
					   <label>C</label>
					</div>
				 </div>
		  </div>
	  </div>  
      <button class="ui button" type="submit">Submit</button>
   </form>
</div>

Semantic-UI Two Column Form:

<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet"/>
<div class="ui text container">
  <h4 class="ui header">Semantic UI Form</h4>
  <form class="ui form"> 
	<div class="ui grid">
		<div class="four wide column ">
			<label>First Name</label>
		</div>
		<div class="twelve wide column">
			<input type="text" name="first-name" placeholder="First Name">
		</div>	
	</div>	
	<div class="ui grid">
		<div class="four wide column ">
			<label>Last Name</label>
		</div>
		<div class="twelve wide column">
			<input type="text" name="first-name" placeholder="Last Name">
		</div>	
	</div>

	<div class="ui grid">
		<div class="four wide column ">		
			<div class="field">
				<label>Categories</label>
			</div>
		</div>
		<div class="twelve wide column">	
			<div class="inline fields">	  
			  <div class="field">
				<div class="ui radio checkbox">
				  <input type="radio" name="frequency" checked="checked">
				  <label>A</label>
				</div>
			  </div>
			  <div class="field">
				<div class="ui radio checkbox">
				  <input type="radio" name="frequency">
				  <label>B</label>
				</div>
			  </div>
			  <div class="field">
				<div class="ui radio checkbox">
				  <input type="radio" name="frequency">
				  <label>C</label>
				</div>
			  </div>
			</div>
		</div>
	</div>	
    <button class="ui button" type="submit">Submit</button>
  </form>
</div>

Try this with your label

<label style="padding-right:50px">Title</label>

Also you can use table in your design to make your page design more efficient.

I recommend using Bootstrap - it will take you no more than 30 mins to understand and will make your website page/website layout so easy see - http://getbootstrap.com/

Also, means you website will be mobile and tablet friendly.

  1. just add the files to your website -http://getbootstrap.com/getting-started/ (under first heading Bootstrap CDN).

  2. then paste in the relevant form layout you would like (you can tweak these) - http://getbootstrap.com/css/#forms (under css heading)

  3. see the grid layout system - http://getbootstrap.com/css/#grid

  4. See all the things you can do just pasting in the bootstrap code: buttons, icons, etc (all listed under components - http://getbootstrap.com/components/

Re my answer - have made your view using bootstrap as per my steps 1 - 4. Took me 7 mins, not even 10 :-) ..paste the below into an index file to test/see what it looks like.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

</head>
<body>
<div class="container">
    <div class="row">

        <form class="form-horizontal">

            <div class="form-group">
                <label class="col-sm-2 control-label">Category</label>
                <div class="col-sm-6">
                    <label class="radio-inline">
                        <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 1
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> 2
                    </label>
                </div>
            </div>

            <div class="form-group">
                <label for="inputTitle" class="col-sm-2 control-label">Title</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="inputTitle" placeholder="Title">
                </div>
            </div>

            <div class="form-group">
                <label for="inputText" class="col-sm-2 control-label">Text</label>
                <div class="col-sm-6">
                    <textarea class="form-control" rows="3" placeholder="Text" id="inputText"></textarea>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <button type="submit" class="btn btn-default">Submit</button>
                </div>
            </div>
        </form>

    </div>
</div>


<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!