在css3中添加边框到三角形元素

时间:2012-12-04 17:41:56

标签: css css3 animation geometry border

这是我的代码

CSS

#page {
    width: 900px;
    padding: 0px;
    margin: 0 auto;
    direction: rtl;
    position: relative;
}
#box1 {
    position: relative;
    width: 500px;
    border: 1px solid black;
    box-shadow: -3px 8px 34px #808080;
    border-radius: 20px;
    box-shadow: -8px 5px 5px #888888;
    right: 300px;
    top: 250px;
    text-align: justify;
    -webkit-transition: all .75s;
    font-size: large;
    color: Black;
    padding: 10px;
    background: #D0D0D0;
    opacity: 0;
}
@-webkit-keyframes myFirst {
    0% {
        right: 300px;
        top: 160px;
        background: #D0D0D0;
        opacity: 0;
    }
    100% {
        background: #909090;
        :;
        right: 300px;
        top: 200px;
        opacity: 1;
    }
}
#littlebox1 {
    top: 200px;
    position: absolute;
    display: inline-block;
}
.littlebox1-sentence {
    font-size: large;
    padding-bottom: 15px;
    padding-top: 15px;
    padding-left: 25px;
    padding-right: 10px;
    background: #D0D0D0;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    -webkit-transition: background .25s ease-in-out;
}
#bothcontainer:hover ~ #box1 {
    -webkit-transition: all 0s;
    background: #909090;
    :;
    right: 300px;
    top: 200px;
    -webkit-animation: myFirst .75s;
    -webkit-animation-fill-mode: initial;
    opacity: 1;
}
#bothcontainer:hover .littlebox1-sentence {
    background: #909090
}
#bothcontainer:hover .triangle {
    border-right: 25px solid #909090
}
.triangle {
    position: relative;
    width: 0;
    height: 0;
    border-right: 25px solid #D0D0D0;
    border-top: 27px solid transparent;
    border-bottom: 24px solid transparent;
    right: 184px;
    -webkit-transition: border-right .25s ease-in-out;
}

HTML

<body dir="rtl">
  <div id="page">
    <div id="bothcontainer">
        <div id="littlebox1" class="littlebox1-sentence">put your mouse here</div>
        <div id="littlebox1" class="triangle"></div>
    </div>
  <div id="box1"></div>
</div>

我想在三角形中添加边框到.littlebox1-sentence

边框将更改其颜色。

Here is a fiddle


我已经接近找到解决方案,但它仍然不是我想要的地方。

Fiddle

3 个答案:

答案 0 :(得分:2)

我不确定你会有什么影响,但我会看看-webkit-filter。它允许您为“此元素及其拥有的任何子元素添加阴影,无论形状如何”。

#littlebox1 {
       top: 200px;
       position: absolute;
       display: inline-block;
       -webkit-filter: drop-shadow(green -10px 0 10px);
}

http://jsfiddle.net/DyxA4/

答案 1 :(得分:1)

三角形是边界。你不能做你想要的。只需制作一张图片。

答案 2 :(得分:1)

另一个解决方案:跳过基于边框的三角形,改为使用三个div:

<div class="sign">
    <div class="arrow"><div></div></div>
    <p>Lorem ipsum dolor</p>
</div>

基本上,我们使用“.arrow div”来创建三角形,并“.arrow”切掉我们不需要的位:

http://jsfiddle.net/k5J6M/1/