Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

html - Add border over triangle element

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...