
网页设计中,经常需要调整表单元素样式,例如:设置较高的input框,同时让文字位于底部而非居中。本文将介绍一种无需padding的巧妙方法。
假设现有HTML结构如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input {
height: 60px;
}
</style>
</head>
<body>
<input type="text" placeholder="请输入文字">
</body>
</html>这段代码中,input高度为60像素,但文字垂直居中。为了让文字位于底部,我们可以采用以下方法:
border: none;移除input的默认边框。改进后的代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.custom-container {
height: 60px;
border: 1px solid #ccc;
display: flex;
align-items: flex-end; /* 关键:将项目垂直对齐到底部 */
}
input {
border: none;
height: 20px; /* 调整高度以适应文字大小 */
width: 100%;
margin-bottom: 5px; /* 微调底部间距 */
}
</style>
</head>
<body>
<div class="custom-container">
<input type="text" placeholder="请输入文字">
</div>
</body>
</html>通过此方法,我们成功地将input高度设置为60像素,同时文字精确地位于底部,并能灵活控制input的外观。 这种方法比单纯使用padding更具可控性和灵活性。
以上就是如何让input的高度变高但文字位于底部?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号