Solved

Don't understand this style

Posted on 2011-03-22
10
208 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now