Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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,我对:last-child选择器的用法有点困惑。我有不同的按钮,标记如下: <div class="people"> <a href="pd.html" title="Post-Doctorate's"> <div class="people-button">Post-Doctorate's</div> </a> <a href="staff.html" title="Staff">

我对:last-child选择器的用法有点困惑。我有不同的按钮,标记如下:

<div class="people">
    <a href="pd.html" title="Post-Doctorate's">
        <div class="people-button">Post-Doctorate's</div>
    </a>
    <a href="staff.html" title="Staff">
        <div class="people-button">Staff</div>
    </a>
    <a href="phdstudents.html" title="PhD Students">
        <div class="people-button">PhD Students</div>
    </a>
</div>

但这似乎不是正确的选择。有关如何执行此操作的任何帮助或解释?

您的代码正确且有效(),但仅适用于受支持的浏览器。
ie:
最后一个孩子
在IE9以下不起作用

要查看兼容性表,请参阅:

另一个问题是,它可能被另一个具有主要优先级的CSS规则覆盖。使用浏览器中的开发工具(F12)或关联菜单(右键单击定位点)检查元素

通常,浏览器将在该元素的右窗格中显示计算的CSS样式&应用(和覆盖)的所有样式


你可以重写你的代码。取下
a
内的
div
s,并将
a
设置为
display:block
以断开行和工作填充:

<a href="pd.html" title="Post-Doctorate's" class="people-button">
    Post-Doctorate's
</a>
<a href="staff.html" title="Staff" class="people-button">
    Staff
</a>
<a href="phdstudents.html" title="PhD Students" class="people-button">
    PhD Students
</a>

你的代码工作得很完美:对我来说很好:你的意思是
填充底部
?它按预期运行,代码运行良好。您使用的是哪种浏览器?是的,我想你要的是填充物。太棒了。。我提出了一个答案,唯一的一票是否决票,没有任何解释。我不太清楚被重写代码的问题到底在哪里,所以我尝试了你的建议,它奏效了,谢谢!顺便说一句,我还发现了另外一个问题:可以使用:last of type选择器,然后编写.people按钮:last of type{margin bottom:5px;}
<a href="pd.html" title="Post-Doctorate's" class="people-button">
    Post-Doctorate's
</a>
<a href="staff.html" title="Staff" class="people-button">
    Staff
</a>
<a href="phdstudents.html" title="PhD Students" class="people-button">
    PhD Students
</a>
.people-button {
    display: block;
}
.people a:last-child {
    padding-bottom: 50px;     /* if you want space inside anchor */
    background-color: #0aa;
}
.people {
    border: 1px solid #000;
    padding-bottom: 20px;     /* if you just want space at bottom of container */
}