html - 第一个 child 不在标签上工作

标签 html css css-selectors

first-child 伪类选择器似乎没有任何作用。这是 CSS,然后是 HTML:

.social-block a:first-child {
     margin-bottom: 20px;
 }

 <div class="social-block">
      <a href="#" target="_blank"><img src="stylesheets/img/socialblock-facebook.png" alt="socialblock-facebook" width="300" height="125"></a>
      <a href="#" target="_blank"><img src="stylesheets/img/socialblock-twitter.png" alt="socialblock-twitter" width="300" height="125"></a>
 </div>

不知道哪里错了!

最佳答案

上边距和下边距不适用于行内元素。查看类似问题:Margin top in inline element .

<a>底部边距,您可以尝试使用 display: block 使其成为 block 级元素.但是,这会将第二个链接推到下一行,因此您可能必须采用其他技术(例如 float )才能使两个链接并排显示。

关于行内元素的更多信息:http://www.maxdesign.com.au/articles/inline/

顺便说一句,:first-child IE 8.0 或更早版本不完全支持伪类。参见 CSS contents and browser compatibility .

关于html - 第一个 child 不在标签上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12608019/

相关文章:

HTML 文本框不起作用

jquery 重新排序 div

javascript - 在 JavaScript 转换期间获取当前 CSS 属性值

html - 使用 UI Binder 时 CSS 选择器未解析

类和属性选择器之间的 CSS 性能

html - 调整和定位容器内的div

javascript - border-radius无法通过使用PIE支持工作?

css - 非静态页脚导航栏出现在移动设备屏幕底部上方

css - 我可以合并 :nth-child() or :nth-of-type() with an arbitrary selector?

css - 针对 :nth-child(2) in IE7/IE8