?
Solved

Don't understand this style

Posted on 2011-03-22
10
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

752 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