在三角形元素上添加边框 [英] Add border over triangle element

查看:99
本文介绍了在三角形元素上添加边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在三角形周围创建边框。我到目前为止:



JSFiddle



  .myDiv {width:300px; padding:15px; text-align:right;背景颜色:lightblue;位置:相对; border:1px solid black;}。myDiv :: before {content:; position:absolute; bottom:-20px; right:20px; border-right:20px solid lightblue; border-bottom:20px solid transparent;}  

 < div class =myDiv> Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。 

$>



但我不能添加一个边框到之前的元素。如何在底部添加一个边框('before`元素)?



(我看到这个问题,但我不能应用相同的原则,因为它的形状不同。)

解决方案

尝试添加 ::之后 border-width 和底部和右边不同的位置,它的工作非常好。不要忘记将 border-color 更改为 黑色 -1 ,将 z-index 低调。



示例:






  .myDiv {width:300px; padding:15px; text-align:right;背景颜色:lightblue;位置:相对; border:1px solid black;} 
.myDiv :: before {content:; position:absolute; bottom:-20px; right:20px; border-right:20px solid lightblue; border-bottom:20px solid transparent;}。myDiv :: after {z-index:-1; content:; position:absolute; width:0; height:0; bottom:-22px; right:19px; border-right:21px solid black; border-bottom:21px solid transparent;}

 < div class =myDiv> Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。 

$>



小提示演示


I am trying to create a border around a triangle. I have this so far:

JSFiddle

.myDiv {
  width: 300px;
  padding: 15px;
  text-align: right;
  background-color: lightblue;
  position: relative;
  border: 1px solid black;
}
.myDiv::before {
  content: "";
  position: absolute;
  bottom: -20px;
  right: 20px;
  border-right: 20px solid lightblue;
  border-bottom: 20px solid transparent;
}

<div class="myDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco</div>

But I can't add a border to the before element. How can I add a border around the piece that's sticking out on the bottom ('before` element)?

(I saw this question, but I can't apply the same principle to this, since it's different shapes.)

解决方案

Try to add an ::after with more border-width and different position bottom and right, its work very well. Don't forget to change border-color to black and low down the z-index by -1.

Example:


.myDiv {
  width: 300px;
  padding: 15px;
  text-align: right;
  background-color: lightblue;
  position: relative;
  border: 1px solid black;
}

.myDiv::before {
  content: "";
  position: absolute;
  bottom: -20px;
  right: 20px;
  border-right: 20px solid lightblue;
  border-bottom: 20px solid transparent;
}

.myDiv::after {
  z-index:-1;
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  bottom: -22px;
  right: 19px;
  border-right: 21px solid black;
  border-bottom: 21px solid transparent;
}

<div class="myDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco</div>

Fiddle demo

这篇关于在三角形元素上添加边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆