身高和文字响应能力问题

发布于 2025-01-25 09:02:22 字数 1155 浏览 1 评论 0原文

我正在为客户的网站上工作,而我一直在研究的“头部英雄”部分响应迅速,除非我在调整高度时对文本的问题重叠。如何缩小文本或制作文本,以使其在其部分的流中?

HTML:

<header class="hero">
<div class="hero-text">
  <li><a href="#">Meet Us</a></li>
  <span> | </span>
  <li><a href="#">Join Us</a></li>
  <span> | </span>
  <li><a href="#">Contact</a></li>
</div>
</header>

CSS:

.hero {
  background-image: url('../image/people.jpg');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
  width: 100%;
  height: 90vh;
}

.hero-text {
  text-align: center;
  position: absolute;
  display: block;
  top: 65%;
  left: 0;
  right: 0;
  text-transform: uppercase;
}

.hero-text li {
  padding: 20px 0;
  margin: 0 auto;
}

.hero-text li a {
  color: white;
  padding: 5px;
  font-size: 1.5rem;
  border-bottom: 1px solid white;
  width: 50%;
}

span {
  display: none;
}

这是网站的屏幕截图: ScreenShot

I'm working on a website for a client and the head hero section I've been working on is responsive except I'm having issues with the text overlapping the section below it whenever adjusting the height. How can I shrink the text or make it so it's in the flow of its section?

HTML:

<header class="hero">
<div class="hero-text">
  <li><a href="#">Meet Us</a></li>
  <span> | </span>
  <li><a href="#">Join Us</a></li>
  <span> | </span>
  <li><a href="#">Contact</a></li>
</div>
</header>

CSS:

.hero {
  background-image: url('../image/people.jpg');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
  width: 100%;
  height: 90vh;
}

.hero-text {
  text-align: center;
  position: absolute;
  display: block;
  top: 65%;
  left: 0;
  right: 0;
  text-transform: uppercase;
}

.hero-text li {
  padding: 20px 0;
  margin: 0 auto;
}

.hero-text li a {
  color: white;
  padding: 5px;
  font-size: 1.5rem;
  border-bottom: 1px solid white;
  width: 50%;
}

span {
  display: none;
}

Here is a screenshot of the website:
Screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪恋 2025-02-01 09:02:22

您的代码存在一些语法问题(UL缺失,您应该始终在UL中使用LI标签。其重叠的原因是因为90VH是绝对位置的英雄文本的关系。我会做follwing:

.hero {
  background-image: url('https://picsum.photos/200');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  width: 100%;
  height: 90vh;
  display:flex;
  align-items:center;
  justify-content:center;
}

.divider {
  padding:0.5rem 0;
  display:none; /* THIS HAS CHANGED */
  width:1px;
  background-color:white;
  height:50px;
}

.hero-text {
  display:flex;
  flex-direction:column; /* THIS HAS CHANGED */
  align-items:center;
  text-transform: uppercase;
  list-style:none;
  gap:2rem;
}

.hero-text li a {
  color: white;
  text-decoration:none;
  padding: 5px;
  font-size: 1.5rem;
  border-bottom: 1px solid white;
  width: 50%;
}


/* THIS HAS CHANGED ABOVE ARE ALL MOBILE STYLES 
AND FOLLOWDING ARE THE DESKTOP ADJUSTMENTS in a min-width query */
@media (min-width: 768px) {

  .hero-text {
    flex-direction:row;
  }

  .divider {
    display: block;
  }
  
}
<header class="hero">
  <ul class="hero-text">
    <li><a href="#">Meet Us</a></li>
    <li><span class="divider"></span></li>
    <li><a href="#">Join Us</a></li>
    <li><span class="divider"></span></li>
    <li><a href="#">Contact</a></li>
  </ul>
</header>

Your Code has some syntax issues (ul missing and you should always use only li tags in your ul. The reason why its overlapping is because of the 90vh which is the relation for the absolute positioned hero text. I would do follwing:

.hero {
  background-image: url('https://picsum.photos/200');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  width: 100%;
  height: 90vh;
  display:flex;
  align-items:center;
  justify-content:center;
}

.divider {
  padding:0.5rem 0;
  display:none; /* THIS HAS CHANGED */
  width:1px;
  background-color:white;
  height:50px;
}

.hero-text {
  display:flex;
  flex-direction:column; /* THIS HAS CHANGED */
  align-items:center;
  text-transform: uppercase;
  list-style:none;
  gap:2rem;
}

.hero-text li a {
  color: white;
  text-decoration:none;
  padding: 5px;
  font-size: 1.5rem;
  border-bottom: 1px solid white;
  width: 50%;
}


/* THIS HAS CHANGED ABOVE ARE ALL MOBILE STYLES 
AND FOLLOWDING ARE THE DESKTOP ADJUSTMENTS in a min-width query */
@media (min-width: 768px) {

  .hero-text {
    flex-direction:row;
  }

  .divider {
    display: block;
  }
  
}
<header class="hero">
  <ul class="hero-text">
    <li><a href="#">Meet Us</a></li>
    <li><span class="divider"></span></li>
    <li><a href="#">Join Us</a></li>
    <li><span class="divider"></span></li>
    <li><a href="#">Contact</a></li>
  </ul>
</header>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文