【问题标题】:Overflow hidden for a heading tag not working on mobile browsers, Chrome and Safari. Only works on desktop browsers在移动浏览器、Chrome 和 Safari 上不工作的标题标签隐藏溢出。仅适用于桌面浏览器
【发布时间】:2020-06-10 19:55:49
【问题描述】:

screenshots of desktop working vs. mobile not working

我有一个代码 sn-p 来显示我正在尝试做的事情。我故意为包含幻灯片的 div 内的标题设置了更宽的宽度。我希望标题的宽度被图像的圆形边缘剪裁。我在桌面浏览器上有类似的工作,但它不会在我的 iphone 上的 Safari 或 Chrome 中呈现。我已经设置了溢出:隐藏到父 div,它确实像我想要的那样隐藏了标题的外部部分。但我无法让它在移动设备上正确呈现。 (注意:overflow hidden 将所有内容都隐藏在了 sn-p 中,我也不确定那里发生了什么)。

我研究过类似的问题,但这些问题似乎是在处理有关整个页面正文的溢出问题。

div {
   position: relative;
   /* overflow: hidden; */
}
h3 {
   margin: 0;
   z-index: 4;
   width: 300px;
   height: 20px;
   position: absolute;
	/* top: 150px; */
	bottom: 0;
	left: 0;
	right: 0;
  background-color: yellow;
  text-align: center;
}
img {
   position: absolute;
   top: 0;
   left: 0;
   z-index: 3;
   animation: slideshow 12s linear 0s infinite;
   border-radius: 25px;
}

img:nth-child(2) {
   z-index: 2;
   animation-delay: 4s;
}

img:nth-child(3) {
   z-index: 1;
   animation-delay: 8s;
}

@keyframes slideshow {
   25% {
      opacity: 1;
   }
   33.33% {
      opacity: 0;
   }
   91.66% {
      opacity: 0;
   }
   100% {
      opacity: 1;
   }
}
<div>
<h3>Slideshow</h3>
<img src="http://dummyimage.com/280x200/56AD30/fff.png&text=1" />
<img src="http://dummyimage.com/280x200/1560f0/fff.png&text=2" />
<img src="http://dummyimage.com/280x200/C03229/fff.png&text=3" />
</div>

【问题讨论】:

    标签: html css overflow hidden


    【解决方案1】:

    我现在看到您添加了图像。你有一个保证金问题。 h3 元素添加边距。如果您在 h3 样式中添加 'margin: 0',您将看到会发生什么。还有一件事,你需要删除'top:150px;'。 下次你必须放一些工作代码。在您添加的示例中,您看不到任何东西,至少您向主 div 添加了一个高度值。

    【讨论】:

    • 你建议我在哪里添加高度值?我发布了一个编辑,其中包含在我的桌面和移动设备上工作的溢出屏幕截图
    • 我听从了您的建议,但该标题需要位于图像的底部。我也隐藏了溢出,只是为了让你能看到一些东西。但我需要该标题被图像剪裁。
    猜你喜欢
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    相关资源
    最近更新 更多