473,394 Members | 1,932 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,394 software developers and data experts.

floating lists to the right

Hi

I've tried a number of techniques but this one is causing me to wonder
whether I'm going to have to go back to using tables to solve this:

I want to have some text aligned to the left and then on the same line a
menu constructed with a horizontal unordered list. Also the page where they
sit resizes to fit the browser window. Here's the xhtml:

<div id="navwrap">
<div id="navright">
<ul>
<li><a href="/admin.asp">Admin</a></li>
<li><a href="/">Projects</a></li>
<li><a href="/file_list.asp">File Manager</a></li>
<li><a href="/change_password.asp">Change Password</a></li>
<li><a href="/logout.asp">Logout</a></li>
</ul>
</div>

<div id="navleft">
<div class="CurrentUser">
user details
</div>
</div>
</div>

CSS:

div#navwrap {
margin: 0;
padding: 4px 8px;
background: #ccc;
height: 18px;
}

div#navleft {
background: #ccc;
}

div#navleft div.CurrentUser {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #111;
font-size: 10px;
padding: 2px 0;
}

div#navright {
background: #ccc;
float: right;
width: 45%;
}

div#navright ul {
border: 0;
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
clear: left;
}

div#navright ul li {
display: block;
float: left;
text-align: center;
padding: 0;
margin: 0;
}

div#navright ul li a {
color: #000;
background: #ccc;
padding: 1px 6px;
border: 1px solid #ccc;
text-align: center;
text-decoration: none;
display: block;
line-height: 1.2em;
}

html>div#navright ul li a {
font-size: 11px;
}

div#navright ul li a:hover {
border-style: solid;
border-width: 1px;
border-color: #fff #333 #333 #fff;
}

div#navright a:active {
border-style: solid;
border-width: 1px;
border-color: #333 #fff #fff #333;
}

Because a floated element needs a width I give it a percentage. The menu is
constructed dynamically so I don't know what the exact width is so I can't
give it a width in pixels. Part of the problem seems to be with the
unordered lists. I have tried using div elements to wrap the menu buttons
but that doesn't seem to produce very good results and in any case it's not
very good structural xhtml in my opinion. Can anyone point me in the right
direction to help solve this problem?

Cheers
Andrew
Jul 20 '05 #1
3 2415
an************@orbnet.co.uk (Andrew) wrote:

[code snipped, an url would have been better]
Because a floated element needs a width
Currently yes, this is however an unnecessary restriction that is about
to be removed in css 2.1. It's still wise to assign a width to aid older
UAs like Opera 6, but you can get away with not specifying it in certain
circumstances.
The menu is
constructed dynamically so I don't know what the exact width is so I can't
give it a width in pixels.
Another method is to give it a width of "0", inline content will break
out of this zero width container, but older UAs like Opera 6 will still
be happy.
Part of the problem seems to be with the
unordered lists. I have tried using div elements to wrap the menu buttons
but that doesn't seem to produce very good results and in any case it's not
very good structural xhtml in my opinion. Can anyone point me in the right
direction to help solve this problem?


Align the list to the right by setting text-align:right on the container
div, and float the bit that should be positioned left.

Absolutely positioning the left aligned content with the containing div
set to display:relative is another method, but this doesn't work in IE.

--
Spartanicus
Jul 20 '05 #2
Hi

See url this time:
http://test.empetus.co.uk
Align the list to the right by setting text-align:right on the container
div, and float the bit that should be positioned left.


I've tried this but although I get the desired effect in IE5.x/6 Opera
still won't be persuaded to stretch the list out horizontally. I'm
testing with the latest version of Opera:

Version 7.23
Build 3227
Platform Win32
System Windows 2000

I have a regular need to display content aligned both left and right
on the same line so a reasonable fix for this is going to be very
useful and mean I can stop using 2 table columns everytime I need to
do this.

Thanks again
Andrew
Jul 20 '05 #3
an************@orbnet.co.uk (Andrew) wrote:
See url this time:
http://test.empetus.co.uk
Align the list to the right by setting text-align:right on the container
div, and float the bit that should be positioned left.


I've tried this but although I get the desired effect in IE5.x/6 Opera
still won't be persuaded to stretch the list out horizontally. I'm
testing with the latest version of Opera:


You need to nest the list and the left floated content in the same div.

One of my pages that uses a navbar with left and right alignment using a
list and float: http://www.pan-europe.utvinternet.ie/

--
Spartanicus
Jul 20 '05 #4

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

Similar topics

1
by: George Hester | last post by:
At the time this suggestion was made I didn't have the wherewithall to even attempt it. But over time I learned enough to make a stab at it. Let just say the foating DIV had to provide the same...
3
by: David Ross | last post by:
I sometimes place a sidebar on a Web page, using the following: ..sideright { float: right; background-color: #fff; width: 40%; font-size: 90%; text-align: justify; margin-left: 1em;...
2
by: Chris Gurk | last post by:
Hi Newsgroup, I am working on a website http://www.charter-yachtcharter.com/testsite/ (still in progress). There are two lists. The first is a simple paragraph (<p>-Tag), the second an...
1
by: James Walker | last post by:
Hi there, i'm having a problem when a list appears immediately after a floating div element... the bullet points or numbers appear behind the image in both IE and Firefox... i've tried wrapping the...
4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
12
by: meltedown | last post by:
I would like the floating divs to float and then the header to come after them , on the left. That's what I thought clearing the floats was for, but in this example, the header is to the right of...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
6
by: Harlan Messinger | last post by:
Please take a look at http://www.gavelcade.com/list_next_to_float.html How can I style a list so that if it appears next to a left-floated box as the first list does in this example, the list...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.