View Full Version : CSS table right aligning while I did align center
linux1880
10-13-2007, 12:35 PM
I did ceate a page using CSS, the first big table I made is on the centre of the screen. When I check with other computer some shows it in cetre but most of the computer shows on the right side and it beacomes really bad.
Is there any ways to define CSS table to force it to align centre no matter what resolution what tyope of screen ? I would be really tankful in anyone can sort this silly problem out :(
linux1880
10-13-2007, 12:40 PM
my css of the main table is like this
#Layer1 {
position:absolute;
left:0px;
top:0px;
width:899px;
height:1200px;
z-index:1;
left: 174px;
top: 8px;
background-color: #FFFFFF;
jscheuer1
10-13-2007, 02:56 PM
First make sure you are using an HTML 4.01 Transitional DOCTYPE with valid URL or stricter as your DOCTYPE. Once you have that, just set the width of the element and margin:0 auto;.
#table1 {
width:899px;
margin:0 auto;
}
However, at 899px, it will be too wide to center on smaller screens. If you were to use a percentage width it could scale to the user's screen/view port. If you were to use em width, it could scale to the user's default text size, which is usually smaller on smaller screens.
linux1880
10-14-2007, 09:39 AM
It didn't work :(
linux1880
10-14-2007, 09:40 AM
forgot to mention that designed it on the dreamweaver.
jscheuer1
10-14-2007, 03:27 PM
What DOCTYPE are you using?
Please post a link to the page on your site that contains the problematic code so we can check it out.
jscheuer1
10-17-2007, 04:32 PM
You PM'ed me a link to the page. Your layout depends heavily upon absolute positioning. That's not the best approach. But I am not here to completely redesign your page. Making the following modifications to two of your style selectors seems to work out:
#Layer1 {
position:absolute;
table-layout: automatic
width:899px;
height:1200px;
z-index:1;
top: 8px;
left: 50%;
margin-left:-450px;
background-color: #FFFFFF;
}
and:
#header {
position:absolute;
width:898px;
height:115px;
z-index:3;
left: 50%;
top: 7px;
margin-left:-455px;
background-image:url(logo/2.jpg);
}
Oh, and I see that throws off vcadmuni, so:
#vcadmuni {
position:absolute;
border:1px solid #C0C0C0;
width:300px;
height:115px;
z-index:2;
left: 50%;
top: 508px;
margin-left:132px;
background-color: #FFFFFF;
background-image: url(chat1.jpg);
}
One of the problems with this sort of set up is that browsers may vary slightly in where they see things falling. Particularly IE. For that browser, conditional comments may be used to tweak the style.
linux1880
10-18-2007, 11:42 AM
Many thanks jscheuer1 ,
It looks much better now with your help, I am glad and thankful to you for this. Btw, The absolute positioning you are talking about was the coding generated by the dreamweaver itself. I am beginner on CSS,
So do you mean I should do the relative positioning from the next time ? As a genuine helper that I have seen on you, how would you advise me to start on this ? Obviously I am a beginner on CSS, I did make a lot of websites before with tables but the page I made was my first CSS page in fact. Any suggestion with you will be a great help for me.
Thanks and regards
Linux
jscheuer1
10-18-2007, 06:04 PM
Actually, static positioning (which is default and need not be specified) is best. You cannot use the top, right, bottom, or left properties with it, but with margins and padding, one shouldn't need to. Relative, absolute, and fixed positioning all have drawbacks, and are best reserved for special effects, not for the entire overall layout of a page. Of these three, relative positioning is generally the least problematic, but does have its pitfalls.
As I said originally, and perhaps should have prefaced with "if using default (static) positioning":
First make sure you are using an HTML 4.01 Transitional DOCTYPE with valid URL or stricter as your DOCTYPE. Once you have that, just set the width of the element and [sic:a margin of] margin:0 auto;.
#table1 {
width:899px;
margin:0 auto;
}
linux1880
11-01-2007, 10:16 AM
default in dreamweaver is absolute positioning, or it's only mine ?
jscheuer1
11-01-2007, 11:42 AM
I think it depends upon how you use DW. I've seen many pages that are the output of DW that use little or no absolute positioning. If you set a distance from the top, bottom, or a side, that's absolute positioning.
linux1880
11-08-2007, 05:17 PM
hi jscheuer1
I did design another page and i did the main table as static , rest were defaulted by dreamweaver as absolute. It is again centrally not aligned. I did apply the code which you gave me last time, but no luck this time :(
I did apply
#apDiv1 {
margin:0 auto;
}
still no luck.
boogyman
11-08-2007, 06:37 PM
you need to add a width attribute
#apDiv1 {
margin:0 auto;
width: 100%;
}
that sets the width to 100% of the available width limited by the parent element, or in other words
body
div
table
if the div in the example above is 800 pixels wide and the table is 100% of the width.. the width of the table would be 800pixels, because it inherits the width from the div.
linux1880
11-09-2007, 09:22 AM
It did not work
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.