CSS Problem

I heard this site is good, so I’m here to give it a try. I have a problem with something I found on W3 School which is I’m trying to get Nav buttons to be in the center instead of either the left or right. The coding is at Sticky Nav Button. If someone could either center the Home/news/Contact buttons to the center that would be great. If not, could someone point me in the right direction to get the answer I’m looking for.

Hi @timlab55. Welcome to the SitePoint forums. :slight_smile:

With that example you linked to, you could center the navigation items by adding the following CSS:

#navbar {
    display: flex;
    justify-content: center;
}
1 Like

I thank you for your help in this matter.
Dan

1 Like

You’re welcome. :slight_smile:

If I have a problem from time to time and need help can I call on you? To me a person who can solve something so quickly is invaluable.
Again thank you.
Dan

1 Like

That’s not the way forums work. If you have a problem ask away. Whoever is available will respond.

1 Like

Sure. But you’ll discover that there are lots of way better coders around here than me. :stuck_out_tongue:

1 Like

Dont worry I’ll post but thank you for the reminder.

2 Likes

Is this site only for CSS? If not then I would like to add another question here please. When I run my website (not up yet), I go from my index.html page to ContactUS.PHP page. In my ContactUS.php page I have two required_once statements. The first one is “…/navbar/navbar.php” and the other is ‘backform.php’. And then the program tosses me an error. The error states "Warning session_start(): Session cannot be started after headers have already been sent in D:\XAMPP\hdocs\sitename. I do know that when my ‘backform.php’ starts up, the very first line in it is session_start(); Is this due to the new navbar?
Thanks

You can ask about any aspect of web design. But this sounds like a PHP question, so it’s best to start a new topic in the PHP section, where the PHP afficianados will see it. :-).

Roger dodger

1 Like

I guess I’m not done with learning about CSS. In two of my CSS files that I have, for example is this. One one file I have .header and then the other one I have header. In addition to that, what is so special about header, .header and #header? Also when is it going to be possible to submit more than just screenshot?
Thanks
Dan

The header selector will select any <header> element.
The .header selector will select any element with a "header" class, eg: <div class="header">
The #header selector will select the element with "header" as its ID, eg: <div id="header">

1 Like

There’s a lot to learn, Don’t give up learning,

1 Like

Trust me, not giving up on this, very interesting stuff. Question grand wizard (Gandalf), when can I send more than 1 upload per day?
THanks
Dan

2 Likes

When you advance beyond a new user to a higher trust level.

1 Like

Okay got it on the trust level thing. Thanks Sam. Speaking of which, you missed one Sam. I also have #nav and sometimes a nav#nav. What do they mean?
Thanks

nav in CSS refers to an element in your HTML called <nav>. That <nav> element might have an ID selector on it: <nav id="nav">. In that case, the <nav> element can be selected in CSS in various ways:

nav { }      /* selects the element based on the element name */
#nav { }     /* selects the element based on its ID */
nav#nav { }  /* selects the element based on the element 
                name and its ID — which is mostly overkill. */

Therefore I’ll take it, that nav or #nav or nav#nav or .header or header or #header all do the same thing correct?

As long as your <header> element has a class of .header and an ID of #header, then yes, although one thing to consider in all this is specificity. This is key to understanding how CSS works. Different selectors carry different authority, so to speak, and can override each other in the “cascade”. It’s better to be economical about use of IDs and classes, only using them where you really need them. Generally, don’t use an ID (such as #nav) unless you’re using JavaScript, or wanting to link to an element, as IDs carry strong specificity and are hard to override in CSS.