使CSS不影响孩子 [英] making css not affect children

查看:49
本文介绍了使CSS不影响孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使CSS样式不影响该元素的子元素

how can I make a css style NOT affect children of that element

$<style type="text/css">
.parent {
background-color: #0F0;}
.child {
    background-color:#fff
}
</style>

<div class="parent">parent<div class="child">child</div>Parent2</div>

(确实会影响)我知道您可以使用<"将样式仅应用于某些父母的孩子,但是如何仅将样式应用于一个元素?

(that DOES affect) I know you can you the "<" to apply the style to only children of certain parents but how can the style ONLY be applied to one element?

推荐答案

默认情况下,背景色透明.如果我正确理解了您的问题,则可以通过孩子的透明背景看到父母的背景.解决此问题的唯一方法是将孩子的背景设置为所需的颜色.

By default, background-color is transparent. If I understand your question correctly, you are seeing the parent's background through the child's transparent one. The only way around this is to set the child's background to be the colour you want it to.

这篇关于使CSS不影响孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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