Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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
类扩展CSS_Css - Fatal编程技术网

类扩展CSS

类扩展CSS,css,Css,因为我有一些元素在不同的上下文中有不同的规则,但有些规则是相同的 可以为他们定义一个类并在不同的上下文中扩展它吗 .read-more { display: inline-block; text-align: center; padding: 0 15px; text-decoration: none; color: blue; margin-left: 5px; } #one .read-more { background: yellow

因为我有一些元素在不同的上下文中有不同的规则,但有些规则是相同的

可以为他们定义一个类并在不同的上下文中扩展它吗

.read-more {
    display: inline-block;
    text-align: center;
    padding: 0 15px;
    text-decoration: none;
    color: blue;
    margin-left: 5px;
}
#one .read-more {
    background: yellow;
}
#two .read-more {
    background: #ff9e13;
}

您可以扩展类以满足不同的需要

请注意,未被重写的属性将取自原始类

例如:

.read-more {
    display: inline-block;
    text-align: center;
    padding: 0 15px;
    text-decoration: none;
    color: blue;
    margin-left: 5px;
    border: 1px solid red;
    background-image: url('img.png');
}
#one .read-more {
    background: yellow;
    border: 2px solid green;
}
所有仅具有
read more
的元素将有一个红色边框,但那些具有id
one
和class
read more
的元素将有绿色边框


还要注意,属性
background
将删除基类中的属性
background image
。因此,id
one
和class
read more
的元素将不会有图像。

你说的“OK”是什么意思?正确吗?或者,如果它是一个类,那么它的所有规则在所有上下文中都必须相同?它是100%有效的CSS。你特别关心什么?好的,谢谢)我已经问过了,在我对课程有点困惑之后