dongquexi1990 2018-05-26 03:34
浏览 35
已采纳

Css:最后一个孩子在Laravel @foreach上使用

On Laravel blade I'm using this code to iterate through a list which is filled by an array:

<ul>
    @foreach($prerequisites as $prerequisite)
        <li class="pre-course"
            style="border-bottom: 1px solid #eee;">
            <p>
                ...
            </p>
        </li>
    @endforeach
</ul>

on this my code each <li> have border-bottom: 1px solid #eee; and i'm trying to remove that on last child with Css by code:

ul li.pre-course:last-child {
  border-bottom:none;
}

but it doesn't work and last child have border

  • 写回答

3条回答 默认 最新

  • druhoytza979667566 2018-05-26 03:44
    关注

    I suppose that's due to the inline style overriding the stylesheet CSS. Try to move the "regular" rule from inline to the stylesheet, like this:

    <ul>
        @foreach($prerequisites as $prerequisite)
            <li class="pre-course">
                <p>
                    ...
                </p>
            </li>
        @endforeach
    </ul>
    

    and CSS:

    ul li.pre-course {
      border-bottom: 1px solid #eee;
    }
    ul li.pre-course:last-child {
      border-bottom:none;
    }
    

    That way :last-child will overwrite the regular CSS rule

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部