【问题标题】:H1 tag border length possible? [duplicate]H1标签边框长度可能吗? [复制]
【发布时间】:2016-01-20 15:39:53
【问题描述】:

我在我添加文本的地方制作了一个全宽图像。 很长一段时间以来,我一直在挠头。 我正在尝试找到添加上下边框文本的最佳解决方案。

但是,我希望边框的长度只有一半或更短,但我就是想不通。

在标记类之前,我尝试在文本容器 div 上使用边框,但在将文本居中和对齐时遇到了问题。

现在是这样的:

CSS:

.adcontainer {
  position: relative;
  width: 100%;
  height: auto;
}
.adcontainer img {
  width: 100%;
  height: auto;
}
.adcontainertext {
  position: absolute;
  top: 25%;
  left: 15%;
  z-index: 0;
  padding: 0;
  padding: 1.2em;
  font-size: .5em;
  text-align: center;
}


.advertheading
{
    font-size: 20px;
    border-bottom: 1px solid white;
    border-top: 1px solid white;
    line-height: 100px;
    display:inline-block

}

HTML:

<div style="clear: both;">
<div class="adcontainer"><img src="https://cdn.shopify.com/s/files/1/0786/5107/files/LARGE_BANNER-BELOW.jpg?5938182738858039286" />
<div class="adcontainertext">
<h2 class="advertheading" style="font-weight: normal; color: #ffffff;">Join the club</h2>
</div>
</div>
</div>

最好的问候, 罗宾。

【问题讨论】:

    标签: html css tags border


    【解决方案1】:

    .adcontainer {
      position: relative;
      width: 100%;
      height: auto;
    }
    .adcontainer img {
      width: 100%;
      height: auto;
    }
    .adcontainertext {
      position: absolute;
      top: 25%;
      left: 15%;
      z-index: 0;
      padding: 0;
      padding: 1.2em;
      font-size: .5em;
      text-align: center;
    }
    
    .adcontainertext h2:before {
      content: '';
      border-top: 1px solid #FFF;
      position: absolute;
      width: 50%;
      left: 25%;
      top: 0;
    }
    
    .advertheading {
      font-size: 20px;
      line-height: 100px;
      display:inline-block;
      position: relative;
    }
    
    .adcontainertext h2:after {
      content: '';
      border-bottom: 1px solid #FFF;
      position: absolute;
      width: 50%;
      left: 25%;
      bottom: 0;
    }
    <div style="clear: both;">
      <div class="adcontainer">
        <img src="https://cdn.shopify.com/s/files/1/0786/5107/files/LARGE_BANNER-BELOW.jpg?5938182738858039286" />
        
        <div class="adcontainertext">
          <h2 class="advertheading" style="font-weight: normal; color: #ffffff;">Join the club</h2>
        </div>
      </div>
    </div>

    【讨论】:

    • 像魅力一样工作。甚至不知道之前和之后会起作用。再次,非常感谢。非常感激!最好的问候。
    • 没问题,一个upvote会很受欢迎:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 2021-11-04
    • 1970-01-01
    • 2023-03-21
    • 2020-11-01
    • 1970-01-01
    • 2011-09-08
    相关资源
    最近更新 更多