<div> 标签内的 <input > 标签垂直对齐失败
Vertical Alignment of <input > tag within a <div> tag Fails
我正在尝试使用 CSS 网格来定位 div 标签和其中的输入字段。不断失败的部分是垂直对齐。我尝试了在线论坛中提出的许多建议,但没有任何效果。将输入字段对齐到 div 标签的底部对我来说很重要。如果有任何帮助,我将不胜感激。
我已经在直接 div 中尝试了 vertical-align="bottom",其中包含输入以及输入标签本身。
我试过使用 position="absolute" 和 bottom="0".
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: helvetica;
font-size: 36px;
color: white;
}
.container {
display: grid;
grid-gap: 5px;
grid-template-columns: [open-paren] 0.5fr [atomic-symbol]1.0fr;
width: 25%;
padding: 3px;
border: 3px solid teal;
border-radius: 5px;
}
.item {
background-color: teal;
border-radius: 5px;
border: 3px solid teal;
height: 100px;
vertical-align: bottom;
}
.item:nth-child(1) {
grid-row: 1/5;
grid-column: open-paren;
text-align: right;
}
.item:nth-child(2) {
grid-row: 4/9;
grid-column: atomic-symbol;
}
</style>
</head>
<body>
<section class="container">
<div class="item">
<p vertical-align="text-bottom">Open</p>
</div>
<div class="item">
<input type="text" vertical-align="bottom">
</div>
</section>
</body>
</html>
包含在 div 标签内的任何元素都与其底部对齐。
我不知道我是否理解正确,但这是将输入定位在 div。
* {
padding: 0;
margin: 0;
}
body {
font-family: helvetica;
font-size: 36px;
color: white;
}
.container {
display: grid;
grid-gap: 5px;
grid-template-columns: 0.5fr 1fr;
width: 50%;
padding: 3px;
border: 3px solid teal;
border-radius: 5px;
}
.item {
display: grid;
align-items: end;
height: 100px;
border-radius: 5px;
border: 3px solid teal;
background-color: teal;
}
.item p {
text-align: right;
}
<section class="container">
<div class="item">
<p>Open</p>
</div>
<div class="item">
<input type="text">
</div>
</section>
我正在尝试使用 CSS 网格来定位 div 标签和其中的输入字段。不断失败的部分是垂直对齐。我尝试了在线论坛中提出的许多建议,但没有任何效果。将输入字段对齐到 div 标签的底部对我来说很重要。如果有任何帮助,我将不胜感激。
我已经在直接 div 中尝试了 vertical-align="bottom",其中包含输入以及输入标签本身。
我试过使用 position="absolute" 和 bottom="0".
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: helvetica;
font-size: 36px;
color: white;
}
.container {
display: grid;
grid-gap: 5px;
grid-template-columns: [open-paren] 0.5fr [atomic-symbol]1.0fr;
width: 25%;
padding: 3px;
border: 3px solid teal;
border-radius: 5px;
}
.item {
background-color: teal;
border-radius: 5px;
border: 3px solid teal;
height: 100px;
vertical-align: bottom;
}
.item:nth-child(1) {
grid-row: 1/5;
grid-column: open-paren;
text-align: right;
}
.item:nth-child(2) {
grid-row: 4/9;
grid-column: atomic-symbol;
}
</style>
</head>
<body>
<section class="container">
<div class="item">
<p vertical-align="text-bottom">Open</p>
</div>
<div class="item">
<input type="text" vertical-align="bottom">
</div>
</section>
</body>
</html>
包含在 div 标签内的任何元素都与其底部对齐。
我不知道我是否理解正确,但这是将输入定位在 div。
* {
padding: 0;
margin: 0;
}
body {
font-family: helvetica;
font-size: 36px;
color: white;
}
.container {
display: grid;
grid-gap: 5px;
grid-template-columns: 0.5fr 1fr;
width: 50%;
padding: 3px;
border: 3px solid teal;
border-radius: 5px;
}
.item {
display: grid;
align-items: end;
height: 100px;
border-radius: 5px;
border: 3px solid teal;
background-color: teal;
}
.item p {
text-align: right;
}
<section class="container">
<div class="item">
<p>Open</p>
</div>
<div class="item">
<input type="text">
</div>
</section>