简体   繁体   中英

Flex items not wrapping with flex-wrap: wrap applied

I'm attempting to place a flex-wrap on my site through a media query of 700px, with this being the only section where it's not working. Not sure if it's me being an idiot, but can anyone see an obvious solution to what I should be applying flex-wraps and flex properties too in my code for the proposition container to wrap on top of the image?

Seems to me it should be:

hero-content-container = flex-wrap: wrap;
hero-proposition-container = flex: 0 0 300px;
hero-image-container = flex: 0 0 300px;

But it's not working. I've also tried adding it a level deeper, so proposition and image with flex-wraps, and their children having flex: 0 0 300px.

HTML:

  <section class="hero-section">
    <div class="hero-container">
      <div class="hero-content-container">
        <div class="hero-proposition-container">
          <h1 class="hero-heading">Welcome (title)</h1>
          <p class="hero-paragraph">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
            nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
            culpa qui officia deserunt mollit anim id est laborum.</p>
          <button type="button" name="button">
            <a href="search-page.html" style="text-decoration: none">This button opens the search page</a>
          </button>
        </div>
      </div>
      <div class="hero-image-container">
        <div class="hero-image-box">
          <h1>Hero picture here</h1>
        </div>
      </div>
    </div>
  </section>

CSS:

.hero-section {
  height: 700px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-container {
  height: 600px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.hero-content-container {
  height: 500px;
  width: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-image-container {
  height: 500px;
  width: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-image-box {
  height: 500px;
  width: 100%;
  border: 3px solid #363636;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-proposition-container button {
  background-color: #f3c623;
  height: 50px;
  width: 300px;
}

.hero-proposition-container a {
  color: #363636;
  font-size: 16px;
}

Thanks.

The .hero-content-container , which you indicate has flex-wrap: wrap , has only one child ( .hero-proposition-container ). With only one child, there is nothing to wrap.

I've also tried adding it a level deeper...

Try going a level higher.

Add flex-wrap: wrap to .hero-container .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM