【问题标题】:width 100% on div with pseudo-elemets :after :before and position absolutediv 上的宽度为 100%,带有伪元素 :after :before 和绝对位置
【发布时间】:2013-03-11 12:37:24
【问题描述】:

看看这个例子——http://jsfiddle.net/5esgD/2/

我需要用 :after 和 :before 伪元素来定位绝对位置,但背景有错误:(

如何修复不与红色背景重叠的蓝色背景?

<div class="button_box">
    <div class="blue_button"></div>
</div>
<br />
<div style="width: 200px; background: green;">i am 200px</div>

和css

.button_box {
    width: 200px;
    height: 29px;
    position: relative;
}
.blue_button:after {
    background: none repeat scroll 0 0 red;
    border-radius: 0 12px 12px 0;
    content: "";
    display: block;
    height: 29px;
    position: absolute;
    right: 0;
    top: 0;
    width: 12px;
}
.blue_button:before {
    background: none repeat scroll 0 0 red;
    border-radius: 12px 0 0 12px;
    content: "";
    display: block;
    height: 29px;
    left: 0;
    position: absolute;
    top: 0;
    width: 12px;
}
.blue_button {
    background: none repeat scroll 0 0 blue;
    cursor: pointer;
    height: 29px;
    position: absolute;
    width: 100%;
}

【问题讨论】:

    标签: html css width absolute pseudo-element


    【解决方案1】:

    http://jsfiddle.net/5esgD/3/

    如果我正确理解您想要什么,只需将border-radius 添加到.blue-button

    .blue_button {
        background: none repeat scroll 0 0 blue;
    
        border-radius: 12px 12px 12px 12px;
        cursor: pointer;
        height: 29px;
        position: absolute;
        width: 100%;
    }
    

    【讨论】:

    • 是的,你理解正确。但是,如果背景图像呢?看看这个easycaptures.com/fs/uploaded/580/6649977625.jpgborder-radius 是个坏主意:(
    • 我假设您正在执行 :before 和 :after 因为按钮的宽度可以改变大小...您可以使用纯 CSS 而不是图像来制作该按钮吗?
    • 是的,它需要调整大小按钮...但我不能没有图像,因为它们有纹理。
    猜你喜欢
    • 1970-01-01
    • 2015-05-06
    • 2012-04-05
    • 2011-09-29
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 2013-01-06
    • 2020-09-20
    相关资源
    最近更新 更多