so I have created a div
as the parent with a span
element inside, holding the title for the parent and I have defined a css
before pseudo-element (:before
) for the parent so when user hovers over the element it has a nice transition
but the problem is : the :before
covers the span
element so the title gets hidden which is not acceptable of course !
here's the sample code on jsfiddle : http://jsfiddle.net/msU6p/4/
here's the HTML :
<div class="menuItem_Large" id="node_1_menu">
<span>menu item 1</span>
</div>
and styles :
.menuItem_Large
{
position: absolute;
left: 0px;
display: inline-block;
padding-left: 6px;
padding-right: 6px;
height: 20px;
line-height: 16px;
vertical-align: middle;
background-image : url('http://i58.tinypic.com/21eyrk8.png');
background-repeat: repeat;
cursor:pointer;
}
.menuItem_Large:before
{
content:"";
position:absolute;
top:0px;
left:0px;
width:0%;
height:20px;
background-color:rgba(0,200,255,1);
transition:width 0.3s ease-out;
}
.menuItem_Large:hover:before
{
width:100%;
}
.menuItem_Large span
{
color: white;
font-size: 16px;
}
I tried using z-index
on span setting it to 2 or so but It doesn't work and when I set z-index
of before
element to negative It goes under the parent's background-image
which is not good
does anyone know where's my mistake or what can I possibly do to make this work only using css
?
Thanks in Advance
In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.
The ::before pseudo-element can be used to insert some content before the content of an element.
The content CSS property is used in conjunction with these pseudo-elements, to insert the generated content.
display:block; position:relative;
for <span>
can help to you. DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With