473,587 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSS: width for <li>

Hi!

li
{
display: inline;
}

<li>foo bar</li>
<li>blah</li>

This make both list item to appear next to another rather then from top
to bottom. However, I want both to have the same width. Setting width in
the above CSS doesn't so the job.

What am I going to do here?

Timo
Jul 20 '05 #1
3 69266
Timo Nentwig wrote:
Hi!

li
{
display: inline;
}

<li>foo bar</li>
<li>blah</li>

This make both list item to appear next to another rather then from top
to bottom. However, I want both to have the same width. Setting width in
the above CSS doesn't so the job.
That's because the width property doesn't apply to non-replaced inline
elements.

<URL:http://www.w3.org/TR/REC-CSS2/visudet.html#pr opdef-width>

What am I going to do here?


Either:

li {
display: table-cell;
width: 10em;
}

....or:

li {
display: block;
width: 10em;
float: left;
}

The former doesn't work in Internet Explorer, the latter may require a
cleared element following it in the flow.

By the way, this is a stylesheet question, which is better off in the
<URL:news:comp. infosystems.www .authoring.styl esheets> newsgroup.
Crossposted, followups set.
--
Jim Dabell

Jul 20 '05 #2

"Timo Nentwig" <tc*@spamgourme t.org> wrote in message
news:c4******** *****@ID-18956.news.uni-berlin.de...
Hi!

li
{
display: inline;
}

<li>foo bar</li>
<li>blah</li>

This make both list item to appear next to another rather then from top
to bottom. However, I want both to have the same width. Setting width in
the above CSS doesn't so the job.

What am I going to do here?

Timo


Width has no affect on inline elements. You could remove the display: inline
and add this to your stylesheet:

li {
float: left;
width: x /* whatever width you need */
}

Regards,
Jim Roberts
Jul 20 '05 #3
Jim Roberts:
Width has no affect on inline elements. You could remove the display: inline
and add this to your stylesheet: li {
float: left;
width: x /* whatever width you need */


Finding "whatever width you need" is however not a trivial matter, since
the element contains text, and you can never know how much space text
will actually take (no matter how much you try to control its size).

So you'd better specify the width in "em" units using a bit more than
you seem to need.

--
Bertilo Wennergren <be******@gmx.n et> <http://www.bertilow.co m>
Jul 20 '05 #4

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

Similar topics

5
9239
by: toylet | last post by:
Attached is some css codes for a website. It has 3 parts: top-bar, side-bar (on the left) and main-body. The top-bar has a mouseover menu called top-menu implemented via ul:hover. When the mouse pointer hovers over the top-menu, the bottom margin of the top-bar expands downwards. How could I make the hover menu to stack on top of the...
4
9527
by: Matt | last post by:
Hi, Got an unordered list with 100% width, with 5 list items of 20% width styled to fill the width of the container element. Renders fine in Mozilla, but when you change the size of the window in IE, the last item in the list has a nasty tendency to wrap down to the next line (and stay there). I can hack it (imperfectly) by setting the...
2
7626
by: Shaun | last post by:
Hello! I have a quick question regarding CSS and having it applied to all elements. I am trying to eliminate the gap between a paragraph and a list that usually occurs in html and I've found away to do that with this code: <p>a</p> <ul style="margin-top: -20; padding-top: 0"> <li>1</li>
5
4474
by: Syl | last post by:
Hello experts!! The top menu navigation bar displays perfectly in IE, but does not display properly in Mozilla or Netscape : http://checkeredshirt.com/textonly.html For some reason the non-IE browers are forcing the top navigation menu to dislpay "staggered" after the the first <ul><lielement. Can anyone see why this is happening ?
2
5958
by: mike_newsgroups | last post by:
Hello everyone, Anyone know how can I change the 30px below to a different value from a javascript function? <table> <tr> <td> <div id="star-rating"> <ul>
10
6245
by: BobaBird | last post by:
When <liis set to {max-width:45em;}, the bullets move from the top to the bottom of the <li>. Also, the bullet for a top-level <liends up on the same line as the last <liof its nested list, with both disc and circle bullets on that line. The problem is in IE7. The page displays as expected in FF 2.0.0.9. Is there a way to make IE7 behave?...
2
7048
by: GloStix | last post by:
For some reason, FF likes to put a black underline on all my buttons. No matter what I do, it has the line I've tried displaying as block and cursor, anything.. Also I've been trying to get it so the entire block is clickable, not just the text. I've sorta got it so it's clickable, just some parts of the button I still can't click on. The...
2
5598
dlite922
by: dlite922 | last post by:
Before you baulk at yet another min-width problem, hear me out. I've been googling for a good hour now and experimenting but at no avail. I have a horizontal UL/LI menu and I want the li width to be at least a certain amount (say 100px) but also extend if the text is longer than that. Observe: that being said, I don't know how...
1
3721
by: Chinsu | last post by:
<html> <head> <style> #ex { width: 700px; background: red; float: left; } a, span { display: block;
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.