• css 伪类:last-child等不起作用


    
    
    <style>
    #icons{ border: 1px solid bisque; height: 250px; } #icons .column{//每一列
    25%; display: inline-block; float: left; text-align: center; } #icons .column .txt{//每列文字 100%; height: 52px; margin-top: 134px; border-right: 2px solid #787b83;//在此处加隔条 } #icons .column .txt:last-child{ border-right: none; } #icons .column .txt p{ 160px; height: 52px; font-size: 14px; line-height: 18px; color: #767777; margin-left: 25%; }

    html:

    <div id="icons">
                <div class="column column1">
                    <div class="txt">
                        <p>打造全新世界观,让你更爱你的生活</p>
                    </div>
                </div>
                <div class="column column2">
                    <div class="txt">
                        <p>丰富多彩的公益活动,发挥新世界的主人公意识</p>
                    </div>
                </div>
                <div class="column column3">
                    <div class="txt">
                        <p>时尚的新理念,超前体验未知的生活</p>
                    </div>
                </div>
                <div class="column column4">
                    <div class="txt">
                        <p>完善的培养机制,培养你全新的世界观</p>
                    </div>
                </div>
            </div>

    效果如下:

    以为在 `#icons .column .txt` 处加隔条后,想把最后一个竖隔条设为 `border:none;` 没想到如上如所示,全部都不见了。

    来,伪类选择器`:first-child`和`:last-child`是根据父级进行筛选的,`#icons .column .txt:last-child` 的父级是‘.txt`,在该处上的子级只有一个,最后的子级当然也是自己本身,所以要想达到效果,就应该在‘.txt`的父级添加伪类。

     

    #icons .column:last-child .txt{
        border-right: none;
    }

     

     

     效果如下:

  • 相关阅读:
    面试系列三 如何保证消息不被重复消费
    面试系列二 消息队列的高可用性
    面试系列一 消息队列
    springcloud系列15 bus的使用
    C++ 参数传值 与 传引用
    [转] 写给立志做码农的大学生
    Python format 格式化函数
    [3] TensorFlow 深层神经网络
    [2] TensorFlow 向前传播算法(forward-propagation)与反向传播算法(back-propagation)
    Python 闭包
  • 原文地址:https://www.cnblogs.com/finn-Reo/p/5899566.html
Copyright © 2020-2023  润新知