html怎么让所有元素消失,html-将CSS样式应用于DIV中的所有元素

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部分:

testing

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值