0

次のように、:after 疑似要素として矢印を使用した 4 方向のツールチップがあります: (JSFiddle を参照)

 <div class="background">
 <div class="tooltip tooltip-right">
     <i>i</i>
     <div><h4>Achtung!</h4>
         <p>Here is the info for section one</p></div> 
 </div>
.tooltip div {
    display:none;
    color:#000;
    border: 3px solid rgba(117, 175, 67, 0.4);
    background:#FFF;
    padding:15px;
    width: 250px;
    z-index: 99;
 }

.tooltip-right div {
    left: 180%;
    top: -80%;
}

.tooltip div:after {
    position:absolute;
    content: "";
    width: 0;
    height: 0;
    border-width: 10px;
    border-style: solid;
    border-color: #FFFFFF transparent transparent transparent;
    bottom:-20px;
}

.tooltip-right div:after {
    left:-20px;
    top:20px;
    border-color: transparent #FFFFFF transparent transparent;;
} 

このデモ hereのように、:before 疑似要素を使用して矢印に境界線を追加する方法を考え出そうとしていますが、さまざまな要素の矢印の方向を変更する方法がわかりません。矢印と境界線のある多方向ツールチップのデモへのリンクを提供したり、助けたりできますか?

4

1 に答える 1

2

基本的な原則は、:after疑似要素を使用して境界矢印を配置したら、疑似要素の上に別の少し小さい矢印を配置することです:before

スタッキングは z-index 値で行われます。

各矢印は、本来あるべき場所に応じて、絶対値 (およびいくつかの負のマージン) を使用して配置する必要があります。

境界線付きの上向き矢印の場合:

HTML

<div class="tooltip top">
  <p>Tooltip Text</p>
</div>

CSS

.tooltip {
  display:inline-block;
  vertical-align:top;
  height:50px;
  line-height:50px; /* as per div height */
  margin:25px;
  border:2px solid grey;
  width:250px;
  text-align:center;
  position:relative; /* positioning context */
}
.tooltip:before,
.tooltip:after { /*applies to all arrows */
  position:absolute;
  content:"";
}

.tooltip:after {
  /* the is going to be the extra border */
  border:12px solid transparent;
}

.tooltip:before {
 /* the is going to be the inside of the arrow */
  border:10px solid transparent; /* less than outside */ 
}

/* Lets do the top arrow first */

.top:after {
  /* positioning */
  left:50%;
  margin-left:-6px; /* 50% of border */
  top:-24px; /* 2x border */
  border-bottom-color:grey; /* as div border */
 }


.top:before {
  /* positioning */
  left:50%;
  margin-left:-5px; /* 50% of border */
  top:-20px; /* 2x border */
  border-bottom-color:white; /* as div background */
  z-index:5; /* put it on top */
}

添付の矢印 (TRBL) (いくつかの小さなコメント付き) を完成させました...

コードペンの例

于 2013-10-22T12:22:00.807 に答える