像branch.com这样的CSS3箭头框

时间:2013-07-23 23:52:52

标签: javascript html css html5 css3

我非常喜欢branch.com上的箭头框,例如:http://tinyurl.com/lw5zlhu

如何使用像branch.com这样的时间轴创建箭头框?

我做了这样的事情:http://jsfiddle.net/uFPEf/6/

HTML

<div class="item">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
       Curabitur adipiscing dignissim purus at adipiscing.
    </p>
</div>
<div class="timeline">
    <div class="line"></div>
</div>
<div class="item">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
       Curabitur adipiscing dignissim purus at adipiscing.
    </p>
</div>
<div class="timeline">
    <div class="line"></div>
</div>
<div class="item">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
       Curabitur adipiscing dignissim purus at adipiscing.
    </p>
</div>

CSS

body {
    font-family: "HelveticaNeue-Light", "Helvetica Neue Light", 
    "Helvetica Neue", Helvetica, Arial, "Lucida Grande", 
    sans-serif; 
    font-weight: 300;
    padding:20px;
}
.item{ 
    border-radius:3px; 
    padding:10px; 
    border: solid 1px #EEEEEE; 
}
.item p {
    color:#333333;
    padding:20px;
}

.timeline { 
    width: 100%;
}

.line {
    background: #EEEEEE;
    height: 50px;
    margin: 0 auto;
    width: 2px;
}

2 个答案:

答案 0 :(得分:2)

你可以使用CSS&#39;元素之前和之后。如果您使用绝对定位直接定位到所需位置,并提供白色背景,则可以模拟它。

.item:before {
    position: absolute;
    top: -11px;
    left: 50px;
    -webkit-transform: rotate(45deg);
    height: 20px;
    width: 20px;
    background: #fff;
    border-top: 1px solid #aaa;
    border-left: 1px solid #aaa;
    content: '';
}
.item:after {
    position: absolute;
    bottom: -11px;
    left: 50px;
    -webkit-transform: rotate(45deg);
    height: 20px;
    width: 20px;
    background: #fff;
    border-top: 1px solid #aaa;
    border-left: 1px solid #aaa;
    content: '';
}

http://jsfiddle.net/uFPEf/7/

答案 1 :(得分:0)

这是一个纯CSS解决方案 虽然使用图像可能更好。

<强> HTML

<div id="box"></div>

<强> CSS

#box{
    width:200px;
    height:200px;
    background:#EEE;
    box-shadow: 0px 0px 2px #999;
    margin:50px;
    position:relative; /* This makes sure the ::after is absolute to this element */
}

#box:after{
    content:''; /* Content is required on all ::before & ::after */
    width:22px;
    height:22px;
    background:#FFF;
    border-top: 1px solid #C2C1C1; /* 3D'ish effect */
    border-left:1px solid #C2C1C1;
    position:absolute;
    bottom:-12px;  /* Half the height of the square */
    left:15px;
    -webkit-transform: rotate(45deg);  /* rotate 45deg to fake a triangle */
}

Demo