Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 以id和类为目标_Html_Css - Fatal编程技术网

Html 以id和类为目标

Html 以id和类为目标,html,css,Html,Css,我有两个单独的HTML页面: <!-- in the body of page1.html --> <div class="foo"> <!-- content goes here --> </div> 有没有一种较短的(干燥-不要重复)方法可以做到这一点?您可以尝试以下方法: .foo, #bar { width: 680px !important; } 您可以这样尝试: .foo, #bar { width: 680px !

我有两个单独的HTML页面:

<!-- in the body of page1.html -->
<div class="foo">
    <!-- content goes here -->
</div>

有没有一种较短的(干燥-不要重复)方法可以做到这一点?

您可以尝试以下方法:

.foo, #bar {
  width: 680px !important;
}

您可以这样尝试:

.foo, #bar {
  width: 680px !important;
}

这可能是“六个一个,六个其他”的场景之一,但你在寻找这个吗

.foo, #bar {
    width: 680px !important;
}
#bar {
    margin: auto;
}

您可以将所有喜欢的选择器放在一个CSS块上,用逗号分隔。

这可能是“六个一个,半打其他”场景之一,但您正在寻找这个吗

.foo, #bar {
    width: 680px !important;
}
#bar {
    margin: auto;
}

您可以在单个CSS块上使用您喜欢的所有选择器,并用逗号分隔。

.foo
类添加到HTML中的
#条中:

<div id="bar" class="foo">
    <!-- some other content goes here -->
</div>

.foo
类添加到HTML中的
#bar

<div id="bar" class="foo">
    <!-- some other content goes here -->
</div>

这对你很有帮助

CSS

.foo, #bar {
  width: 680px !important;
}
HTML

<div class="foo">
    <!-- content goes here -->
</div>

<div id="bar">
    <!-- some other content goes here -->
</div>


要分组选择器,请用逗号分隔每个选择器。

这对您很有帮助

CSS

.foo, #bar {
  width: 680px !important;
}
HTML

<div class="foo">
    <!-- content goes here -->
</div>

<div id="bar">
    <!-- some other content goes here -->
</div>


要对选择器进行分组,请用逗号分隔每个选择器。

为什么不将
foo
类添加到
div?或者,只需使用
.foo,#bar{css}
@dognose子选择器在本例中不起作用,因为
#bar
不是
foo
的子选择器。我想OP想要
.foo,#bar{css}
。是的,使用逗号分隔的选择器
.class,#id{rule}
使用逗号作为常见的css,谢谢。@Santi当然你是对的,只是忘记了逗号。为什么不将
foo
类添加到
bar
div中呢?或者,只需使用
.foo,#bar{css}
@dognose子选择器在本例中不起作用,因为
#bar
不是
foo
的子选择器。我想OP想要
.foo,#bar{css}
。是的,使用逗号分隔的选择器
.class,#id{rule}
使用逗号作为常见的css就行了,谢谢。@Santi当然你是对的,只是忘记了逗号。是的,这就是我想要的。是的,这不是我想的那种解决方案,但我知道你从哪里来。这不是我想的那种解决方案,但我知道你从哪里来。