作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在将 box-shadow 添加到我的文本区域时遇到问题。下图描述了我正在努力实现的目标。
CSS 代码:
.text_area {
position: relative;
box-sizing: border-box;
width: 100%;
height: 120px;
resize: none;
outline: none;
padding: 5 10px;
border: none;
background: #ffffff;
font-size: 13px;
color: #292c2e;
letter-spacing: 0;
}
.text_area::placeholder {
position: absolute;
top: 50%;
left: 0;
color: #e3e3e3;
}
如果有人知道如何正确添加 box-shadow inset 请写信给我!
最佳答案
我能想到的实现这一点的唯一方法是将 textarea 包装到另一个元素中并使用伪元素添加渐变。这是因为 textarea 不是 block 级元素(不能在其中包含其他元素)。
看这个例子:
.wrapper {
height: 500px;
width: 500px;
resize: both;
position: relative;
}
textarea {
width: 100%;
height: 100%;
resize: none;
box-sizing: border-box;
}
.wrapper::after {
background-image: linear-gradient(white, transparent);
position: absolute;
z-index: 2;
content: "";
top: 0;
left: 0;
height: 20%;
width: 100%;
pointer-events: none;
}
<div class='wrapper'>
<textarea>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</textarea>
</div>
关于html - 如何仅在顶部将 box-shadow inset 添加到 textarea?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58898953/
我是一名优秀的程序员,十分优秀!