Image overlaying the site text

Asked

Viewed 78 times

1

My image is superimposing my text on h1 and my button, and when I lower the screen a little, all my tag text p superimposes the image.

I tried to use display: flex to prevent this from happening, but it didn’t work. I tried to find some post that helps me to fix this problem, but I could not locate any.

I need the image to stay aligned to the right of my tag texts h1 and p, and also from my button, and don’t overlap them.

Follows my code:

.container{ 
    width: 100%;
    height: 100%;
    display: flex;
    flex-grow: initial;

}
.content{
    font-size: 16px;
    margin: 5rem 4rem 0  10rem;

}
.content h1{
    width: 70%;
    height: 60%;
    display: flex;
    font-weight: 700;
    color: var(--second-color);
    font-size: 3.5rem;
    margin-left: 8rem;
    letter-spacing: 1px;
}

.content img{
    margin-left: 22%;
    top: 32%;
    position: absolute;
}

.content p{
    width: 50%;
    height: 40%;
    font-weight: 300;
    color: var(--second-color);
    font-size: 24px;
    margin-left: 8rem;
    position: relative;
}

.btn{
   width: 30%;
   font-weight: 700;
   margin-left: 8rem;
   padding: 1rem;
   font-size: 2rem;
   background: var(--main-color);
   color: white;

   cursor: pointer;
   border-radius: 14px;
   border: none;
}
 <section class="container">
  <div class="content">
    <h1>Create amazing graphics</h1>
    <img src="team-redimensionada.jpg" alt="imagem-ilustrativa">
    <p>Colaborate and create beautiful graphics with your team</p>
    <button class="btn">Start Now</button>
  </div>
</section>

1 answer

1


Remove the position: absolute; and add a float: right; in the .content img.

If you want her next to the h1, just tag <img> before the tag <h1>.

.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-grow: initial;
}

.content {
  font-size: 16px;
  margin: 5rem 4rem 0 10rem;
}

.content h1 {
  width: 70%;
  height: 60%;
  display: flex;
  font-weight: 700;
  color: var(--second-color);
  font-size: 3.5rem;
  margin-left: 8rem;
  letter-spacing: 1px;
}

.content img {
  margin-left: 22%;
  top: 32%;
  float: right;
}

.content p {
  width: 50%;
  height: 40%;
  font-weight: 300;
  color: var(--second-color);
  font-size: 24px;
  margin-left: 8rem;
  position: relative;
}

.btn {
  width: 30%;
  font-weight: 700;
  margin-left: 8rem;
  padding: 1rem;
  font-size: 2rem;
  background: var(--main-color);
  color: white;
  cursor: pointer;
  border-radius: 14px;
  border: none;
}
<section class="container">
  <div class="content">
    <h1>Create amazing graphics</h1>
    <img src="team-redimensionada.jpg" alt="imagem-ilustrativa">
    <p>Colaborate and create beautiful graphics with your team</p>
    <button class="btn">Start Now</button>
  </div>
</section>

  • 1

    Thank you very much, it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.