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 trial

CSS

Carlos Quivera
Carlos Quivera
6,917 Points

How to add a border to an anchor element and change it's color on hover?

I have the following code on my html file: <div class="submit"> <a href="my_work.html">WATCH MY WORK</a> </div>

And this is my CSS:

.submit {
    text-align: center;
    font-family: 'Roboto Slab', serif;
    margin-top: 10%;
}

.submit a {
    color: white;
    background-color: #5A827F;
    padding: 5px 11px;
    border-style: 2px solid
}

.submit a:hover {
    border-color: white;
}```

As you can see, I added a border around my anchor the same color as the background so when I hover the anchor, it changes the color of my border from #5A827F to white without moving the element but it's not applying the border, what am I doing wrong?

Thanks!
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Border</title>
        <style>
            body {
                background-color: #000;
            }
            .submit {
                text-align: center;
                font-family: 'Roboto Slab', serif;
                margin-top: 10%;
            }

            .submit a {
                color: white;
                background-color: #5A827F;
                padding: 5px 11px;
                border-style: 2px solid
            }

            .submit a:hover {

                border:1px solid #fff;
            }
        </style>
    </head>

    <body>
        <div class="submit">
            <a href="my_work.html">WATCH MY WORK</a>
        </div>
    </body>
</html>

You should set the border size. I hope it helps.

Hi Carlos,

If you look to the bottom of the text box you will see something that says Markdown Cheetsheet. Also, there is a post here titled: Posting Code to the Forum by Dave McFarland. If you don't understand that maybe this will make sense: How to display code at Treehouse.

Jeff

1 Answer

Holt Hunter
Holt Hunter
4,629 Points

Try this:

submit a { color: white; background-color: #5A827F; padding: 5px 11px; border: 2px solid #5a827f;}

then

.submit a:hover { border: 2px solid white; }
Carlos Quivera
Carlos Quivera
6,917 Points

Thank you so much! It worked! :D