CSS :before visible when overflow hidden

标签 css overflow

之前可以显示一些东西吗?什么时候 overflow hidden ?或者我们可以指定 side 将被隐藏以防止溢出吗? 例如:

.before {
  width: 200px;
  margin: 30px;
  background-color: blue;
  height: 30px;
  position: relative;
}

.before:before {
  content: "221";
  color: blue;
  font-size: 15px;
  display: inline-block;
  position: absolute;
  left: -20px;
  top: -20px;
}

#ex2 {
  overflow: hidden;
}
<div id='ex1' class='before'>Wisible text with css before, more text, more and more... but </div>
<div id='ex2' class='before'>hidden overflow text with css before... more and more text</div>

最佳答案

如果您将某个元素声明为 overflow:hidden ,它将应用于所有内容,包括 beforeafter 元素。无法禁用特定子项的隐藏值。

考虑将您的内容包装在具有其父级的最大宽度和高度的 div 中,并在该 div 上设置 oveflow: hide。根元素的 beforeafter 伪元素将存在于包装器外部,因此不会受到影响。

.before {
  width: 200px;
  margin: 30px;
  background-color: blue;
  height: 30px;
  position: relative;
}

.before:before {
  content: "221";
  color: blue;
  font-size: 15px;
  display: inline-block;
  position: absolute;
  left: -20px;
  top: -20px;
}

#ex2 > .wrapper {
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
}
<div id='ex1' class='before'><div class="wrapper">Visible text with css before, more text, more and more... but </div></div>
<div id='ex2' class='before'><div class="wrapper">Hidden overflow text with css before... more and more text</div></div>

关于CSS :before visible when overflow hidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55423821/

相关文章:

javascript - 如何将鼠标事件添加到 div 集并从数据库表单单击 div 加载数据?

html - 为什么我的内容区域停在页脚之前?

c - C中堆栈溢出和无限次循环调用的区别

css - CSS中的*溢出是什么?

android - 溢出-x : hidden; not working on android devices

javascript - 谷歌地图导致其他元素溢出正文

css - 用作图像映射的图像突出显示 onclick

javascript - 脚本只会显示最后一个文本和最后一个颜色,但会按照指示进行动画处理,这是怎么回事?

css - Android 设备的媒体查询

html - 如何防止绝对定位的元素影响滚动条?