I have a <div>
inside which there is a <p>
with a text. How can I make <div>
an underline effect apply text-decoration: underline
when hovering over it <p>
using CSS?
This is my HTML code:
<div id="addNewColumn" style="width: 200px; height: 300px; border: 1px dashed green; border-radius: 5px; border-width: 2px; margin: 20px; cursor: pointer">
<p id="newColLink" style="text-align: center;"> Underline on hover </p>
</div>
If what you want is that when passing the
mouse
through thediv
apply the styletext-decoration: underline;
, try the followingcodigo
.Applies from
CSS
thehover
to the parent#addNewColumn:hover
but the ruleCSS
will apply to the child (p)To apply what you want by hovering on an element BUT assigning the styles to another element you could do the following:
With the selector
#addNewColumn:hover p
you are saying that all the elements<p>
that are inside the selector arediv#addNewColumn
applied a certain style when hovering the mouse over it.NOTE: inline styles (as you are using them) are bad code practice, you should have an external stylesheet and link it to the HTML via the tag
<link>
You leave your body as you have it:
In your css file that you will have linked to your html, add the following: