2016-07-26 45 views
-1

由於我找到的所有問題都是關於「評論框箭頭」的;將三角形連接到div

我想打一個DIV它看起來像這樣

enter image description here

我需要兩個三角形附加到一個div容器,但我不知道如何做到這一點。目前我的代碼看起來像這樣:http://codepen.io/anon/pen/yJEyOm

.expand { 
    width: 200px; 
} 

.expand:after { 
    content: " "; 
    width: 0; 
    height: 0; 
    border-style: solid; 
    border-width: 0 5px 5px 0; 
    border-color: transparent #007bff transparent transparent; 
} 

.expand:before { 
    content: " "; 
    width: 0; 
    height: 0; 
    border-style: solid; 
    border-width: 0 5px 5px 0; 
    border-color: transparent #007bff transparent transparent; 
} 

的這裏的問題是,三角形沒有在總顯示,只是它的一部分。如何解決這個問題?

回答

1

類似這樣的:http://codepen.io/anon/pen/OXEPmB? 問題是僞元素的位置。

.expand { 
    width: 100px; 
    background-color: #007bff; 
    position: relative; 
    padding-left: 10px; 
} 

.expand:after { 
    content: " "; 
    width: 0; 
    height: 0; 
    border-style: solid; 
    border-width: 0px 0px 10px 10px; 
    border-color: #fff #fff #fff #007bff; 
    position: absolute; 
    right: 0; 
    bottom: 0; 
} 

.expand:before { 
    content: " "; 
    width: 0; 
    height: 0; 
    border-style: solid; 
    border-width: 0 10px 10px 0; 
    border-color: #fff #007bff #fff #fff; 
    position: absolute; 
    left: 0; 
    bottom: 0; 
} 
1

試試這個

div{ 
 
    width:100%; 
 
    position:relative; 
 
    background:red; 
 
    height:20px; 
 
} 
 
div:before{ 
 
    content: ''; 
 
    display: block; 
 
    position: absolute; 
 
    bottom: -20px; 
 
    left: 50%; 
 
    transform:translate(-50%,0); 
 
    border-top: 23px solid red; 
 
    border-left: 16px solid transparent; 
 
    border-right: 16px solid transparent; 
 
    height: 0; 
 
    width: 50%; 
 
} 
 
span{ 
 
    display:block; 
 
    position:absolute; 
 
    left:50%; 
 
    transform:translate(-50%,0); 
 
    bottom:-20px; 
 
    font-size:20px; 
 
}
<div> 
 
    <span>Expand</span> 
 
</div>

0

試試這個代碼。

.container{ 
 
    width: auto; 
 
    background-color: #007bff; 
 
    height:20px; 
 
} 
 

 
.expand { 
 
    position:absolute; 
 
    width: 85px; 
 
    height: 0px; 
 
    border-left: 20px solid transparent; 
 
    border-right: 20px solid transparent; 
 
    border-top: 20px solid #007bff; 
 
    margin-top:18px; 
 
    margin-left:25px; 
 
    
 
} 
 

 
.expand p{ 
 
    margin-top:-20px; 
 
    padding-left:12px 
 
    
 
}
<div class="container"> 
 

 
    <div> 
 
    <div class="expand"><p>expand</p></div>

0

這可以讓你TOT添加和自定義任何你想要的。只需添加img並自定義空間並完成。

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <meta charset="UTF-8"> 
 
\t \t <title>Insert title here</title> 
 
\t \t <style> 
 
\t \t \t a { text-decoration:none; } 
 
\t \t \t ul, ul li { margin:0; padding:0; } 
 
\t \t \t ul li { display:inline-block; } 
 
\t \t \t ul li a { background: url('navrepeater.png') repeat-x #efefef; line-height: 20px; display:inline-block; } 
 
\t \t \t ul li a:before, ul li a:after { 
 
\t \t \t \t content: ""; 
 
\t \t \t \t width: 30px; 
 
\t \t \t \t height: 30px; 
 
\t \t \t \t display: inline-block; 
 
\t \t \t \t vertical-align: middle; 
 
\t \t \t } 
 
\t \t \t ul li a:before { background: url('left.png') no-repeat #ccc; } 
 
\t \t \t ul li a:after { background: url('right.png') no-repeat #ccc; } 
 
\t \t </style> 
 
\t </head> 
 
\t <body> 
 

 
\t \t <ul> 
 
\t \t \t <li><a href="#">aaa</a></li> 
 
\t \t \t <li><a href="#">aaa</a></li> 
 
\t \t \t <li><a href="#">aaa</a></li> 
 
\t \t </ul> 
 

 
\t </body> 
 
</html>