Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Expanding content to top

How do I expand my content to top instead of bottom? I’m trying to make the text go to top but it’s always going to bottom. Here is my code =>

.box {
  width: 200px;
  height: 200px;
  background-color: red;
  position: absolute;
}

.div {
  position: relative;
  transition: .35s ease-in-out 0s;
  height: 0;
  width: 70%;
  left: 50%;  
  top: 100px;
  transform: translateX(-50%);
  text-align: center;
  z-index: 3;
}

.text {
  position: relative;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  box-shadow: 0 0 0 1px black;
  line-height: 155%;
  padding: 0.2em 0.3em;
  color: white;
  background-color: black;
  background-color: rgba(0, 0, 0, .8);
  border-radius: 3px;
  font-size: 1.125rem;
}
<div class="box">
  <div class="div">
    <p class="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </div>
</div>

My expected output is =>
Image

I know that I’m using top: 100px in .div but is just to create an example. I’m aiming to the text always go to top, no matter the configuration.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to manipulate height, top and bottom but no success, what should I do? Thank you.

>Solution :

You might want to swap position: relative; and position: absolute; in the .box– and .div-classes as follows:

.box {
  width: 200px;
  height: 200px;
  background-color: red;
  position: relative;
}

.div {
  position: absolute;
  transition: .35s ease-in-out 0s;
  height: 0;
  width: 70%;
  left: 50%;  
  transform: translateX(-50%);
  text-align: center;
  z-index: 3;
}

.text {
  position: relative;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  box-shadow: 0 0 0 1px black;
  line-height: 155%;
  padding: 0.2em 0.3em;
  color: white;
  background-color: black;
  background-color: rgba(0, 0, 0, .8);
  border-radius: 3px;
  font-size: 1.125rem;
}
<div class="box">
  <div class="div">
    <p class="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading