Text over picture can only be in one word. When it@s two words or more, the second word drop down and slightly overlaps the first word

huangapple go评论60阅读模式
英文:

Text over picture can only be in one word. When it@s two words or more, the second word drop down and slightly overlaps the first word

问题

I have a picture as a background and a h2 header above the picture. But I cant have headings with more than one word without the second word dropping down.

不明白为什么会这样,以及如何修复它。

Text over picture can only be in one word. When it@s two words or more, the second word drop down and slightly overlaps the first word

#forsidebilde {
  width: 100%;
  height: auto;
}

#showcasetittel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  min-height: 300px;
  font-size: 5em;
  z-index: 1;
}
<div class="showcase">
  <img id="forsidebilde" src="bilder/forsidebilde.jpg" alt="Bilde av fjell og fjord.">
  <h2 id="showcasetittel">Velkommen</h2>
</div>
<section id="main">
英文:

I have a picture as a background and a h2 header above the picture. But I cant have headings with more than one word without the second word dropping down.

Not sure why it does this and how to fix it.

Text over picture can only be in one word. When it@s two words or more, the second word drop down and slightly overlaps the first word

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

#forsidebilde {
  width: 100%;
  height: auto;
}

#showcasetittel {
  position: absolute;
  top: 50‰;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  min-height: 300px;
  font-size: 5em;
  z-index: 1;
}

<!-- language: lang-html -->

&lt;div class=&quot;showcase&quot;&gt;
  &lt;img id=&quot;forsidebilde&quot; src=&quot;bilder/forsidebilde.jpg&quot; alt=&quot;Bilde av fjell og     fjord.&quot;&gt;
  &lt;h2 id=&quot;showcasetittel&quot;&gt;Velkommen&lt;/h2&gt;
&lt;/div&gt;
&lt;section id=&quot;main&quot;&gt;

<!-- end snippet -->

答案1

得分: 0

使用浏览器的检查元素工具,您应该能够看到您的h2的宽度。我有一种感觉,它会强制换行,因为元素无法扩展以容纳一行文字,所以它在空格处断开。您可以尝试在h2单词之间使用&nbsp;特殊字符代码,以防止它换行到两行。

我认为文本重叠的原因是因为行高属性小于文本的高度。尝试使用不同的行高进行实验,看看是否有帮助。

英文:

Using your browser's Inspect Element tool, you should be able to see the width of your h2. I have the feeling it's forcing a line break because the element isn't able to expand to contain the text on one line, so it breaks the line at the space. You might be able to use the &amp;nbsp; special character code between the h2 words to prevent it from breaking onto two lines.

The reason the text is overlapping is, I believe, because the line-height property is less than the height of the text. Try experimenting with different line heights to see if that helps.

huangapple
  • 本文由 发表于 2023年4月13日 18:28:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定