将 css 样式应用于 div 中的跨度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17481528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:25:12  来源:igfitidea点击:

apply css style to span in div

cssstylesheet

提问by jestges

I've a table structure like below

我有一个像下面这样的表结构

<td id="td1">
<a href="#">
<div>
1
<div>
<span>0</span>
<span>1</span>
<span>2</span>
</div>
</div>
<div> </div>
</a>
</td>

<td id="td2">
<a href="#">
<div>
2
<div>
<span>0</span>
<span>1</span>
<span>2</span>
</div>
</div>
<div> </div>
</a>
</td>

And now I wanted to apply style for spanunder td1 and not to td2. Is there any way to get it dont? How can we write a css style for this?

现在我想在 td1 而不是 td2 下为span应用样式。有什么办法可以不?我们如何为此编写 css 样式?

回答by Mimo

You can use the selector in this way: #td1 span { /* your styles */}

您可以通过以下方式使用选择器: #td1 span { /* your styles */}

回答by Swarnamayee Mallia

Here is the fiddle link

这是小提琴链接

table tr td span {
    padding:0 5px;
    color:#fff;
    background-color:#117809;
    }

or if you want to give css to span within a particular div then following the following css. DEMO

或者,如果您想让 css 跨越特定 div,则遵循以下 css。演示

#td1 span {
    padding:0 5px;
    color:#fff;
    background-color:#DC0B0B;
    }

回答by Rohit Azad

Try to this

试试这个

#td1 span{color:green;font-weight:bold;}

Demo

演示