x404.co.uk
http://www.x404.co.uk/forum/

XHTML/CSS
http://www.x404.co.uk/forum/viewtopic.php?f=3&t=325
Page 1 of 1

Author:  Angelic [ Mon May 04, 2009 7:32 pm ]
Post subject:  XHTML/CSS

I know this isn't exactly "meeting place" material, but I hope the attachment will help.

Basically i'm doing some website coding for a module where i've got to design a website. The lectures weren't exactly helpful, so i've been teaching myself using t'internet and it's been slow going.

One thing I can't work out how to do is to create a box which will contain everything and that is centered (much like THIS page.

Anyone good at website programming?

*looks hopeful and offers pie*

Image

Author:  finlay666 [ Mon May 04, 2009 7:42 pm ]
Post subject:  Re: XHTML/CSS

By 'white box' that is centred do you mean the white and all that is contained within it?

If so it looks like a relative CSS style setting with say 5% left start and 95% right finish, then you whack all the stuff you want inside it. set a 1% border top & bottom say.

And Bob is your proverbial man from U.N.C.L.E. .... or something like that ;)

Did you not look at the source for the page? there would be a link somewhere in the source to the CSS if it is referenced and not embedded.

the CSS file is : HERE

The actual source of the site will help you find out what does what

Author:  big_D [ Mon May 04, 2009 7:44 pm ]
Post subject:  Re: XHTML/CSS

You just need to put the content into its own <div> tag, giving it either an id or a class (class is generally preferred, but if it is unique on the page, id is okay as well.

Then set up the CSS for the div's class or id.

E.g. in you xhtml file:
Code:
<div class="main_content">blah blah blah</div>



In your css file:

Code:
.main_content {
    border : solid 1px black;
    width : 50%;
    left: 25%;
}

Just fill in the code you need to apply the formatting.

A good place to start is w3schools.com

Author:  EddArmitage [ Mon May 04, 2009 9:18 pm ]
Post subject:  Re: XHTML/CSS

big_D wrote:
class is generally preferred, but if it is unique on the page, id is okay as well
Why so, out of curiosity? I always use ID if it is unique, to force it to be unique and stop it being used where it's not intended to be.

Edd

Author:  Angelic [ Mon May 04, 2009 9:35 pm ]
Post subject:  Re: XHTML/CSS

Okay i've put it in it's own class, and did "left: 20%;" but it is still aligning left, very strange. How do I make it centre? =/

But thanks for the boxage help =) I sorta figured it out just as I posted but didn't consider doing it as a percentage (which I think I might do it as now).

Author:  forquare1 [ Mon May 04, 2009 9:54 pm ]
Post subject:  Re: XHTML/CSS

EddArmitage wrote:
big_D wrote:
class is generally preferred, but if it is unique on the page, id is okay as well
Why so, out of curiosity? I always use ID if it is unique, to force it to be unique and stop it being used where it's not intended to be.

Edd


We were always told one would use an ID for a specific thing, it could be specific to a single page, or a site-wide specific thing like the main body div. One would use a class for less specialist circumstances, like a class for making any picture float left or right.

Author:  Nick [ Mon May 04, 2009 10:35 pm ]
Post subject:  Re: XHTML/CSS

forquare1 wrote:
EddArmitage wrote:
big_D wrote:
class is generally preferred, but if it is unique on the page, id is okay as well
Why so, out of curiosity? I always use ID if it is unique, to force it to be unique and stop it being used where it's not intended to be.

Edd


We were always told one would use an ID for a specific thing, it could be specific to a single page, or a site-wide specific thing like the main body div. One would use a class for less specialist circumstances, like a class for making any picture float left or right.


Yeah, exactly. Using a class in this instance would be pretty pointless.

You would also need the "line position:relative;" in the css for that <div>

Author:  big_D [ Tue May 05, 2009 4:43 am ]
Post subject:  Re: XHTML/CSS

Yep. If the item can be used more than once, then it should be a class. If it is unique, use Id.

Also, if you have several input fields on a form, for example, each would have an Id, but you would give them all the same class, so that you only need to define the style once and they all look the same...

Yes, position:relative is also needed. I didn't want to include all of the CSS he would need, just get him started, so that he actually learnt how it works and how to research it on his own. ;)

As a hint, Angelic, you will probably need to define the width and height of the body and / or html styles:

Code:
html {
    width : 100%;
}

body {
    width : 100%;
}


For example.

Author:  EddArmitage [ Tue May 05, 2009 11:10 am ]
Post subject:  Re: XHTML/CSS

Nick wrote:
forquare1 wrote:
We were always told one would use an ID for a specific thing, it could be specific to a single page, or a site-wide specific thing like the main body div. One would use a class for less specialist circumstances, like a class for making any picture float left or right.


Yeah, exactly. Using a class in this instance would be pretty pointless.

You would also need the "line position:relative;" in the css for that <div>
Well yes, I agree entirely, but I still don't see why class is "preferred". Surely ID is preferred, where it is suitable, but in most cases you have to use class or duplicate lots and lots of CSS, which is obviously *VERY* bad.

Edd

Author:  Nick [ Tue May 05, 2009 11:21 am ]
Post subject:  Re: XHTML/CSS

big_D wrote:
Also, if you have several input fields on a form, for example, each would have an Id, but you would give them all the same class, so that you only need to define the style once and they all look the same...


It's interesting how people do things differently. I would always prefer to refer to the input element itslef in the css. If there was more than one form, I'd give each form an ID and do it that way.

I tend to use as few classes as possible. I think it's because I like to keep the HTML as clean as possible and also because classes are mis-used so often - it's a pet hate of mine.

Author:  Nick [ Tue May 05, 2009 11:25 am ]
Post subject:  Re: XHTML/CSS

EddArmitage wrote:
Nick wrote:
forquare1 wrote:
We were always told one would use an ID for a specific thing, it could be specific to a single page, or a site-wide specific thing like the main body div. One would use a class for less specialist circumstances, like a class for making any picture float left or right.


Yeah, exactly. Using a class in this instance would be pretty pointless.

You would also need the "line position:relative;" in the css for that <div>
Well yes, I agree entirely, but I still don't see why class is "preferred". Surely ID is preferred, where it is suitable, but in most cases you have to use class or duplicate lots and lots of CSS, which is obviously *VERY* bad.

Edd


I agree. As I hinted in my previous post, for me a class is NEVER preferred. Of course, they are sometimes the best option, but very rarely.

Author:  EddArmitage [ Tue May 05, 2009 4:44 pm ]
Post subject:  Re: XHTML/CSS

Nick wrote:
I agree. As I hinted in my previous post, for me a class is NEVER preferred. Of course, they are sometimes the best option, but very rarely.
Yes, just read your post and we're on the self-same wavelength.

Edd

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/