【问题标题】:CSS arrow on tooltip DIV工具提示 DIV 上的 CSS 箭头
【发布时间】:2017-06-16 06:10:50
【问题描述】:

我正在尝试在矩形工具提示 div 的每一侧添加一个居中的箭头/三角形,并且我尝试应用其他问题和演示中的一些代码,但没有一个看起来居中或箭头的阴影与 @987654324 重叠@。箭头应该是带有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

【问题讨论】:

标签: css tooltip css-shapes


【解决方案1】:

试试这样的:

.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;  
}
<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>

受此启发:https://codepen.io/ryanmcnz/pen/JDLhu

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

【讨论】:

  • 肯定会。谢谢!
猜你喜欢
  • 2015-06-24
  • 1970-01-01
  • 2019-08-10
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 2017-02-05
  • 1970-01-01
  • 2023-04-06
相关资源
最近更新 更多