I want to change background of elements inside a div, only when hovered and when their property contenteditable is true.
I have tried :
#myDiv[contenteditable="true"]:hover { background-color: rgba(217, 245, 255,0.5);}
But it doesn't work. And if I move the pseudo class to the div :
#myDiv:hover [contenteditable="true"] { background-color: rgba(217, 245, 255,0.5);}
Then all fields with contenteditable=true get the background... any trick to fix that in pure css ?
EDIT : HTML example:
<div id="myDiv">
<span contenteditable="true">blabla</span>
<div "subdiv" contenteditable="true">blibli</div>
</div>
The contenteditable attribute specifies whether the content of an element is editable or not.
The contenteditable is used to specify whether the element's content is editable by the user or not. Syntax: <element contenteditable="true|false"> This attribute has two values. true: If the value of the contenteditable attribute is set to true then the element is editable.
You can add the contenteditable="true" HTML attribute to the element (a <div> for example) that you want to be editable. If you're anticipating a user to only update a word or two within a paragraph, then you could make a <p> itself editable.
This will select all direct children of .myDiv
with [contenteditable="true"]
.myDiv:hover > *[contenteditable="true"] {
background-color: rgba(217, 245, 255,0.5);
}
<div class="myDiv">
<p contenteditable="true">Lorem ipsum dolor sit amet.</p>
<span contenteditable="true">Lorem ipsum dolor.</span>
<p contenteditable="false">Lorem ipsum dolor.</p>
</div>
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