Unable to create a web layout design

Viewed 47

I am unable to create a web layout I am using only HTML and CSS . Kindly help me out here

my code :

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

section {
  min-height: 100vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fddcc356;
}

.container {
  width: 90%;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.img_part {
  width: 40%;
  height: 250px;
  background: url(images/hat.jpg) no-repeat center/cover;
  border-radius: 8px;
  position: relative;
}

.text_part {
  width: 50%;
  min-height: 550px;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  border-radius: 8px;
  color: white;
  margin-left: -20px;
}

.text_part h1 {
  font-size: 40px;
  font-weight: lighter;
}

.text_part p {
  margin: 20px 0;
  line-height: 25px;
  font-weight: 500;
}

.text_part a {
  text-decoration: none;
  color: black;
  padding: 20px 30px;
  letter-spacing: 2px;
  display: inline-block;
  text-transform: uppercase;
  background-color: white;
  position: absolute;
}

.behind_part {
  min-width: 25%;
  min-height: 100px;
  background-color: brown;
  position: absolute;
  border: 2px solid red;
  margin-right: 350px;
  margin-top: -350px;
}
<section>
  <div class="container">
    <div class="img_part"></div>
    <div class="text_part">
      <div class="content">
        <h1>French girl</h1>
        <h1>Summer Outfit</h1>
        <p>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.
        </p>
        <a href="#" class="btn">Learn More</a>

      </div>
    </div>
    <div class="behind_part"></div>

  </div>
</section>

My Output : enter image description here

The actual output: enter image description here

Problem: The main problem here is that I cannot move the brown container behind the image as it completely covers my image . I want to show brown container behind the image such that it does not cover the face of the image. Although I manage to do the task 90% how can I tackle this problem.

1 Answers

The z-index property in CSS specifies how elements overlap each other.

The z-index CSS property sets the z-order of a positioned element and its descendants or flex items. Overlapping elements with a larger z-index cover those with a smaller one.

MDN Docs

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

section {
  min-height: 100vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fddcc356;
}

.container {
  width: 90%;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.img_part {
  width: 40%;
  height: 250px;
  background: url(https://via.placeholder.com/200) no-repeat center/cover;
  border-radius: 8px;
  position: relative;
}

.text_part {
  width: 50%;
  min-height: 550px;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  border-radius: 8px;
  color: white;
  margin-left: -20px;
}

.text_part h1 {
  font-size: 40px;
  font-weight: lighter;
}

.text_part p {
  margin: 20px 0;
  line-height: 25px;
  font-weight: 500;
}

.text_part a {
  text-decoration: none;
  color: black;
  padding: 20px 30px;
  letter-spacing: 2px;
  display: inline-block;
  text-transform: uppercase;
  background-color: white;
  position: absolute;
}

.behind_part {
  min-width: 25%;
  min-height: 150px;
  background-color: brown;
  position: absolute;
  border: 2px solid red;
  margin-right: 350px;
  margin-top: -350px;
  
  z-index: -999;
}
<section>
  <div class="container">
    <div class="img_part"></div>
    <div class="text_part">
      <div class="content">
        <h1>French girl</h1>
        <h1>Summer Outfit</h1>
        <p>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.
        </p>
        <a href="#" class="btn">Learn More</a>

      </div>
    </div>
    <div class="behind_part"></div>

  </div>
</section>

Adding z-index: -999; to the image will make it move to the back.

Related