媒体查询和响应式网站问题

问题描述 投票:0回答:1

当我尝试使用最大宽度为 400 px 的 CSS 使网站响应时,所有元素或所有 body 都会移至左侧,并且我无法将其放在页面中间,我该怎么办解决这个问题吗?

我的结果:

My result

这是关于一个部分的代码,但问题适用于所有部分

.hero-section {
  width: 80%;
  margin: 50px auto;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 50px;
  gap: 50px;
  background-color: #fe796719;
  border-radius: 20px;
}

.hero-section .left h1 {
  font-family: Fraunces;
  letter-spacing: 0.5px;
  text-transform: capitalize;
  font-size: 45px;
  margin-bottom: 40px;
}

.hero-section .left h1 span {
  color: #ef5e41;
}

.hero-section .left p {
  font-size: 20px;
  line-height: 1.5;
}

.hero-section .left a {
  display: inline-block;
  font-size: 30px;
  font-family: fraunces;
  padding: 15px 25px;
  margin: 50px auto;
  cursor: pointer;
  background-color: #ef5e41;
  border-radius: 30px;
  border: none;
  color: #fff;
}

@media screen and (max-width:400px) {
  .hero-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .hero-section .left {
    text-align: center;
  }
  .hero-section .left h1 {
    font-size: 30px;
    margin-bottom: 20px;
  }
  .hero-section .left p {
    color: black;
    line-height: 1.5;
    font-size: 18px;
  }
  .hero-section .left a {
    font-size: 25px;
  }
}
<div class="hero-section">
  <div class="left">
    <h1>Small crowd but seek <strong>big IMPAKT</strong> ? <br /><span>we got you !!!</span></h1>
    <p>With our expert team your brand is our N1 priority. <br />When you pick us you pick thriving, bc your success is ours too, so let us walk you there with a free consultation.</p>
    <a href="#">Request Concultation</a>
  </div>
  <div class="right">
    <img src="images/Hero.png" alt="Marketing" />
  </div>
</div>

我尝试将宽度设置为 100%,但没有任何改变。 将主体从其位置移动的唯一方法是给它一个“左边距”或给它一个特定的宽度,例如 700 像素。因为看起来当我将媒体查询的最大宽度设置为 400px 时,正文也采用相同的宽度。

html css media-queries
1个回答
0
投票
	
© www.soinside.com 2019 - 2024. All rights reserved.