【问题标题】:How to make a header bar fold over the webpage css如何使标题栏折叠在网页css上
【发布时间】:2012-12-07 06:16:45
【问题描述】:

谁能告诉我CSS代码或指向一个关于如何实现这个效果的教程。 这是我正在谈论的图像:

注意:我知道如何使用绝对定位,我只需要知道它们是如何实现效果的。

【问题讨论】:

  • 这是定位问题还是“丝带横幅效果”的问题?

标签: html css effect


【解决方案1】:

这可以相对定位,也可以绝对定位 - 可以采用任何一种方式:

#item {
    position: relative;
    right: -10px; /* moves it 10px to the right */
}

或者绝对:

#item {
    position: absolute:
    top: 20px; /* 20px from the top */
    right: -20px; /* 20px off the right edge */
}

请注意,如果绝对定位的元素没有定位的祖先,则它们将根据视口进行定位。

折叠部分可以使用伪元素:before或:after上的边框来完成。

演示:http://jsfiddle.net/MaepP/2/

【讨论】:

    【解决方案2】:

    如果功能区是问题所在,则在空 (0-size) 元素上使用边框(您可以使用 :after pseudo-element 添加该元素)。 .

    HTML

    <div id="content">
        <div id="ribbon"></div>
    </div>
    

    CSS

    #content{
        background-color:#77c;
        width:300px;
        height:200px;
        position:relative;
    }
    #ribbon{
        position:absolute;
        width:80px;
        height:30px;
        right:-20px;
        top:50px;
        background-color:#999;
    }
    #ribbon:after{
        content:'';
        width:0;
        height:0;
    
        border-color: transparent transparent #666 #666;
        border-style:solid;
        border-width:5px 10px;
    
        position:absolute;
        right:0;
        top:-10px;
    }
    

    演示地址 http://jsfiddle.net/gaby/zJPhy/

    【讨论】:

    • 谢谢你,Gaby 太完美了,你能不能也给我一个左侧的例子。
    • @JohnFloyd,见jsfiddle.net/gaby/zJPhy/2 只需要重新排序边框颜色并正确定位..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多