473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DIV and UL: two different blocks in IE ?


Hi all,

I am new to CSS (and web technologies in general) and trying to do some
basic stuff with it. For example, I'd like to position a block element
centered in a page: the text inside this block should be also centered.
Here is what I tried:

<html>
<head>
<style type="text/css">
<!--
body, ul, div {
margin: 0 ;
padding: 0 ;
}

..test {
text-align: center ;

width: 95% ;
margin: 1em auto ;

border: #3333ff 1px solid ;
}
-->
</style>
</head>

<body>
<div class="test">test</div>
</body>
</html>

In Mozilla, what I get is a blue rectangle around the div that's 95%
wide as the body, with some space left and right (presumably 2.5% each
side), plus text centered in this rectangle. Exactly what I want.

In IE6, the div pushed to left side, i.e. it's not centered at all. The
strange thing (to me) is that if I replace the div by an ul, then I get
what I want. Can you explain that ?

And can you explain me how to center the div (I don't need any ul here,
actually I want to have an address element, but it behaves just the same
as the div...) ?

Jul 20 '05 #1
3 2346
Vincent <vi************@wanadoo.fr> wrote:
I am new to CSS (and web technologies in general) and trying to do some
basic stuff with it. For example, I'd like to position a block element
centered in a page: the text inside this block should be also centered.
Here is what I tried:

<html>
<head>
No Doctype so you're putting IE6 into quirks mode.
<style type="text/css">
<!--
body, ul, div {
margin: 0 ;
padding: 0 ;
}

.test {
text-align: center ;

width: 95% ;
margin: 1em auto ;
If you're setting the width to 95% why not use
margin: 1em 2.5%;
It's supported by a wider range of browsers than the auto value.
border: #3333ff 1px solid ;
}
-->
</style>
</head>

<body>
<div class="test">test</div>
</body>
</html>

In Mozilla, what I get is a blue rectangle around the div that's 95%
wide as the body, with some space left and right (presumably 2.5% each
side), plus text centered in this rectangle. Exactly what I want.

In IE6, the div pushed to left side, i.e. it's not centered at all. The
strange thing (to me) is that if I replace the div by an ul, then I get
what I want. Can you explain that ?


Actually, not the case. The UL is not centered, the standard left
indent makes it look as if it is. If you put both the div and the ul
in the same page you'll see that they end at the same point. i.e. the
95% includes the ul's left indent.

Have a look at the source of
http://steve.pugh.net/test/test58-s.html (standards mode)
and
http://steve.pugh.net/test/test58-s.html (quirks mode)

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #2
Vincent wrote:
I simply added the doctype line without the PI and then it worked ! Do you
know why this ?xml? interferes ?


It's a bug in Internet Explorer. It's present in early Opera 7.x releases
too.
--
Jim Dabell

Jul 20 '05 #3
Steve Pugh wrote:

Because Microsoft are stupid. IE is programmed to look only at the
first non-white space line of the file for a doctype. If there's
anything before the doctype (XML, a comment, anything) then it goes
into Quirks mode.

Amazing...

Change the width to 70% and you'll see that the UL is certainly not
centered.


Ok, you convinced me. Thanks a lot for your time and explanations...

Vincent.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Doug Holton | last post by:
Is there any metaclass trick or something similar to allow anonymous code blocks? I'd like to be able to let users do something like this fictitious example: b = Button() b.OnClick =: print...
2
by: Dr. Richard E. Hawkins | last post by:
I've googled around, and asked everyone I know, but I still can't find any reference to anyone else having faced this particular IE bug with floats. I've put a page at...
5
by: | last post by:
newbie code -------------------------- #include <iostream> using namespace std; #include <cstring> class aaa {
4
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an...
4
by: Joel Gordon | last post by:
Hi, When I try and compile the a class containing the following method : public void doSomething() { for (int i=0; i<5; i++) { IList list = new ArrayList(); Console.WriteLine( i /...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
11
by: efialtis | last post by:
Hi to all, I am creating a program which plays a game. The game is played on a NxN square board. In every position of the board we may have a ball or not. Take for example the following 5x5...
5
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a...
10
by: ypjofficial | last post by:
Hello All, since the programs' stack is shared among all the function inside the program, I was just doing some R&D to see whether the same stack space is used for the variables inside the...
6
by: lxu4net | last post by:
There's a huge hash table in my application. I use it as a main memory database. A lot of client write random data into the hash table, so it call a lot of malloc() / free(). But after it run for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.