重定位一个伪元素

时间:2015-05-12 21:40:53

标签: javascript jquery html css

我有以下html / CSS,它在带有图像背景的div底部创建一个元素

在div底部创建的形状...

enter image description here

HTML

<div style="background-image:url('...');">
    <div class="mask"></div>
</div>

CSS

.mask:before {
    border-left: 0 none;
    border-right: 20px solid transparent;
    left: 0;
}

.mask:after {
    border-left: 20px solid transparent;
    border-right: 0 none;
    right: 0;
}

.mask:before, .mask:after {
    border-bottom: 20px solid #fff;
    content: " ";
    display: block;
    height: 0;
    position: absolute;
    top: 0;
    width: 50%;
    box-sizing: border-box;
}

.mask {
    bottom: 0;
    height: 20px;
    left: 0;
    position: absolute;
    width: 100%;
    z-index: 1000;
}

我的移动设备下有这个代码&#39; jQuery的。我希望在屏幕尺寸上旋转形状(箭头/三角形指向侧面)。但不知道如何重写代码来做到这一点。

修改

https://jsfiddle.net/hunt0194/gu1sgotd/

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你需要箭头指向你底部的左/右指向?这里是所有解决方案:

(另外,您只能使用一个pseudo element来创建箭头。)

&#13;
&#13;
.main{
  background:red;
  height:50px;
  position:relative;
  margin-bottom: 100px;
}

.arrow{
  content: '';
  position:absolute;
  width: 0;
  height: 0;
  border-style: solid;
  margin-left: -15px;
  left:50%;
}

.bottom{
  bottom: -30px;
  border-width: 30px 30px 0 30px;
  border-color: red transparent transparent transparent;  
}

.up{
  bottom: -30px;
  border-width: 0 30px 30px 30px;
  border-color: transparent transparent red transparent;  
}

.left{
  bottom: -60px;
  border-width: 30px 30px 30px 0;
  border-color: transparent red transparent transparent;  
}

.right{
  bottom: -60px;
  border-width: 30px 0 30px 30px;
  border-color: transparent transparent transparent red;
}
&#13;
<div class="main">
  <div class="arrow bottom"></div>
</div>

<div class="main">
  <div class="arrow up"></div>
</div>

<div class="main">
  <div class="arrow left"></div>
</div>

<div class="main">
  <div class="arrow right"></div>
</div>
&#13;
&#13;
&#13;

另请参阅CSS triangle generator

至于&#34; 我希望在屏幕尺寸&#34;上旋转形状(箭头/三角形指向侧面),只需使用已发布样式的media-queries - JSFiddle