Forum Moderators: not2easy

Message Too Old, No Replies

Long side menu bars and vertically centering text in big anchors

more problems with side menus in css

         

grahamstewart

3:21 am on Mar 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I'm building a site for a local hospital, using HTML4.01 Strict and CSS for style and layout. I've implemented a left sidebar menu but I have two problems with it:

1) I want all the menu 'buttons' (really just stylised <A>'s) to be the same height, but this means n the buttons with a single line of text that the text sits at the top of the button - how can I get the text to appear in the center? (i.e. centered vertically)

2) the menu only fills the window. If the main body text is long enough that it needs to scroll then it reaches below the bottom of the menu and wraps around it. How can I make the menu height equal 100% of the page (rather than 100% of the window)?

<snip>

Thanks for your help,

GrahamS

[edited by: Nick_W at 8:39 am (utc) on Mar. 8, 2003]
[edit reason] no urls please [/edit]

SethCall

7:02 am on Mar 8, 2003 (gmt 0)

10+ Year Member



I tried playing with paddings, margins, and top properties, but I simply could not devise an a perfect solution.

I suppose the best thing I could come up with (without resorting to container divs: which ruin your hover effect)

is to make padding: 10px 0px; (or whatever you want for a reasonable border around your text) and to remove your height specifier.

This creates slightly varying sized "buttons", but I can't really think of much else right now ;)

DrDoc

10:42 am on Mar 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is an attribute for aligning text vertically: vertical-align
However, it doesn't quite work for vertical menus. I agree with Seth.

Also, about your other question: how to extend the navigation. I guess you're using a div for the navigation, right?
Well, you can always "fake" that the menu extends.

For the navigation div, set z-index to, say, 60. Create a new div, and give it the following styles:

position: absolute;
bottom: 0px;
left: 0px;
z-index: 55;
height: 100%;
width: (same as width of nav div);

Apply background too, if applicable. This will cause a div, with the same color and width, to reside behind your navigation div at all times.

Is the navigation floated left then? Maybe you can position it instead, and apply a right padding to the page?

grahamstewart

1:02 pm on Mar 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



D'oh.. apparently I shouldn't have posted URLs.. sorry again Nick.

Basically my CSS looks like...


div.sitebody {
padding-top: 30px;
}
#sitemenu {
float: left;
padding-top: 30px;
color: #ffffff;
background-color: #0800ce;
margin-right: 10px;
text-align: center;
width: 124px;
height: 100%;
}
#sitemenu div.menuborder {
border-top: 1px solid #000070;
border-bottom: 1px solid #0000f0;
}
#sitemenu a {
color: #efefff;
background-color: transparent;
font-family: Verdana, Arial, sans-serif;
font-size: 70%;
font-weight: bold;
display: block;
text-decoration: none;
border-top: 1px solid #0000f0;
border-left: 1px solid #0000f0;
border-bottom: 1px solid #000070;
border-right: 1px solid #000070;
padding: 2px 5px 2px 5px;
margin: 0px;
height: 30px;
}
#sitemenu a:hover {
color: white;
background-color: #0000a6;
text-decoration: none;
}

and the HTML looks something like this...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Test Layout</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" media="all" href="menu_example.css" type="text/css">
</head>

<body>

<div id="sitemenu">
<div class="menuborder">
<a href="404.html">Welcome</a>
<a href="404.html">Information for Patients</a>
<a href="404.html">Visiting Friends and Family</a>
<a href="404.html">Maps and Directions</a>
<a href="404.html">Meet the Doctors</a>
<a href="404.html">About the Hospital</a>
<a href="404.html">Contact Us</a>
</div>
</div>

<div class="sitebody">
<h1>Welcome</h1>
<p>blah</p>
</div>
</body>
</html>

So the problems are that the menu items that appear on one line are not centered within the anchor (which is displayed as a block). but the more important problem is that if there is a lot of text in the sitebody (e.g. extend 'blah' to be a lot more text) then the menu doesn't go all the way down.

SethCall: Yeah, I got as far as the padding as well. A reasonable solution but I'd prefer the menu buttons to be the same height as possible - and I'd prefer not to specify the menu font size as an absolute value since i'd like it to respond to changes in text size properly.

DrDoc: setting height to 100% means it is only as tall as the window. But that's not good if the sitebody goes off the bottom of the window - I want the menu to be as big as the site body and at least as tall as the window.

Thanks for your help,

GrahamS

DrDoc

1:32 pm on Mar 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The height:100% wasn't for the #sitemenu div. It's for a "fake extended sitemenu".

Again, try positioning the #sitemenu and #sitebody divs (absolute positioning)

Add a new div (call it whatever you want) and give it the styles in my previous post. :)

SethCall

4:09 pm on Mar 8, 2003 (gmt 0)

10+ Year Member



you really want this look? Make <img>'s to look like you want. Wouldn't be hard ... ;)

SuzyUK

5:12 pm on Mar 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Graham..

re: the 2 column layout
a tip here would be to make your whole page have the blue background, then make your content section have a white background with a margin-left to clear the menu and padding as required.

Suzy

grahamstewart

4:01 am on Mar 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrDoc: Hmm.. the trouble with using absolute positioning is that I'd need to specify the font-size for the menu as an absolute value as well. Otherwise if the user increases the font size (by using the 'View->Text Size' option in IE for instance) then the menu will get wider and overwrite the site body.
Floating it (as I'm doing at the moment) avoids this problem... but clearly leads to others ;)

SuzyUK: yeah.. that could be a solution, but it makes it harder to put any kind of nice background in the menu bar (the real version of this has a nice 'rolled edge' effect on the right side) and again it requires the menu to be a set width.

Seth: Using images means users wouldn't be able to increase the size of the text on the menu. Plus it would mean using Javscript for the rollovers.

Perhaps I just need to accept some compromise here. The reason I'm trying so hard to allow users to choose font size is its a hospital website and it needs to be as accessible as possible. I also intend to offer multiple stylesheets (big text, high contrast and all that).

Thanks again

GrahamS

grahamstewart

4:11 am on Mar 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrDoc: Just tried your solution but it still only makes the menu as big as the window.. not as big as the full page (in IE6 and Opera7). What I need is a way to make the menu at least as big as the window, but bigger if the sitebody extends off the bottom.