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 >
<div >
<p >Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
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.
I tried to manipulate height, top and bottom
but no success, what should I do? Thank you.
CodePudding user response:
You had a lot of unnecessary code. And mess with position relative and absolute :D Here it is working well https://jsfiddle.net/ue6s3ap5/5/
* {
margin: 0;
padding: 0;
}
.box {
width: 200px;
height: 200px;
background-color: red;
position: relative;
}
.div {
position: absolute;
margin: 20px
}
.text {
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: rgba(0, 0, 0, .8);
border-radius: 3px;
font-size: 1.125rem;
}
<div >
<div >
<p >Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
CodePudding user response:
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 >
<div >
<p >Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>