当其父容器具有滚动条时,如何使工具提示可见?

时间:2019-04-05 11:49:36

标签: css

我在div上附加了一个箭头。当此div内容超过其最大高度时,将向其中添加一个滚动条。这样一来,附加在div顶部的箭头就变得不可见了。

即使添加滚动条,如何确保箭头可见。

下面是代码,

.first_div {
  z-index: 1;
  display: flex;
  width: 100%;
  height: 48px;
  padding: 0 12px 0 12px;
  background-color: yellow;
  align-items: center;
}

.drawer {
  display: flex;
  flex-direction: column;
  background-color: yellow;
  position: absolute;
  width: 320px;
  top: 55px;
  right: 22px;
  min-height: 40%;
  max-height: 80%;
  overflow: scroll;
  overflow-x: hidden;
}

.drawer header {
  min-height: 38px;
  border-bottom: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 0px;
  padding-top: 2px;
}

.drawer:after {
  content: "";
  position: absolute;
  bottom: 100%;
  right: 9%;
  margin-left: -5px;
  border-width: 9px;
  border-style: solid;
  border-color: transparent transparent red transparent;
}
<div>
  <div class="first_div">
    <div class="drawer">
      <header>title</header>
      <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
        <li>four</li>
        <li>five</li>
        <li>one</li>
        <li>two</li>
        <li>three</li>
      </ul>
    </div>
  </div>

1 个答案:

答案 0 :(得分:-1)

您需要将:after添加到header并将滚动条添加到ul

我对您的CSS代码进行了一些更改:

这是更新的小提琴:

.first_div {
  z-index: 1;
  display: flex;
  width: 100%;
  height: 48px;
  padding: 0 12px 0 12px;
  background-color: yellow;
  align-items: center;
}

.drawer {
  display: flex;
  flex-direction: column;
  background-color: yellow;
  position: absolute;
  width: 320px;
  top: 55px;
  right: 22px;
  min-height: 40%;
  max-height: 80%;
}

.drawer ul {
  overflow: scroll;
  overflow-x: hidden;
}

.drawer header {
  min-height: 38px;
  border-bottom: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 0px;
  padding-top: 2px;
}

header:after {
  content: "";
  position: absolute;
  top: 0;
  right: 9%;
  margin-left: -5px;
  border-width: 9px;
  border-style: solid;
  border-color: transparent transparent red transparent;
  z-index: 9999999;
}
<div>
  <div class="first_div">
    <div class="drawer">
      <header>title</header>
      <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
        <li>four</li>
        <li>five</li>
        <li>one</li>
        <li>two</li>
        <li>three</li>
        <li>one</li>
        <li>two</li>
        <li>three</li>
        <li>four</li>
        <li>five</li>
        <li>one</li>
        <li>two</li>
        <li>three</li>
      </ul>
    </div>
  </div>