[英]How can I vertically align this placeholder inside an input=“text” form?
默認情況下,輸入中的文本垂直居中。
padding-top: 2%;
導致它被推到底部。
對於修復,我建議使用高度或將 padding-bottom 設置為 2%
很難說不提供任何 html 或 css,但看起來您可能會在不更改line-height
屬性的情況下強制輸入height
。
我猜你想創建自定義輸入。
我的建議是你可以通過編寫這樣的代碼來實現它
#search-bar { padding: 10px 20px; border-radius: 20px; border: none; } body { background: #292929; }
<input id="search-bar" placeholder="Some text.." />
您還可以使用::placeholder
設置占位符樣式
#search-bar { padding: 10px 20px; border-radius: 20px; border: none; } #search-bar::placeholder { color: red; letter-spacing: 4px; } body { background: #292929; }
<input id="search-bar" placeholder="Some text.." />
編輯
我也想向您推薦一些 flexbox。
請看一下這段代碼。 我們可以使用display: flex
輕松地將子元素居中在父元素中,並使用justify-content
, align-items
.parent { border: 1px solid black; width: 200px; height: 200px; display: flex; justify-content: center; /* this is for horizontal alignment */ align-items: center; /* this is for vertical alignment */ }.child { background: lightskyblue; width: 50px; height: 50px; }
<div class="parent"> <div class="child"></div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.