【问题标题】:CSS Problem : Center Text in a box with ImageCSS问题:在带有图像的框中居中文本
【发布时间】:2019-03-20 17:44:30
【问题描述】:

有人可以帮忙吗? 我正在努力让一些 CSS 代码正常工作。

我需要三个盒子;他们需要看起来像图片中的样子

但是当我运行我的代码时,文本总是在图像下方。

请谁能告诉我我做错了什么? :

https://codepen.io/arminx2/full/wYPxZe

</div><div style="margin-top: 16px; background: white; box-shadow: rgba(76, 76, 76, 0.25) -1px 1px 2px 1px; padding: 12px; height: 70px; border-radius: 2px; flex-direction: row; align-items: center; cursor: pointer; opacity: 1; transition: all 1s linear 0s;"><img src="http://relationshiphero.com/images/sageTeal.png" style="height: 32px; width: 32px; margin-right: 16px;"><div><div style="font-size: 12px; color: rgb(5, 26, 90); margin-bottom: 2px;">16% better value</div><div style="color: rgb(0, 112, 232); font-size: 14px; font-weight: bold;">Sage - 60 minutes</div></div><div style="margin-left: auto; margin-right: 8px; color: rgb(0, 112, 232);"><img src="/images/triangleRight.png" style="width: 16px; height: 16px;"></div></div><div style="margin-top: 16px; background: white; box-shadow: rgba(76, 76, 76, 0.25) -1px 1px 2px 1px; padding: 12px; height: 70px; border-radius: 2px; flex-direction: row; align-items: center; cursor: pointer; opacity: 1; transition: all 1s linear 0s;"><img src="http://relationshiphero.com/images/heroTeal.png" style="height: 32px; width: 32px; margin-right: 16px;"><div><div style="font-size: 12px; color: rgb(5, 26, 90); margin-bottom: 2px;">38% better value</div><div style="color: rgb(0, 112, 232); font-size: 14px; font-weight: bold;">Hero - 240 minutes</div></div><div style="margin-left: auto; margin-right: 8px; color: rgb(0, 112, 232);"><img src="http://relationshiphero.com/images/triangleRight.png" style="width: 16px; height: 16px;"></div></div></div></div><div class="rightSec"><div style="position: absolute; height: 450px; width: 341.8px; border-top-left-radius: 4px; border-bottom-left-radius: 4px; background-image: url(&quot;/images/home/howItWorks5.jpg&quot;); background-size: cover; background-position: center top;"></div></div></div></div>

我不确定我做错了什么。如果有人可以看看这个,我将不胜感激。

谢谢

【问题讨论】:

    标签: css image button center


    【解决方案1】:

    你需要给使用flexbox的元素添加display: flex;属性

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 2011-03-01
      • 2021-03-25
      • 2016-12-23
      相关资源
      最近更新 更多