473,569 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Spreading list contents across full width

Suppose I've got HTML with the following in it:

<ul class="navigati on">
<li><a href="chapter1. html" title="Chapter 1">Previous</a></li>
<li><a href="./">Contents</a></li>
<li><a href="chapter3. html" title="Chapter 3">Next</a></li>
</ul>

I'd like to style this such that all three links appear on the same
line, with Prev at the far left, Contents in the center, and Next at the
far right. I'm looking for three (possibly) different solutions, in
fact: (1) a solution according to CSS 2.1 specifications, even if no
browser supports it; (2) a solution that works in relatively compliant
browsers like Firefox; and (3) a solution that works in everything
(except maybe IE 5.5 for Mac!).

I don't want to alter the HTML, and the styling should work for other
pages in the same hyper-document.

No, this isn't a homework assignment! I was trying to do this a couple
of days ago, and I couldn't find anything that worked.

David
Stardate 6901.6
Nov 25 '06 #1
7 6303
David Trimboli wrote :
Suppose I've got HTML with the following in it:

<ul class="navigati on">
<li><a href="chapter1. html" title="Chapter 1">Previous</a></li>
<li><a href="./">Contents</a></li>
<li><a href="chapter3. html" title="Chapter 3">Next</a></li>
</ul>

I'd like to style this such that all three links appear on the same
line, with Prev at the far left, Contents in the center, and Next at the
far right. I'm looking for three (possibly) different solutions, in
fact: (1) a solution according to CSS 2.1 specifications, even if no
browser supports it; (2) a solution that works in relatively compliant
browsers like Firefox; and (3) a solution that works in everything
(except maybe IE 5.5 for Mac!).

Site navigation toolbar works without javascript support, without CSS
styling, with CSS support disabled.

<link rel="prev" href="chapter1. html" title="Chapter 1">
<link rel="contents" href="./" title="Contents ">
<link rel="next" href="chapter3. html" title="Chapter 3">

W3C Quality Assurance tips for webmasters: Use <link>s in your document
http://www.w3.org/QA/Tips/use-links

Link Bars: How Link Relations Are Implemented (slightly outdated)
http://webcoder.info/reference/LinkBars.html

Most webpages at mozilla.org implement <link>s that way. For an example:

http://www.gtalbot.org/NvuSection/Gu...uSection5.html

For Firefox extension:
https://addons.mozilla.org/firefox/2933/

Gérard
--
remove blah to email me
Nov 25 '06 #2
Gérard Talbot wrote:
Site navigation toolbar works without javascript support, without CSS
styling, with CSS support disabled.

<link rel="prev" href="chapter1. html" title="Chapter 1">
<link rel="contents" href="./" title="Contents ">
<link rel="next" href="chapter3. html" title="Chapter 3">
Er, well, yes, of course LINKs are good, but that's not what I'm asking
about. I'm looking for stying advice.

It doesn't have to be links. The question is just as valid if I wanted
to, say, have a Yes, No, and Maybe spread across one line:

<ul class="example" >
<li>Yes</li>
<li>Maybe</li>
<li>No</li>
</ul>

How would I get them all on the same line with the Yes on the far left,
the No on the far right, and they Maybe in the middle?

David
Stardate 6902.8
Nov 26 '06 #3
Suppose I've got HTML with the following in it:
>
<ul class="navigati on">
<li><a href="chapter1. html" title="Chapter 1">Previous</a></li>
<li><a href="./">Contents</a></li>
<li><a href="chapter3. html" title="Chapter 3">Next</a></li>
</ul>
Hi David,

I haven't got the *full* solution to this, however I have got something
that is fairly close without adding anything to your HTML.

Assuming the HTML above, I can get a rough version of what you want
that will work in IE6 and Firefox etc with the following stylesheet:

ul {
list-style:none;
display: block;
text-align: center;
margin: 0;
}

li {
display: inline;
width: 33%;
float: left;
}

Now this isn't the full solution as I stated because doing this gives
you white space to the left of "Prev" and to the right of "next" as
these items become centrally aligned within their own space. Also you'd
need to add some kind of clear after this or everything will try and
float around each other later on in the page.

However with the addition of a couple of attributes you can space the
left and right items out.

So your HTML would have to include an ID attribute for "prev" and one
for "next" and then the additional styles would just tweak the
alignment:

li#prev {
text-align: left;
}

li#next {
text-align: right;
}

This gives a pretty good approximation of what you are after though you
do have to add some extra attributes so isn't a "true" solution.

Which leads me to my final idea - using sibling selectors. This has
absolutely *NO* support in IE6 [and I'm not even certain whether this
works in IE7 - would be good to know actually if someone can test and
get back to us?].

I have tested this is FF1.5 and it works fine so I assume FF2 will be
cool too.

So we use the standard HTML you gave above, and the following
stylesheet:

ul {
display: block;
margin: 0;
}

li {
list-style: none;
display: inline;
width: 33%;
float: left;
}

li + li {
text-align: center;
}

li + li + li {
text-align: right;
}

So you can see that in the UL def, I can remove the text-align: centre
which now shifts everything back to the left of their containers. The
li+li selects the li that is next to an li already so this would select
the CENTRE and RIGHT LIs and apply center text alignment to them.

Finally the li+li+li selects the RIGHT LI element and because it has
higher specificity will override the text-align with a right alignment.

Whilst this has no IE support [response please if IE7 is good], it does
solve the question I think...

How's that? Any other ideas?

Cheers
AndrewF

Nov 26 '06 #4
AndrewF wrote:
>Suppose I've got HTML with the following in it:

<ul class="navigati on">
<li><a href="chapter1. html" title="Chapter 1">Previous</a></li>
<li><a href="./">Contents</a></li>
<li><a href="chapter3. html" title="Chapter 3">Next</a></li>
</ul>

ul {
list-style:none;
display: block;
text-align: center;
margin: 0;
}

li {
display: inline;
width: 33%;
float: left;
}
Aha! Float 'em /all/ to the left! That's the key I was missing! I'd
fiddled with floating .navigation:fir st-child to the left and
..navigation:fi rst-child + li + li to the right, but lack of support for
:first-child made it hard to test to see if I was on the right track.
(Firefox chose /every/ LI element as the first-child!) Floating
everything to the left and then text-aligning everything the way you
want makes much more sense.

[...]
So your HTML would have to include an ID attribute for "prev" and one
for "next" and then the additional styles would just tweak the
alignment:

li#prev {
text-align: left;
}

li#next {
text-align: right;
}

This gives a pretty good approximation of what you are after though you
do have to add some extra attributes so isn't a "true" solution.

Which leads me to my final idea - using sibling selectors. This has
absolutely *NO* support in IE6 [and I'm not even certain whether this
works in IE7 - would be good to know actually if someone can test and
get back to us?].

I have tested this is FF1.5 and it works fine so I assume FF2 will be
cool too.
It works find in Firefox 2.0. I haven't got IE 7 to test.
So we use the standard HTML you gave above, and the following
stylesheet:

ul {
display: block;
margin: 0;
}

li {
list-style: none;
display: inline;
width: 33%;
float: left;
}

li + li {
text-align: center;
}

li + li + li {
text-align: right;
}
[...]
How's that? Any other ideas?

Fantastic! Thanks, Andrew.

David
Stardate 6904.1
Nov 26 '06 #5
Hi David,

Glad I could be of help - very strangely, after doing all of this this
afternoon I was writing some code this afternoon for some page turning
nav and I've just lifted the lot.

I'm not sure what is going on with the :first-child selector in FF.
I've noticed that in 1.5 too, it seems to just use the same behaviour
as "element element" which in the case we're using above, gives you
all the LIs...

If someone is reading this and has IE7 it would be great for some
results posting as I'm not going to taint my dev machine *just* yet...

Cheers
AndrewF

Nov 26 '06 #6
In article <Tj************ ***@newsfe09.lg a>,
David Trimboli <da***@trimboli .namewrote:
>AndrewF wrote:
>>Suppose I've got HTML with the following in it:

<ul class="navigati on">
<li><a href="chapter1. html" title="Chapter 1">Previous</a></li>
<li><a href="./">Contents</a></li>
<li><a href="chapter3. html" title="Chapter 3">Next</a></li>
</ul>
...
>Aha! Float 'em /all/ to the left! That's the key I was missing! I'd
fiddled with floating .navigation:fir st-child to the left and
.navigation:fi rst-child + li + li to the right, but lack of support for
:first-child made it hard to test to see if I was on the right track.
(Firefox chose /every/ LI element as the first-child!)
...
Just as an aside, it looks as if you confused this and really should have
been trying '.navigation li:first-child' as 'navigation:fir st-child' will
match if the _ul_ is the first-child in its container.

John
--
John P Baker
Nov 27 '06 #7
JP. Baker wrote:
Just as an aside, it looks as if you confused this and really should have
been trying '.navigation li:first-child' as 'navigation:fir st-child' will
match if the _ul_ is the first-child in its container.
Oh! Thanks, I really did have that wrong. As you can tell, I was
thinking .navigation:fir st-child meant "match the first child of any
element with the class 'navigation.'"

I guess I really can reference each element individually, with

..navigation li:first-child
..navigation li:first-child + li
..navigation li:first-child + li + li

David
Stardate 6907.0
Nov 27 '06 #8

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

Similar topics

9
62521
by: puzzled | last post by:
I'm trying to use a small gif of a Christmas tree as a horizontal divider across the screen (which could be any number of pixels wide). My attempt at doing this was basically like this: <img alt="tree graphic (1k)" src="tree.gif" height="60" width="100%"> So I got a tree that looked like a funhouse mirror reflection - 60 pixels high,...
3
1579
by: Matthias Kaeppler | last post by:
Hello, this more a question about good practice than it is about the C++ language itself, but still... my question is this: I have a class representing the main window of my application which is really growing big. Well, most of the action is happening in the main window in my app so that's okay I guess. To solve the clutter, I thought...
19
4230
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
7
1840
by: David Laub | last post by:
I have stumbled across various Netscape issues, none of which appear to be solvable by tweaking the clientTarget or targetSchema properties. At this point, I'm not even interested in "solving" these problems - I'm more interested in isolating them, .i.e. finding a "complete" list of issues. Here's my list of serious issues found so far. By...
19
6928
by: JezB | last post by:
I have a DIV whose contents varies in size according to data. How can I size the DIV precisely to fit it's contents ?
3
3089
by: Brian Henry | last post by:
I have two list boxes on my form... lstCanSend and lstRecipients... well then there are two buttons add and remove between them (your basic select and pick listing) which uses java script to move the items between list boxes (the listbox controls are server side ones with runat=server set on them, the buttons are basic html button i dont want...
1
1705
by: Steve Richter | last post by:
I have a simple table with two columns. The first column contains 5 lines of text. The second column contains an iFrame. The iFrame in turn contains a web page. The problem is it does not display at all like I would like it to. I want the column height to expand to the contents of either column. Instead, since I guess the browser does not...
4
2256
by: volker | last post by:
Hi, I'm trying to move an iframe from one position in the DOM to another. The moving itself is not a problem at all, but I experience a different behaviour between Firefox (1.5) and IE (6): As soon as I insert the iframe somewhere else, in Firefox the contents get reloaded, whereas in IE the iframe remains as it is. The latter one is the...
0
7615
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
7924
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. ...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
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.