html-将CSS样式应用于DIV中的所有元素
我想将CSS文件应用于页面中的具体DIV。 这是页面结构:
...
...
(all the elements here must follow a concrete CSS rules)
...
我试图应用CSS文件的规则来编辑它(CSS文件太大):
#applyCSS * { (For all the elements inside "applyCSS" DIV:)
.ui-bar-a {
...
...
}
.ui-bar-a .ui-link-inherit {
...
}
...
}
但是该解决方案不起作用。 那么,我该怎么做呢?
user1702964 asked 2020-08-11T23:55:15Z
7个解决方案
115 votes
#applyCSS > * {
/* Your style */
}
检查这个JSfiddle
它将为所有子代和孙子代设置样式,但将排除div本身中松散飞行的文本,并且仅定位(通过标签)包装的内容。
Nisse Engström answered 2020-08-11T23:55:49Z
25 votes
您可以尝试:
#applyCSS .ui-bar-a {property:value}
#applyCSS .ui-bar-a .ui-link-inherit {property:value}
等等,这就是您想要的吗?
Arkana answered 2020-08-11T23:55:25Z
11 votes
.yourWrapperClass * {
/* your styles for ALL */
}
此代码将为.yourWrapperClass中的所有元素应用样式。
Adem Büyük answered 2020-08-11T23:56:09Z
7 votes
我不明白为什么它对您不起作用,但对我却有效:[http://jsfiddle.net/igorlaszlo/wcm1soma/1/]
HTML
This "a" element text should be red
This span text in "a" element should be red too
CSS
#applyCSS * {color:red;display:block;margin:20px;}
也许您有一些未与我们分享的特殊规则...
Igor Laszlo answered 2020-08-11T23:56:42Z
5 votes
如下编写所有class / id CSS。 .ui-bar-a ID将是所有CSS代码的父级。
例如,您在CSS中添加了类.ui-bar-a以应用于div:
#applyCSS .ui-bar-a { font-size:11px; } /* This will be your CSS part */
以下是您的HTML部分:
Nilesh answered 2020-08-11T23:57:11Z
5 votes
如果您正在寻找写出所有选择器的快捷方式,那么CSS预处理器(Sass,LESS,Stylus等)可以满足您的需求。 但是,生成的样式必须是有效的CSS。
萨斯:
#applyCSS {
.ui-bar-a {
color: blue;
}
.ui-bar-a .ui-link-inherit {
color: orange;
}
background: #CCC;
}
生成的CSS:
#applyCSS {
background: #CCC;
}
#applyCSS .ui-bar-a {
color: blue;
}
#applyCSS .ui-bar-a .ui-link-inherit {
color: orange;
}
cimmanon answered 2020-08-11T23:57:40Z
0 votes
替代解决方案。 通过以下方式将外部CSS包含在HTML文件中
在applyCSS.css中:
#applyCSS {
/** Your Style**/
}
RED.Skull answered 2020-08-11T23:58:04Z