Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Editing my CSS for single navbar- want it chopped off at sides

Edrol97

Silver Coder
Hi all,

I've got a navbar I want to create similar to the one below.

Screenshot 2024-09-27 at 11.50.04.png

Currently my satirical version looks like this-

Screenshot 2024-09-27 at 11.51.45.png

There are a few problems with the navbar- namely the shape of it- I want it to be slimmer cut down at the sides to about 75% width, and also there is a hover effect on the topnav in the first picture, that changes each of the menu options to a different colour. After trying defining each link as a specific class, i.e.,
HTML:
<div class="topnavmail">
<a class="about" href="about_me.html">About</a>
and then styling the class
CSS:
.topnavmail .about a:hover {
  color: red;
}
 
Rather than giving each link it's own class name, you could select all <a> elements in the parent .topnavmail element:
CSS:
.topnavmail a:hover {
  color: red;
}

For the width of the header, set width: 75%; to the header element, and then you can add margin: 0 auto; to centre align the header.
 
Rather than giving each link it's own class name, you could select all <a> elements in the parent .topnavmail element:
CSS:
.topnavmail a:hover {
  color: red;
}

For the width of the header, set width: 75%; to the header element, and then you can add margin: 0 auto; to centre align the header.
Hi John,

The problem is I want each <a> element in .topnavmail to appear a different colour on hover. I've done the margin: 0 auto for the header, and it works, but when I try and input the same logic for the footer, it doesn't position it to the center. The footer I wish to create a near repica of from the top footer up is below.
Screenshot 2024-09-27 at 14.13.45.png

Currently what i have is this:

Screenshot 2024-09-27 at 14.19.35.png


The width: 75% made the footer I had float to the very left despite having no left attribute set on it. I thought float: center could work, but tried that and it didn't

How would you rectify this?

Thanks,

Eliot
 
The float property doesn't have such a value as center, and I would normally advise against using the float property for aligning elements in this way.

If you have float: left; on this footer element, try removing it and applying the margin: 0 auto; to the footer. Otherwise, could you post the HTML and CSS for the footer element?
 
You don't have a lot of links in the nav so you could use:
CSS:
.topnavmail a:nth-of-type(1):hover{
    color: red;
}
.topnavmail a:nth-of-type(2):hover{
    color: pink;
}

and so on. You might need to adjust this selector if there is structure between .topnavmail and the <a> such as if your nav links are in a <ul>. If that is the case, the selector would change to:
Code:
.topnavmail li:nth-of-type(1) a:hover{
    color: red;
}
.topnavmail li:nth-of-type(2) a:hover{
    color: pink;
}

and so on.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom