4

这是一个例子。http://jsfiddle.net/52c7t/

简单地说:我试图让 div 在右侧,在左侧有一个像 div 一样的边框。(我希望边框位于右侧 div 的左侧)

我尝试了一百万种不同的组合,但都无法做到。我试图避免制作图像并使用 css 执行此操作。

谢谢你的帮助!

更新:

我的意思的图像。对不起我的平面设计技巧:P

http://i.imgur.com/pGSnL.png

HTML

<div id = "top_bar">
        <div  id="top_left_button" >border</div>
        <div  class = "trapezoid"> none </div>
</div>​

CSS

.trapezoid{
    vertical-align: middle;
    position:absolute;
    border-bottom: 60px solid blue;
    border-left: 45px solid transparent;
    border-top-left-radius:30px;
    *border-top-right-radius:15px;
    *border-bottom-right-radius:3px;
    height: 0;
    width: 50px;
    display: inline-block;
    right:1px;
}



#top_bar{
    background-color: #000;
    border-bottom: 1px solid #666;
    color: #222;
    position:fixed;
    left:0px;
    top: 0px;
    width:100%;
    overflow:hidden;
    height: 50%;
    font-weight: normal;
    white-space: nowrap;
    color: white;
    z-index:20; 
    line-height: 45px;
    min-width:320px;
    max-width: 320px;
    max-height:48px;
    border-radius: 5px;
    text-shadow: rgba(0,0,0,0.6) 0px -1px 0px; 
}

#top_bar:after {
    content: '';
    width: 10%;
    display: inline-block;
    font-size: 0;
    line-height: 0
}

#top_title, #top_left_button, #notifications, #top_right_button {
    color: white;
    height: 100%;
    overflow:hidden;
    display: inline-block;
    text-align: center;
    vertical-align: middle;
}
#top_left_button,#top_right_button{
    width: 20%;
    background: rgba( 100, 255, 255, .1 );
}


#top_left_button{
    border-right: 2px solid #666;

}​

编辑:更新链接

4

2 回答 2

3

简单的解决方案是创建另一个 div,因为您的蓝色 div 已经使用边框属性组成。

那个新的 div 本质上是蓝色 div 的克隆,但是会被染成红色并使用 CSS 的 width 属性变得更大一些。这成为蓝色 div 的伪边框。

新 div 示例:

.trapezoid-border{
    vertical-align: middle;
    position:absolute;
    border-bottom: 60px solid red;        /* Color Changed will be pseudo-border color */
    border-left: 45px solid transparent;
    border-top-left-radius:30px;
    *border-top-right-radius:15px;
    *border-bottom-right-radius:3px;
    height: 0;
    width: 53px;                       /* Extra 3 pix when compared to .trapezoid class width */
    display: inline-block;
    right:1px;
}

jsFiddle 演示

于 2012-12-08T23:59:09.983 回答
1

坦率地说,我认为你应该为此使用图像,但如果你真的想要或不得不避免这种情况,一个有点脏(虽然我认为看起来很有说服力)的解决方法是创建一个固定大小的 red <div>,你可以定位和旋转(利用transform属性)恰到好处地达到相应的效果。

.redborder {
    background-color:red; 
    width:3px;
    height:70px;
    transform:rotate(37deg);
    -ms-transform:rotate(37deg);
    -moz-transform:rotate(37deg);
    -webkit-transform:rotate(37deg);
    -o-transform:rotate(37deg);
    position:absolute;
    right:70px;
    top:-10px;
}

关于 jsfiddle:http: //jsfiddle.net/QBTpV/18/

(在 Chrome 和 IE 中测试)

于 2012-12-09T00:05:04.970 回答