gpt4 book ai didi

html - 如何让名字和姓氏标签在相应的输入表单下对齐?

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:44 26 4
gpt4 key购买 nike

如何让名字和姓氏标签在相应的输入表单下对齐?有人可以从逻辑上解释这个吗?我想很多人都想知道这个,因为它的美学和专业外观。大部分 CSS 代码用于执行 css 媒体查询。提前致谢!

<!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;
}

这就是我想要的样子: x

最佳答案

你可以像this JSFiddle那样做

我已将每个输入字段包装在 <p> 中带有类名的标签 .inputs .我已将此类设置为显示 inline-block这样 <p>标签彼此串联。然后只需放置 <br/> <input> 之间的标签和 <lable>以便它们在不同的行上。

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;
}

关于html - 如何让名字和姓氏标签在相应的输入表单下对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40639727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com