工具提示DIV上的CSS箭头

时间:2017-01-30 22:54:36

标签: css tooltip css-shapes

我正在尝试在矩形工具提示div的每一侧添加居中箭头/三角形,我尝试应用其他问题和演示中的一些代码,但没有一个看起来居中或箭头的阴影与div。箭头应为白色,阴影为0 0 20px 0 rgba(0, 0, 0, 0.2);

HTML:

<div class="tooltip cal-tooltip">
 <div class="tooltip cal-tooltip">
  <div class="cal-tooltip-cont">
    <div class="cal-tooltip-img four-three-img">
      <img src="http://placeholdit.imgix.net/~text?txtsize=75&txt=Event%20Photo&w=600&h=400" />
    </div>
    <div class="card-info">
      <h2>Wrapping related content title</h2>
      <h3>Event date</h3>
      <h3>Event venue</h3>
    </div>
  </div>
</div>

CSS:

.tooltip {
  position: absolute;
  top: 0;
  z-index: 1;
  background-color: white;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2);
}
.tooltip > div {
  padding: 15px;
}
.tooltip > div img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cal-tooltip {
  width: 20em;
  cursor: auto;
}
.cal-tooltip .cal-tooltip-cont {
  display: flex;
}
.cal-tooltip .cal-tooltip-cont > div {
  flex-basis: 50%;
}
.cal-tooltip .cal-tooltip-cont > div:nth-child(1) {
  padding-right: 5px;
}
.cal-tooltip .cal-tooltip-cont > div:nth-child(2) {
  padding-left: 5px;
}
.cal-tooltip .cal-tooltip-cont > div h2 {
  padding-bottom: 5px;
  font-size: 1em;
}
.cal-tooltip .cal-tooltip-cont > div h3 {
  font-size: .85em;
}

演示:http://codepen.io/ourcore/pen/Lxeapj

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

&#13;
&#13;
.tooltip {
  position: absolute;
  top: 20px;
  left: 60px;
  z-index: 1;
  background-color: #fff;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, .2);
  width: 17em;
  padding: 15px;
}

.tooltip:after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  margin-left: -1em;
  margin-top: -1em;
  left: 100%; /* change to 0% for left arrow */
  top: 50%;
  box-sizing: border-box;
  border: 1em solid black;
  border-color: transparent transparent #fff #fff;
  transform-origin: 50% 50%;
  transform: rotate(-135deg); /* change to 45 deg for left arrow */
  box-shadow: -5px 5px 10px 0 rgba(0, 0, 0, 0.1);  
}

.card {
  display: flex;  
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card > div {
  flex-basis: 50%;  
}

.card-info {
  padding-left: 15px;  
}
&#13;
<div class="tooltip">
  <div class="card">
    <div class="card-image">
      <img src="http://placeholdit.imgix.net/~text?txtsize=75&txt=Event%20Photo&w=600&h=400" />
    </div>
    <div class="card-info">
      <h2>Test title</h2>
      <h3>Event date</h3>
      <h3>Event venue</h3>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

灵感来自:https://codepen.io/ryanmcnz/pen/JDLhu

至少这是一个开始。希望它有所帮助!

相关问题