Solved

Don't understand this style

Posted on 2011-03-22
10
209 Views
Last Modified: 2012-05-11
I'm working with this webpage and I don't understand the style for this tag.

This is the style for the main <div> tag (that holds other <div> tags)
<BODY>
<DIV id=main>...........</DIV></BODY>  :

     #main {POSITION: absolute; WIDTH: 950px; MARGIN-LEFT: -475px; LEFT: 50%}


I don't understand the "-475px; LEFT: 50%" part.

It displays with no problems in the browser, but is it ok to use this style for a webpage?


Other styles used for the page:
BODY {MARGIN: 0px;}
HTML {BACKGROUND-IMAGE: url(images/GT-3000x1BG_lt_grey3.gif); BACKGROUND-REPEAT: repeat-y; BACKGROUND-POSITION: center 50%}

0
Comment
Question by:MikeMCSD
  • 5
  • 5
10 Comments
 
LVL 7

Expert Comment

by:nbove
ID: 35192055
The "MARGIN-LEFT:-475px;" part will shift the div to the left 475 pixels.  And the "LEFT:50%" part will make left section of the div begin at 50% at the midpoint of it's parent.  The combination of the two will make the div show up 475 pixels to the left of the midpoint of the screen, essentially centering the div.
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 35193918
thanks . .

but why do that to center it?  Aren't there other ways, or better ways to do it?
0
 
LVL 7

Expert Comment

by:nbove
ID: 35193983
As for why certain programmers code things in certain ways, I have given up trying to understand such things.  Yes, there are better ways to center a block.  If I were writing the style for the above block I would have written it as:

#main {POSITION: relative; WIDTH: 950px; MARGIN-LEFT: auto; MARGIN-RIGHT: auto}

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Author Comment

by:MikeMCSD
ID: 35194092
I miss laying out pages with <tables>.
This <div> thing is confusing the hell out of me.
0
 
LVL 7

Expert Comment

by:nbove
ID: 35194109
Ultimately, it is up to you to lay your page out in whatever manner makes the most sense to you.  There are advantages to using DIV tags and CSS to control the style of your site, but if it makes the site confusing and unmaintainable for you, then I would say that the benefits do not outweight the drawbacks for you.  Use whatever method works best for you and makes a clean page that is easy for you maintain.
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 35194136
But <div>'s are suppose to be better for SEO and page load speed.
Then you have to deal with the IE6 and IE7 problems.
I guess I'll just have to put more study time into it.

0
 
LVL 7

Expert Comment

by:nbove
ID: 35194226
You are correct.  Incidentally, if your question has been answered, please mark this question as answered.
0
 
LVL 16

Accepted Solution

by:
MikeMCSD earned 0 total points
ID: 35281603
I tried your style and the original one in IE5 and the original one was centered
and yours didn't display right.
I'm beginning to think there is some real reason why they used that style.
Maybe it works best for all browsers.
If it wasn't for all this browser compatility nonsense, CSS would'nt be so bad.
It will take another few years before this problem goes away.
0
 
LVL 7

Expert Comment

by:nbove
ID: 35287261
It appears that your original question has been resolved.  If so, please mark this question as resolved.
0
 
LVL 16

Author Closing Comment

by:MikeMCSD
ID: 35321847
Need someone who is really a pro at CCS to give the correct insight into this question.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question