【问题标题】:Align text over the image在图像上对齐文本
【发布时间】:2017-03-15 17:17:47
【问题描述】:

我需要在图像上对齐标题文本。

到目前为止,由于我使用了相对定位、绝对定位和z-index 的组合,它可以正常工作,但是我需要根据页面中的内容在特定位置对齐标题文本。

.container 是引导类。
我页面中的内容也在容器类中+,而且它有自己的类.article-view。本课分为.left-side(25%).right-side(75%)

我需要将标题文本 (.article-heading) 与内容类 .right-side 的水平位置对齐。

使用此代码,我只能在容器左侧获取标题文本

非常感谢您的任何帮助回答! :)

我的 HTML:

.article-banner {
  width: 100%;
  float: left;
  position: relative;
}
img {
  width: 100%;
  height: 350px;
  object-fit: cover;
}
.article-heading {
  color: #fff;
  position: absolute;
  z-index: 10;
  float: left;
  width: 35%;
  top: 15%;
  margin-left: 0;
  padding: 15px;
  background-color: rgba(189, 189, 189, 0.4);
}
span {
  text-transform: uppercase!important;
}
h1 {
  font-weight: 100;
}
.article-view {
  width:100%;
  float:left;
  background:#fff;
  border-radius:10px;
  padding:20px 25px;
  margin-bottom:60px;
  margin-top:20px;
}
.left-side {
  width:25%;
  float:left;
  padding-right:30px;
  padding-left:10px;
  margin-top:30px;
}
.right-side {
  width:75%;
  float:left;
  padding-left:40px;
  padding-right:15px;
  font-size:16px;
  line-height:26px;
  min-height:420px;
  margin-top:10px;
  position:relative;
}
<div class="article-banner">
  <div class="container">
    <div class="article-heading">
      <span>october 2015</span>
      <h1>Heading text</h1>
    </div>
  </div>
  <img src="img.png">
</div>

【问题讨论】:

  • 你能给我们任何你想要的输出截图吗?
  • "...这个类分为..." - 在哪里以及如何?

标签: html css position


【解决方案1】:

试试这个:-

.image { 
   position: relative; 
   width: 100%; /* for IE 6 */
}

h2 { 
   position: absolute; 
   top: 200px; 
 
   width: 100%; 
  text-align:center;
}
<div class="image">

      <img src="http://keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg" alt="" />
      
      <h2>A Movie in the Park:<br />Kung Fu Panda</h2>

</div>
要么

.article-banner {
  width: 100%;
  float: left;
  position: relative;
}
img {
  width: 100%;
  height: 350px;
  object-fit: cover;
}
.article-heading {
  color: #fff;
  position: absolute;
  z-index: 10;
  float: left;
  width: 35%;
  top: 15%;
  margin-left: 0;
  padding: 15px;
  background-color: rgba(189, 189, 189, 0.4);
}
span {
  text-transform: uppercase!important;
}
h1 {
  font-weight: 100;
}
.article-view {
  width:100%;
  float:left;
  background:#fff;
  border-radius:10px;
  padding:20px 25px;
  margin-bottom:60px;
  margin-top:20px;
}
.left-side {
  width:25%;
  float:left;
  padding-right:30px;
  padding-left:10px;
  margin-top:30px;
}
.right-side {
  width:75%;
  float:left;
  padding-left:40px;
  padding-right:15px;
  font-size:16px;
  line-height:26px;
  min-height:420px;
  margin-top:10px;
  position:relative;
}
<div class="article-banner">
  <div class="container">
    <div class="article-heading">
      <span>october 2015</span>
      <h1>Heading</h1>
    </div>
  </div>
  <img src="http://keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg">
</div>

【讨论】:

  • 对不起,现在我看到你的第二个被剪断了这就是我需要的,只是我需要将内容从左侧对齐 25%,让它在 div 的正上方,它有 75%
  • Oki 伙计们,最后,我找到了解决方案。我把容器放在绝对定位的 div 里面,在容器里面,我做了所有必要的定位。它正在工作。谢谢你的所有提示:)
猜你喜欢
  • 2022-10-05
  • 2014-08-14
  • 1970-01-01
  • 2012-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
相关资源
最近更新 更多