在CSS中设置父元素和子元素的样式 [英] Style both parent and child element in css

查看:145
本文介绍了在CSS中设置父元素和子元素的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下结构...

I have the following structure...

<a href="#" class="brand-logo">
    <img src="../static/images/logo_wpc-sm.png" alt="WPC Logo" class="wpc-logo"/>
</a>

我有以下CSS代码...

And I have the following css code...

.brand-logo {
    height: 100%;
}
 .wpc-logo {
    height: 100%;
}

我的问题:这是一种可以在一个CSS代码中对两者进行样式设置的方法吗?

My question: It is a way I can style both in one css code?

推荐答案

如果您想要使用相同样式的单独类名,请在CSS选择器之间使用逗号 .

If you want separate class names with the same styles, use a comma , between CSS selectors.

.brand-logo,
.wpc-logo {
  height: 100%;
}

或者您可以创建一个通用类来应用于这两个元素.

Or you can create a common class to apply to both elements.

.common {
  height: 100%;
}

<a href="#" class="brand-logo common">
    <img src="../static/images/logo_wpc-sm.png" alt="WPC Logo" class="wpc-logo common"/>
</a>

这篇关于在CSS中设置父元素和子元素的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆