W3C home > Mailing lists > Public > www-amaya@w3.org > January to March 2005

CSS box calculations when a float is involved

From: John Russell <ve3ll@rac.ca>
Date: Sun, 16 Jan 2005 12:26:59 -0500
To: www-amaya@w3.org
Message-ID: <41EA5D93.16844.A258F5@localhost>
I am trying to do menus with lists instead of tables ;-] ;-] 
The first level requires a horizontal listing so i applied 
float:left to these items --- display lines up items ok 
but when i applied a background and/or a border on the
containing ul, i found that the width of the ul ran to right margin!
Shouldn't the ul box be the width of the containing elements
unless otherwise defined ???

i have included a small demo example for your consideration! 

perhaps there is a better way to get horizontal alignment then
using float but i tried display:inline and that does not allow 
nested lists to position correctly !!   
john russell ve3ll@rac.ca [those are L's as in LLAMA]

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>MenuBar Test: VE3LL@RAC.CA</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
body {background:#deadff;margin:20px}
ul {background:#ffdead;
    margin:0px; border:1px solid black; padding:0px}
li {list-style:none; float:left; font-weight:bold; width:120px;
    margin:0px; border:1px solid black; padding:10px}
em {font-weight:bold}
<h1>MenuBar Test: VE3LL@RAC.CA</h1>
   <li>HTML Stuff</li>
   <li>Java Brews</li>
<p>There are some styling problems with these few simple rules
in <em>every</em> browser tested. The only unusual rule was
float to line up the list items horizontally!</p>
<p><em>Amaya</em> does not compute the size of the containing ul
correctly! Its border continues too far to the right!</p>
<p><em>FoxFire, mozilla, NetScape, Opera and Slimbrowser</em> do not
respect ul background and continue the floats outside of the li and
ul boxes! Placing a clear rule on the following element helps.</p>
Received on Sunday, 16 January 2005 17:17:26 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:53:31 UTC