html - 使用 css last-child 改变边框

标签 html css

是否可以使用 CSS last-child 来做到这一点?

enter image description here

我可以使用相同的类来添加 last-child 并将第二个边框设为更小的 px 吗?或者唯一的方法是添加不同的类名?

.border {
  border: 3px solid black;
  width: 80px;
  display: inline-block;
}
<div class="border"></div>
<div class="border"></div>

最佳答案

您需要包装 border div,然后使用 :last-child 可以实现此目的。

The reason behind using wrapper is :last-child will only try to match the very last child of a parent element

.border {
  border: 3px solid black;
  width: 80px;
  display: inline-block;
}

.border:last-child {
  width: 40px;
}
<div class="wrapper">
  <div class="border"></div>
  <div class="border"></div>
</div>

关于html - 使用 css last-child 改变边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50602582/

相关文章:

javascript - 将宽度设置为 100% 以使其在 js 中响应

javascript - Jquery:挑选出没有 A 类或 B 类的元素

jQuery:悬停链接时动画(淡入淡出)div 中的背景颜色或图像?

javascript - 如何找到哪个脚本修改了所选属性的CSS

javascript - 如果选中复选框,如何将总和除以 2? javascript/html

html - 为什么我的 Bootstrap 输入没有正确对齐?

php - 在不使用 API 和库但使用标题类型的情况下将 Html + CSS 页面呈现为 PDF

javascript - 改进 HTML-Tagname-strip 的正则表达式

html - 如何在不使用图像的情况下在 css 中创建曲线

javascript - 以下切换/poptext 不起作用