Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSean Flanagan
33,235 PointsBackground colour of links
Hi. I've set the background colour of my links to yellow but when I hover my pointer over them, the yellow doesn't show. Does anyone know why, please?
Here's my HTML:
<!DOCTYPE html>
<html>
<head>
<title>Link and User Action Pseudo-Classes</title>
<link rel="stylesheet" href="css/css_foundations_style.css">
</head>
<body>
<h1>CSS Pseudo-Classes</h1>
<a href="#a">Lorem ipsum dolor sit amet</a>
<p>Consectetur adipiscing elit. Vivamus sed egestas tortor, vel tincidunt dolor. Maecenas euismod auctor massa ut convallis.Nullam tempor erat eget nulla auctor modeltie.</p>
<a href="#b">Duis ut velit faucibus</a>
<p>Proin orci arcu, dapibus vel faucibus in, commodo in nunc. Vestibulum erat dolor laoreet nec cursus non, luctus ut elit. In sed congue lectus, id ullamcorper massa.</p>
<a href="#c" target="_blank">View more in a new tab »</a>
<form>
<input type="text" name="name" placeholder="name">
<input type="text" name="email" placeholder="email">
<input type="submit" name="submit">
</form>
</body>
</html>
And here's my CSS:
body {
margin: 0;
padding: .8% 24%;
font: 1.1em/1.5 sans-serif;
}
a,
p {
padding 3px;
}
form {
margin-top: 30px;
}
input {
font-size: inherit;
}
input[type="text"] {
display: block;
margin-bottom: 15px;
padding: 10px;
width: 250px;
border: 2px solid steelblue;
}
input[type="submit"] {
width: 100px;
height: 40px;
border: none;
background: steelblue;
color: white;
font-size: inherit;
}
/* Pseudo-classes */
a:link {
color: red;
}
a:visited {
color: green;
}
a:active {
font-size: 26px;
}
a:hover {
color: white;
text-decoration: none;
background-color: tomato;
}
:focus {
background-color: yellow;
}
Thanks for any help that gets offered.
3 Answers
Carman A
7,672 PointsDoes it turn white, with tomato background?
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsHere is the problem. :focus {} targets any element that currently has the focus. So, if you it the tab button a few times, you'll see your different links light up the way you want them to.
If you want to change the background color to yellow when the user hovers over it, you'll need to change the background-color from tomato to yellow in the a:hover selector.
Sean Flanagan
33,235 PointsHi Nicholas. I changed the background colour to yellow like you said and the links went yellow when I hovered the pointer over them. Thanks.
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsNo Problem! Happy to help. :)
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsEdit: Accidental Repost. :(
Carman A
7,672 PointsCarman A
7,672 PointsIf so delete the
a:hover
selector/pseudo element and following code.