CSS透明向下三角形仅使用后

时间:2017-04-28 10:12:11

标签: html css

我需要使用CSS三角形创建页面。我担心的是我只能使用:after

图片

Need CSS for this

HTML:

<div class="logo">
  <!--<div class="down"></div>-->
</div>

CSS:

.logo {
  background-image: url("https://cdn0.iconfinder.com/data/icons/small-n-
  flat/24/678110-sign-info-128.png");
  width:124px;
  height: 131px;
  float: left;
  margin-left: 290px;
  margin-top: 30px;
  margin-bottom: 93px;
  z-index: 10 !important;
  position: relative;
  /*margin-right: 160px;*/
}

.logo::after {
  content: '';
  border-left: 80px solid transparent;
  border-right: 80px solid transparent;
  border-top: 80px solid white;
  position: absolute;
  width: 0;
  height: 0;
  top: 90px;
  left: -15px;
  /*top: 120px;
  left: 275px;*/
  clear: both;
  /*transform-origin: 0 100%;        
  transform: rotate(45deg);*/
  /*margin-top: 90px;
  margin-left: 0px;*/
  z-index: 0 !important;
}

我希望徽标应显示在三角形上方。

2 个答案:

答案 0 :(得分:0)

这是因为 z-index 既适用于徽标类,又需要从 .logo 中移除z-index所需的同一类,并添加 -ve z-index .logo :: after

.logo {
background-image: url("https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678110-sign-info-128.png");
width:124px;
height: 131px;
float: left;
margin-left: 290px;
margin-top: 30px;
margin-bottom: 93px;
position: relative;
/*margin-right: 160px;*/
 }
 .logo::after {
content: '';
 border-left: 80px solid transparent;
border-right: 80px solid transparent;
border-top: 80px solid white;
position: absolute;
width: 0;
height: 0;
top: 90px;
left: -15px;
/*top: 120px;
left: 275px;*/
clear: both;
 /*transform-origin: 0 100%;        
transform: rotate(45deg);*/
/*margin-top: 90px;
margin-left: 0px;*/
z-index: -1;
 }

这是一个有用的链接:https://jsfiddle.net/qk5u45Lv/

答案 1 :(得分:0)

还有一个选择:

HTML:

<div class="logo"><span>i</span></div>

Apply this css:

.logo {
  background: #3498db none repeat scroll 0 0;
  border-radius: 100%;
  box-shadow: 0 5px 0 #2980b9;
  height: 100px;
  width: 100px;
  text-align:center;
  position:relative;
}
.logo > span {
  color: #fff;
  font-family: -moz-fixed;
  font-size: 82px;
  font-weight: 600;
  text-align: center;
  text-shadow: 1px 3px 1px #000;
}

.logo::after {
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 50px solid #f00;
  bottom: -45px;
  content: "";
  height: 0;
  left: 0;
  position: absolute;
  width: 0;
  z-index: -1;
}

OUPUT:

enter image description here

了解更多内容link

希望这会对你有帮助!!!

如果有任何疑问,请告诉我。