Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

:before和:after的absolute定位错误问题

我的想法是要选中时在选项的右上角有打钩,但是实际上是在父级的右上角,查了一下absolute确实是这个效果,这就让我也不知道怎么解决这个问题了
image.png

image.png

.van-col_active {
    border: 1px solid  #0099ff!important;
    &:before{
        content: "";
        position: absolute;
        display: block;
        border-top: 12px solid #0099ff;
        border-right: 15px solid #0099ff;
        border-bottom:  12px solid transparent;
        border-left:  15px solid transparent;
        border-top-right-radius: 5px;
        right: 0;
        top: 0;
    }
    &:after {
        content: "√";
        position: absolute;
        display: block;
        top: 0;
        right: 1%;
        font-family: Glyphicons Halflings;
        font-weight: bolder;
        font-size: 14px;
        line-height: 18px;
        transform: scale(1.2, 0.8);
        color: #ffffff;
    }
    span {
        color: #0099ff!important;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
.van-col_active {
    position: reltive
}

回想一下 absolute 的定义就知道了,是相对于向上查找到的第一个有定位的祖先元素定位,所以给元素一个定位,其内部的伪元素就会相对于此元素定位了。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...