【发布时间】:2021-10-23 02:44:09
【问题描述】:
我正在尝试使用 Flexbox 对齐 ::placeholder 伪元素。
我知道传统的对齐方式,例如 text-align 用于内联对齐,line-height hack 用于块对齐,或者只是绝对定位。我对这些不感兴趣。
Flexbox 可以很好地对齐 ::before 和 ::after 伪元素(试试看!)。但不知何故,它不适用于对齐 <textarea> 和 <input> 元素的 ::placeholder 伪元素。
为什么?
textarea {
height: 10rem;
display: flex;
/* should put it center center */
align-items: center;
justify-content: center;
}
input {
height: 10rem;
display: flex;
/* should put it top center */
align-items: flex-start;
justify-content: center;
}
<textarea placeholder="Some text"></textarea>
<input placeholder="Some text" />
【问题讨论】:
-
在 css 中使用 textarea::placeholder 并尝试
标签: css flexbox alignment textarea