类扩展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
的元素将有一个红色边框,但那些具有idone
和classread more
的元素将有绿色边框
还要注意,属性
background
将删除基类中的属性background image
。因此,idone
和classread more
的元素将不会有图像。你说的“OK”是什么意思?正确吗?或者,如果它是一个类,那么它的所有规则在所有上下文中都必须相同?它是100%有效的CSS。你特别关心什么?好的,谢谢)我已经问过了,在我对课程有点困惑之后