根據不同的內容以不同的方式處理溢出

我的最終目標是讓按鈕懸停時的語音氣泡出現在頁面的最高z-index/layer處。該按鈕將是div中具有max-height限制的較大文本內容的一部分。

有時,文本內容可能會溢出這個max-height限制,理想情況下,我希望創建一個滾動條,這樣內容仍然可以整齊地放在父div中。但是,當文本內容不適合時,我希望建立一個滾動欄,以免內容溢出父div。

我的問題就從這里開始

overflow-y: scroll屬性添加到父div以處理長文本內容的邊緣情況,會將氣泡推到div層下,并自動創建x-axis scroll.I想要的y-axis滾動條沒有x-axis滾動條,并強制懸停時的氣泡顯示在頂部,即使文本內容較長。

下面是更好地描述我的問題的代碼筆。從.demo元素中刪除overflow-y: scroll正是我想要的,除非內容對于父div限制來說太大。。。

? 最佳回答:

display: none;代替opacity: 0,所以:before只在:hover上。這將使工具提示顯示時只有overflow-x: scroll;。

html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  margin: 64px auto;
  text-align: center;
  max-width: 640px;
  width: 94%;
  background-repeat: no-repeat;
  height: 100vh;
  background-color: #8bc6ec;
  background-image: linear-gradient(135deg, #8bc6ec 0%, #9599e2 100%);
}

.demo {
  background-color: white;
  padding: 2rem;
  border-radius: 0.5rem;
  max-height: 400px;
  overflow-y: scroll;
}

.demo,
.demo p {
  margin: 4em 0;
  text-align: center;
}

.button {
  background-color: #ea4c89;
  border-radius: 8px;
  border-style: none;
  box-sizing: border-box;
  color: #ffffff;
  cursor: pointer;
  display: inline-block;
  font-family: "Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: 500;
  height: 40px;
  line-height: 20px;
  list-style: none;
  margin: 0;
  outline: none;
  padding: 10px 16px;
  position: relative;
  text-align: center;
  text-decoration: none;
  transition: color 100ms;
  vertical-align: baseline;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.button:hover,
.button:focus {
  background-color: #f082ac;
}


/**
 * Tooltip Styles
 */


/* Add this attribute to the element that needs a tooltip */

[data-tooltip] {
  position: relative;
  z-index: 2;
  cursor: pointer;
}


/* Hide the tooltip content by default */

[data-tooltip]:before,
[data-tooltip]:after {
  visibility: hidden;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: progid: DXImageTransform.Microsoft.Alpha(Opacity=0);
  display: none;
  pointer-events: none;
}


/* Position tooltip above the element */

[data-tooltip]:before {
  content: attr(data-tooltip);
  background-color: white;
  color: black;
  position: absolute;
  width: max-content;
  border: solid black 1.5px;
  padding: 5px 10px;
  border-radius: 10px;
  left: 102%;
  top: 115%;
}


/* Show tooltip content on hover */

[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
  visibility: visible;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  filter: progid: DXImageTransform.Microsoft.Alpha(Opacity=100);
  display: block;
}
<div class="demo">

  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum
    is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model
    text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where does it come from? Contrary to
    popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the
    more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum"
    (The Extrem<button class="button" data-tooltip="I’m the tooltip text on the right of the button that extends out pretty far">I’m a button with a tooltip</button></p>
</div>

主站蜘蛛池模板: chinese国产一区二区| 中文字幕一区二区三区精彩视频| 国产乱码一区二区三区四| 亚洲国产精品乱码一区二区| 午夜精品一区二区三区免费视频| 国产综合无码一区二区色蜜蜜| 日韩动漫av在线播放一区| 亚洲一区精彩视频| 中文字幕人妻丝袜乱一区三区| 亚洲国产激情一区二区三区 | 精品国产区一区二区三区在线观看| 精品国产免费一区二区三区| 韩国精品一区二区三区无码视频| 无码精品国产一区二区三区免费| 日本精品一区二区三区视频| 日韩一区二区三区射精 | 91一区二区视频| 国产乱人伦精品一区二区在线观看| 无码人妻精品一区二区三区99不卡| 国产乱码精品一区二区三区香蕉| 91午夜精品亚洲一区二区三区| 伊人激情AV一区二区三区| 国产无码一区二区在线| 日韩一区二区三区在线精品| 婷婷亚洲综合一区二区| 日韩AV无码一区二区三区不卡| 国产日韩精品视频一区二区三区 | 日韩伦理一区二区| 国产乱码精品一区二区三区中文 | 国产精品一区12p| 亚洲日本久久一区二区va| 亚洲熟女一区二区三区| 中文字幕日韩一区二区三区不| 欧洲精品一区二区三区在线观看| 日韩美一区二区三区| 国产一区在线电影| 国产AⅤ精品一区二区三区久久| 激情内射亚州一区二区三区爱妻| 丝袜人妻一区二区三区网站| 国产成人精品一区二区三区免费 | 精品国产毛片一区二区无码|