Jonas.D
Jonas.D

Reputation: 357

<p> keeps on falling out of <div>

I've been trying to get my <p> in my <div> but it keeps on falling out. I want the div to become larger in height whenever the text inside <p> becomes more text.

#service-wrapper {
  width: 100%;
  height: auto;
  margin-top: 20%;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  padding-top: 8px;
  max-width: 90%;
}

.service-title {
  width: 100%;
  height: 70px;
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 25px;
  font-weight: 600;
  margin-top: 0;
}

.service-wrapper2 {
  width: auto;
  height: auto;
  display: inline-flex;
  max-width: 100%;
}

.service-container {
  width: 300px;
  height: auto;
  border: 4px solid rgb(94, 106, 124);
  margin: 10px 40px;
}

.container-title {
  width: auto;
  height: 30%;
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 20px;
  padding-top: 8px;
  border: solid 1px #fff;
  background-image: url("images/drawing.jpg");
  background-size: 100% 100%;
}

.service-container p {
  color: rgb(247, 250, 255);
  max-height: 100%;
}
<div class="service-wrapper2">
  <div class="service-container">
    <div class="container-title">service1</div>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.

    </p>
  </div>

I've got multiple service.containers next to each other but I don´t think it matters for this case.

Upvotes: 0

Views: 730

Answers (1)

Salvatore
Salvatore

Reputation: 1435

This is what you are looking for. I've made small ammends to your css as well to fix the issue (For eg: removed the height from container-title).

word-wrap: break-word; 

The word-wrap property allows long words to be able to be broken and wrap onto the next line.

.service-wrapper2 {
  width: auto;
  display: inline-flex;
  max-width: 100%;
}

.service-container {
  padding: 20px;
  width: 300px;
  border: 4px solid rgb(94, 106, 124);
  margin: 10px 40px;
  word-wrap: break-word;
}

.container-title {
  width: auto;
  color: #000;
  font-family: 'Montserrat', sans-serif;
  font-size: 20px;
  padding-top: 8px;
  border: solid 1px #fff;
  background-image: url("images/drawing.jpg");
  background-size: 100% 100%;
}

.service-container p {
  color: #000;
}
<div class="service-wrapper2">
  <div class="service-container">
    <div class="container-title">service1</div>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaawwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaa

    </p>
  </div>
</div>

Upvotes: 4

Related Questions