When I hover over the p1
element the h1
element is supposed to appear but it doesn’t. I am a bit confused by this because when I looked it up this is what it said to do but it doesn’t seem to work.
h1 {
background-color: blueviolet;
color: white;
width: 250px;
border: 2px solid black;
padding-top: 20px;
padding-bottom: 20px;
display: none;
}
p {
font-family: "Times New Roman", Times, serif;
font-size: 20px;
}
p1 {
color: blueviolet;
}
p1:hover + h1 {
display: block;
}
```
<h1>Welcome to IT202</h1>
<p><strong>Mouse over the text "Show Welcome" and the welcome message is displayed. Mouse out and the welcome messages disappears!</strong></p>
<p1>Show Welcome</p1>
I tried adding ids but that did not work
2
Answers
Don’t use tag as HTMl does not have any builtIn tag insted use . In css #p1:hover{backgroundcolor:red} this may resolve
False.
You’re using the next-sibling combinator (
+
), which targets the following sibling.There is no
h1
coming after ap1
in your code. Therefore, nothing is being targeted withp1:hover + h1
.It works, for example, if you put the
p1
before theh1
.If you want to maintain the order of elements on the screen, consider the
order
property.