html - 绝对定位在wordpress中不起作用

标签 html css

我试图让这段文字进入图片。出于某种原因,当我将它添加到 WordPress 时它不起作用。似乎在我附在下面的 JS fiddle 中工作正常。任何帮助将不胜感激。 Screenshot of what's happening on WP

https://jsfiddle.net/tdh3euue/

<div class="outer-wrapper">

<img class="aligncenter wp-image-1015" 
src="https://www.thesurebettor.com/wp-content/uploads/2017/05/what-is-
matched-betting-1.jpg" alt="" width="750" height="431" />
<div class="text-wrapper"><p>What is matched</p><p>betting?</p>

</div>
</div>

.outer-wrapper {
position: relative;
}

.text-wrapper {
 position: absolute;
 left: 35px;
 top: 35px;
 color: white;
 font-size: 52px;
 font-weight: bold;  
}

最佳答案

从你的图片来看,我认为你的中心对齐到外包装,这就是文本移动的原因。

我在这里使用 left: calc((100% - 750px)/2 + 35px); 因为你的 img 宽度固定为 750px,所以我使用那个 calc 将正确的左边设置为 35px img 的左边缘。

同时使用 @media (max-width: 750px) 如果屏幕小于 750px,calc 将返回小于 35px 的值,我们不希望这样,这个媒体如果屏幕宽度小于 750px,查询将帮助您将左边设置为 35px。

.outer-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.text-wrapper {
  position: absolute;
  left: calc((100% - 750px)/2 + 35px);
  top: 10px;
  color: white;
  font-size: 52px;
  font-weight: bold;
}

@media (max-width: 750px) {
  .text-wrapper {
    left: 35px;
  }
}
<div class="outer-wrapper">

  <img class="aligncenter wp-image-1015" src="https://www.thesurebettor.com/wp-content/uploads/2017/05/what-is-matched-betting-1.jpg" alt="" width="750" height="431" />
  <div class="text-wrapper">
    <p>What is matched</p>
    <p>betting?</p>

  </div>
</div>

关于html - 绝对定位在wordpress中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44079838/

相关文章:

Javascript FileReader onload 未触发

php - 是否可以关闭 </ul> 并在循环中添加新的 <ul> ?

HTML/CSS 导航不向下推 : After responsive display not displaying full height and scroll

cross-browser - 不同浏览器的盒子阴影颜色不同?

javascript - UL 标签(来自 wysihtml5 javascript)不水平对齐

javascript - 光滑的 slider 不工作

html - 更正 XPath 查询以获取 div 内部文本

html - iphone safari 不显示滚动条

javascript - ajax 调用的纬度和经度 - Html5

css 大师 : how to swap too spans (inline-block, 没有固定宽度)?