Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Hover only on text?

Tags:

html

text

css

hover

If I have the following HTML with a custom CSS class:

.custom_list_item {
  color: black;
}

.custom_list_item:hover {
  color: red;
}
<div class="custom_list_item">Test</div>

This makes it so when I hover over the entire box, it makes the text red. Is there a way to make sure this only happens when I hover over just the text itself?

like image 390
MinhazMurks Avatar asked Oct 30 '25 22:10

MinhazMurks


1 Answers

Wrap it in a span. A p would stretch over the full width of div.

.custom_list_item {
    color: black;
}

.custom_list_item span:hover{
    color: red;
}
<div class="custom_list_item"><span>Test</span></div>
like image 131
TVBZ Avatar answered Nov 02 '25 11:11

TVBZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!