Solved

Don't understand this style

Posted on 2011-03-22
10
205 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

760 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

16 Experts available now in Live!

Get 1:1 Help Now