fungusanthrax fungusanthrax - 19 days ago 4
HTML Question

How can I get the first and last name labels to align under the corresponding input forms?

How can I get the first and last name labels to align under the corresponding input forms? Can someone explain this logically? I think a lot of people would like to know this because of its aesthetics and professional look. The bulk of the CSS code is to perform css media queries.
Thanks in advance!

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link href="css/book_now.css" rel="stylesheet" />
</head>
<body>
<div id="header">
<h1>Danny4Help</h1>
</div>
<div class="col-4 col-m-12"></div>
<div class="col-4 col-m-12">
<div id="container">
<h2>Book now</h2>
<p>Get in touch with us</p>
<ul>
<li><p>Name</p>
<input name="fname" size="8"> <input name="lname" size="14">
<br><label>First</label><label>Last</label>
</li>
</ul>
</div>
</div>
<div class="col-4 col-m-12"></div>
</body>




CSS

* {
box-sizing: border-box;

}
.row::after {
content: "";
clear: both;
display: block;
}
[class*="col-"] {
float: left;
padding: 15px;
}
/* For mobile phones: */
[class*="col-"] {
width: 100%;
}
@media only screen and (min-width: 600px) {
/* For tablets: */
.col-m-1 {width: 8.33%;}
.col-m-2 {width: 16.66%;}
.col-m-3 {width: 25%;}
.col-m-4 {width: 33.33%;}
.col-m-5 {width: 41.66%;}
.col-m-6 {width: 50%;}
.col-m-7 {width: 58.33%;}
.col-m-8 {width: 66.66%;}
.col-m-9 {width: 75%;}
.col-m-10 {width: 83.33%;}
.col-m-11 {width: 91.66%;}
.col-m-12 {width: 100%;}
}
@media only screen and (min-width: 768px) {
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
}
#header{
padding:15px;
background-color:rgb(157,221,220);
margin-bottom:7px;
}
body{
background-color:white;
color:rgb(164,111,67);
}
#container{
font-size:12px;
border:1px solid black;
}
label{
padding:0px;
clear:both;
}


This is what I want it to look like:
x

Answer

You can do it like this

I have wrapped each input field in a <p> tag with the class name .inputs. I have set this class to display inline-block so that they sit inline. Then just place <br/> tags between the <input> and the <lable> so that they are on separate lines.

HTML

      <p>Name</p>
      <p class="inputs">
        <input name="fname" size="8">
        <br/>
        <label>First</label>
      </p>
      <p class="inputs">
        <input name="lname" size="14">
        <br/>
        <label>Last</label>
      </p>

CSS

     .inputs {
       display: inline-block;
     }
Comments