效果圖:
爲了便於區別,我們將那個三角形繪製成了紅色,顯示框繪製成了橙黃色。
- 做出上面三個元素:問號及其圓圈、三角形和長方形提示框
- 設置三角形及長方形提示框不可見
- 設置鼠標經過問號時顯示提示框
- hover
- before
p:before{
content:'添加的內容'
}
p{width:20px; height:20px; background-color:green;}
它顯示出來的是一個邊長爲20px的正方形p{width:20px; height:20px; background-color:green; border-radius:50%; text-align:center; }
p:before{content:'?'; color:orange; font-weight: bold;}
p:before{
content:'';
border: 10px solid transparent;
border-bottom-color:#F3252D;
}
box-shadow:10px 20px 15px rgba(4,235,4,0.2);
<div class="tips">
<p>提示信息的內容</p>
</div>
.tips{
width:20px;
height:20px;
border-radius:50%;
background-color:green;
text-align:center;
}
.tips:before{
content:'?';
font-weight:bold;
color:red;
}
/*注:以上就是剛剛說的那個圓及它中間的問號*/
/*注:下面繪製長方形內容顯示框,並使它不顯示*/
.tips p{
display : none; /*剛開始時隱藏*/
width : 300px;
padding : 20px; /*此處使用padding而不用height,想想有何區別*/
border-radius : 5px; /*圓角*/
background-color : #fbcc7d; /*背景色*/
color : #000; /*文字顏色*/
box-shadow : 1px 1px 1px rgba(0,0,0,0.2); /*陰影*/
position : absolute; /*固定位置,不然會撐開頁面*/
left : auto; /*邊框起始位置*/
margin-top : 8px; /*邊框距離頂部8px,這是因爲要在它上面加上一個三角形,8px是那個三角形的邊長*/
text-align : left; /*文字居左*/
}
/*注:下面給內容框添加一個三角形*/
.tips p:before{
content : '';
border : 8px solid transparent;
border-bottom-color : #F3252D;
position : absolute; /*位置固定*/
left : 5px; /*三角形與內容框的相對位置*/
top : -16px; /*使它在P元素的上面16px處(這16px就是三角形的邊長的兩倍)*/
}
/*給問號添加hover屬性*/
.tips:hover p{
display : block;
}
至此,提示框就完成了。