css scripters :D

hello crossfire friends, long time no speak :]

anyways ill get to the point, im designing a website by using css :o
i want to center my navigation bar, but I don't know the coding for it :/

so if anyone can give me a hand, ill give them a code to demonoid :p
Comments
43
give you a hand :$?
i don't play counterstrike :$
HOMOOOOOOOOOo

maak team voor lan
Parent
ik wacht op de invite :-)
Parent
haha wil je gaan dan? haal me op, gaan we een dagje trashen daar!
Parent
ja man kom mij bezoeken rutger. drinken we biertje op oude tijden
Parent
wanneer is die?
Parent
March 5-7 2010
Parent
en locatie?
Parent
check forums, tstaat er allemaal in
Parent
wat dacht je van deze suggestie. Op de terugweg stop je om en nabij rotterdam en doen we daar een biertje :-)
Parent
is goed pm je mobiel even dan. rotterdam is nogal groot
Parent
i play counterstrike :$
i'm pro in css :$
in shooting teammates :<
Parent
true :x
lets paly later!!
Parent
if i finished my math stuff :<
Parent
oki, i should do some more work for my presentation too :/
Parent
yooo miXer bruv
OK i suppose you're making a horizontal navbar with stuff in it

So make the navbar like you normally would in html using tables and shit or whatever you want to (you can actually make such stuff using nothing but css but I suppose you'll make the basic layout with html)

then you put the whole navbar structure inside <div> tags like this:
Quote<div class="navigation">ENTER UR NAV CODE HERE</div>


and put this in your stylesheet file

Quotediv.navigation {
margin:0px auto;
text-align:center;
}
That sets top and bottom margins to 0 and left and right margins to auto. also centers text.

There's a catch though, this makes the box size dependant on content. If you want to have a fixed size, use this instead:
Quotediv.navigation {
margin:0px 20%;
text-align:center;
}
Becos this makes it so that there's always 20% space as a margin to your navbox no matter how little or much content you have there. If the content is too much to fit into the box, it will go into a new line stretching the box down.

Fuck if I know if they work, I've done quite a bit of coding though (In this work practice shit i was at a local advertising agency place and I coded some web layouts to them using various methods including using pretty much nothing but css and div tags XD)


E: It's also possible to center the tables directly in html - but that's deprecated nowadays and therefore not valid and might stop working in future revisions of the language.

E2: if you wait a moment I'll fix this old layout of mine (as in make the code a little more valid) and you can use it as an example.
If you want to ever center a div you add this property:
margin:0 auto;
margin 0px auto;
margin:0px auto 0px auto;

all the above are the same, remember its top,left,bottom,right - so what we are doing here is setting left and right to auto and it will center within its current container

PS container is another word for something like a <div>

Your doing the right thing - dont use tables to lay a website out. Once you get used to css its easy, gives you more creative flexibility, allows for easy theme changes, faster for the browser, and it is XHTML strict if you do it right - that means it will looks right on anything including small devices.

The post above is correct except you don't need
text-align:center;

That's for text - the guy got confused because there is an old trick to centering <div> in ie5 browser using that, no one uses ie5 so don't worry about it.

And also don't use margins to set the width like he said, use width:100% or width:66px etc
That's for text - the guy got confused because there is an old trick to centering <div> in ie5 browser using that, no one uses ie5 so don't worry about it.



hahahah, that's a big bs, u obviously don't know how many ppl actually use it, fact that gamers don't use it doesn't mean nobody does!
Parent
http://www.w3schools.com/browsers/browsers_stats.asp

i put tricks in to make it work on old browsers because im a perfectionist, but making your code practices wrong so it works on very old ones because they got it wrong is not that great an idea imo. Actually I believe the only one you need to do this for is if you are centering the main web container anyway and then you do:
body{
text-align:center;
}

But I dunno why people would use ie5 tbh, its so insecure and displays wrongly, even ie6 is fucked - but I take your word for it.

Also this is for a gaming website!
Parent
I know it's for text, but centering navigation text looks better than having it in the left corner :)

cheers
Parent
Okyeah here's the example I spoke about earlier -- basically rewrote it completely, made it some years ago as a school project :P

http://burneddi.pingviini.info/filut/leiskareviivi
Preview

Soyeah it uses tables for basic structure but they don't have any properties in them - I know it's nowadays recommended to use nothing but CSS but it's quite complex if you're not too experienced with all this stuff. Besides, tables work fine..

It's even valid, after I removed some silly errors!
Those aren't used in the document, they're leftovers from its earlier form :)

Thank's for notifying though, i'll remove them. It actually uses no images at all in it's current state - except for the favicon.
Parent
still, WIDTH = 1 px cases like this and repeat-x = times the pixels u need : )
Parent
Yes, I know. I recall making it that way to get the 1px black border, but that was stupid as you could just define it into the element :).

Back then I was young, foolish and inexperienced though.
Parent
And here is something I wrote which is the "perfect" pure STRICT xhtml 1.0 three column website which works on all browsers, it can have a liquid width or a fixed one and it is easy to change to two column.. or no column.

have a look at how clean the code is!

http://www.hiphopmonster.com/Div_3Column/index.html
I'd say you're being quite overstrict here :)

The lad is obviously creating a website for small community, and isn't too experienced with web developing. While I agree with you in that creating web pages that work on practically everything you can think of ("Working" is a relative thing though - It's really hard to read that page of yours on a small resolution when there's like 1 letter per line in the main box, and because the boxes stretch all the way to the borders of your screen it looks silly on large widescreens, too. That's easily fixed though), it's quite silly to urge their importance to someone who has just started with all this stuff.

The bad thing about table layouts is that they don't scale unless you use some javascript or other hacks, which is widely considered bad.. Although I recall having to use javascript in a CSS tableish layout to stop a copyright box from stretching to the right edge of your screen (and there was no other way to stop it from doing that) :-)


E: Pardon me opening poster, looking at this website of yours, damn, it's nicely coded :P! And I see your problem too, I'll see if I can't find a fix. I'm just an amateur, after all.
Parent
yeh im with you, as for content that it purely to fill some space and show what each box is for, I wrote it as a starting point for myself -- a template. So the text formatting is left alone, as for the width that is true, but changing the width of the entire site is as easy as changing width:100% to width:900px on 1 line in the css. But yeh anyway i know what ur saying!
Parent
css aint a script.

oh and dump xhtml, it has no future. apart from the fact that its still being served as html :x
can u explain me the "xhtml has no future" part
Parent
html 5 is the future. should i go further or you are able to find tons of articles through google by yourself?
Parent
I'm able but u can go further : )
Parent
With all the semantics, etc, xhtml is a good idea and I liked it, but it unfortunately failed hard in reality.

A webmaster thinks he is cool, because he produced a website in xhtml 1.0. What he doesnt know is that his website is served as text/html and not as application/xhtml+xml anyways. This way the browser receives a badly written html 4.01 (since the page is correct with xhtml 1.0 standard; mainly its about the trailing tags, but not only). The reason why browsers display the page properly nonetheless, is because they ignore the faults of the code, use loose rules while processing data, etc.

Having two languages: xhtml and html, w3c had to choose one standard from these two. Some time ago w3c decided to support html 5.
http://www.w3.org/News/2009#entry-6601 this one and scroll up a bit, there is another news confirming the draft group working on xhtml 2.0 wont be renewed. this is to accelerate progress of html 5.

EDIT: http://www.w3.org/2009/06/xhtml-faq.html this one is worth reading too.
Parent
So where's my invite
Back to top