I have DIV with some CSS styling and TEXT inside DIV. How to move TEXT outside of DIV and apply some styling using either CSS or JavaScript?
HTML
<div class="divstyle">TEXT</div>
CSS
.divstyle {
width: 200px;
height: 50px;
background-color: grey;
}
I create complete DIV over javascript:
var inputfield = document.createElement("div");
inputfield.textContent = inputfieldData['TEXT'];
inputfield.classList.add("divstyle");
inputfieldsContainer.appendChild(inputfield);
When it renders in browser it looks like this:
+-----------------+
| TEXT |
+-----------------+
I wish to be like this:
TEXT
+-----------------+
| |
+-----------------+
What I tried:
.divstyle::before {
top: -50px;
left: -20px;
}
Is there a way to add DIV inside DIV using only CSS?
Maybe the solution could be to wrap the TEXT in some tag and apply CSS to it, but if it’s possible to do it over CSS?
3
Answers
Here is an example of how you can achieve this:
Although I don’t understand why you want this, here is a way to achieve it :
HTML
CSS
You could add a span using another styling (here: textstyle)
which could look like that
The important part to notice here is that position is set to absolute, so you can position it relative to its first positioned ancestor element.