Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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,我正在尝试更改第二个按钮的背景色。但是,它也会影响第一个按钮。您能帮我吗? 这是我的密码: <table class="table table-striped table-bordered table-hover"> <thead> <tr class="caption"> <th class="center" colspan="8">Name</th> <th class="center"

我正在尝试更改第二个按钮的背景色。但是,它也会影响第一个按钮。您能帮我吗? 这是我的密码:

<table class="table table-striped table-bordered table-hover">
<thead>
    <tr class="caption">
        <th class="center" colspan="8">Name</th>
        <th class="center" colspan="3">
            <button class="btn btn-white btn-info btn-bold" title="Save" onclick="Save();">

            </button>
            <button class="btn btn-white btn-info btn-bold" title="Cancel" onclick="Cancel();">

            </button>

        </th>
    </tr>
    <tr>
</table>

名称

您无缘无故地使用了“+”并且忘记分配类“.”

基本上,从代码中读取:

获取类表、其子元素及其子元素(它是一个类)和效果(为什么、如何?为什么使用此检查?这就像使用if函数)元素thead及其子元素。。(等)


只要给第二个按钮一个额外的类。请看这个

HTML

<table class="table table-striped table-bordered table-hover">
<thead>
    <tr class="caption">
        <th class="center" colspan="8">Name</th>
        <th class="center" colspan="3">
            <button class="btn btn-white btn-info btn-bold" title="Save" onclick="Save();">Save

            </button>
            <button class="btn btn-white btn-info btn-bold second" title="Cancel" onclick="Cancel();">Cancel

            </button>

        </th>
    </tr>
</thead>
</table>

您可以使用第n个子项选择器:

button:nth-child(2) {
  background: red;
}
但在这里,将按钮赋予它自己的类将更有意义:

.btn-cancel {
  background: red;
}
Bootstrap(您似乎正在使用)甚至有
btn danger
类可用于此,因此即使没有任何自定义CSS,它也可以工作:

<button class="btn btn-bold btn-danger" onclick="Cancel();">Cancel</button>
取消
还有其他可用颜色:


顺便说一句,按钮标签不适用于你的代码,应该是这样的

<button class="btn btn-white btn-info btn-bold" onclick="Save();">Save</button>
保存
不是



您的代码不可读,似乎不完整。你确定你粘贴的代码正确吗?你的css是什么样子的?如何将类添加到清晰标识它们的按钮中?如何更改相同类名但不同标题的颜色,并单击表内按钮中的事件?相同的类,不同的类标题?所以它们是不同的类。你能给我解释一下为什么使用“+”吗?他们没有意识到这是代码。
<button class="btn btn-bold btn-danger" onclick="Cancel();">Cancel</button>
<button class="btn btn-white btn-info btn-bold" onclick="Save();">Save</button>
<button class="btn btn-white btn-info btn-bold" title="Save" onclick="Save();"></button>