While playing with some CSS stuff I came across a common issue of hiding an element without hiding its pseudo elements. So I a practical way to do that. But still it won't work in every situations.
The first method is a method works for inline text and that kinds of situations only.- First, works with text only.
- Second, works with any plain background.
- It hides, not remove it.
<div>Hello</div>
div:before{Now according to above markup the output will be:
content:'Before ';
color:#000;
}
<div>Before Hello</div>To hide Hello string from the element we can do:
div:before{Use rgba color codes if you want to animate the above stuff.
content:'Before ';
color:#000 !important;
}
div{
color:transparent;
}
In this way plain text can be hidden. Well this is just a pretty hack to do that little kind of stuff. For a plain background container we can just do its background to transparent.
div{To hide it we can just change the background to transparent and if have any text then make its color to transparent too.
background:#00cfff;
width:250px;
height:250px;
}
div:after{
content:'';
background:#222;
width:250px;
height:250px;
display:inline-block;
}
div.hide{But still its a hack and doesn't work for every situations. I found it hence sharing it, If you have any better than this then comment and I'll update this article.
background:transparent;
}
Post A Comment:
0 comments: