125*_*748 2 html javascript css
有没有办法使用这些影子 dom 元素将 css 仅应用于特定元素。我想我希望在我的页面上实现webkit 客户滚动条,但希望textarea它们的宽度小于文档正文上的宽度。
所以如果我有一个带有样式的页面
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
div{
height:5000px;
width:150px;
background-color:red;
float:left;
}
textarea{
float:left;
max-height:150px;
height:150px;
}
Run Code Online (Sandbox Code Playgroud)
和 HTML
<div id="theDiv">
asdf
</div>
<textarea id="thebox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</textarea>
Run Code Online (Sandbox Code Playgroud)
我想将样式表直接应用于文本区域,而不让它影响任何其他元素。
function ImportStyleFile () {
var el = document.getElementById('thebox');
var linkTag = el.createElement ("link");
linkTag.href = "new.css";
linkTag.rel = "stylesheet";
var head = document.getElementsByTagName ("head")[0];
head.appendChild (linkTag);
}
Run Code Online (Sandbox Code Playgroud)
哪里new.css有这样的风格,比如说,
::-webkit-scrollbar-thumb {
border-radius: 0px;
-webkit-box-shadow: inset 0 0 6px rgba(20,20,20,0.5);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这并不是那么简单。我想您无法创建样式表并将其附加到文本区域。关于如何让它发挥作用的任何想法
是::-webkit-scrollbar一个伪元素,可以应用于单个元素,如下所示:
textarea::webkit-scrollbar { ... }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3000 次 |
| 最近记录: |