PDA

View Full Version : CSS Menu???


jalves18
04-09-2003, 11:33 PM
I know absolutely nothing about CSS... go ahead call me lame... anyways what I want to accomplish is a menu in which I have some buttons across the top of my page and when you hover over them they do two things.

1. The button changes to a onhover button
2. A menu/list appears underneath the button with a list of links for the site.

If anyone has a simple way of doing this that I can edit easily please, please help me... Thanks in advance for your help.

cg9com
04-10-2003, 01:06 AM
as far as the dropdown stuff, your going to need javascript, todays CSS cant accomplish that.
to change say a button though, thats possible, again using javascript (possible with just CSS, but support is slim)
ive posted this a couple times in here.

<style type="text/css">
.button {
color:white;
}
.buttonover {
color:black;
}
</style>

<input type=button value=Button class=button
onmouseover="this.className='buttonover';"
onmouseout="this.className='button';" />


if you want a premade menu, you can check some free places like http://www.javascriptkit.com, or http://www.dynamicdrive.com.

and to learn CSS (do it! :D)
http://www.w3schools.com/css/

jkd
04-10-2003, 02:00 AM
Originally posted by cg9com
as far as the dropdown stuff, your going to need javascript, todays CSS cant accomplish that.

Say what? Sure it can.

http://www.meyerweb.com/eric/css/edge/menus/demo.html

Brothercake even has one of his own. :)

jalves18
04-10-2003, 02:41 AM
Okay.... well thats pretty close to what I am looking for but I want my buttons placed horizontally across the top with a menu that pops up when you hover over that particular button... any ideas???

jalves18
04-10-2003, 02:54 AM
Alright I found the following which does work but there are three things that need to be editted and I'm stumped...

Things to change:
1. position has to be underneath the button
2. button has to change onHover
3. I want the menu background to be a color but transparent

Here's what I got:

<style>
<!--

.menuskin{
position:absolute;
width:180px;
background-color:white;
border:2px solid black;
font:normal 12px verdana;
line-height:18px;
z-index:100;
visibility:hidden;
}

.menuskin a{
text-decoration:none;
color:black;
padding-left:10px;
padding-right:10px;
}

#mouseoverstyle{
background-color:orange;
}

#mouseoverstyle a{
color:black;
}

-->
</style>
<script language="JavaScript1.2">

var linkset=new Array()

linkset[0]='<div class="menuitems"><a href="Awards.htm">Awards</a></div>'
linkset[0]+='<div class="menuitems"><a href="#">History</a></div>'
linkset[0]+='<div class="menuitems"><a href="#">Locations</a></div>'
linkset[0]+='<div class="menuitems"><a href="MBE.htm">Minority Business</a></div>'
linkset[0]+='<div class="menuitems"><a href="#">News</a></div>'

linkset[1]='<div class="menuitems"><a href="#">Commercial Roofing</a></div>'
linkset[1]+='<div class="menuitems"><a href="#">Historic Restorations</a></div>'
linkset[1]+='<div class="menuitems"><a href="#">Maintenance & Service</a></div>'
linkset[1]+='<div class="menuitems"><a href="#">Sheet Metal Fabrication</a></div>'
linkset[1]+='<div class="menuitems"><a href="#">Waterproofing</a></div>'
linkset[1]+='<div class="menuitems"><a href="#">Licenses</a></div>'
linkset[1]+='<div class="menuitems"><a href="SafetyProg.htm">Safety Program</a></div>'

linkset[2]='<div class="menuitems"><a href="#">Current Projects</a></div>'
linkset[2]+='<div class="menuitems"><a href="#">Completed Projects</a></div>'
linkset[2]+='<div class="menuitems"><a href="#">List All</a></div>'

linkset[3]='<div class="menuitems"><a href="mailto:Mail@titanroofing.com">General E-Mail</a></div>'
linkset[3]+='<div class="menuitems"><a href="Contact-Form.htm">E-Mail Form</a></div>'
linkset[3]+='<div class="menuitems"><a href="Contact-Chicopee.htm">Chicopee Location</a></div>'
linkset[3]+='<div class="menuitems"><a href="Contact-Quincy.htm">Quincy Location</a></div>'
linkset[3]+='<div class="menuitems"><a href="Contact-Worcester.htm">Worcester Location</a></div>'
linkset[3]+='<div class="menuitems"><a href="mailto:webmaster@titanroofing.com?subject=Error On Titan Roofing, Inc. Site (Main Page)">Webmaster / Errors</a></div>'

var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function showmenu(e,which){

if (!document.all&&!document.getElementById&&!document.layers)
return

clearhidemenu()

menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=180 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
menuobj.document.close()
}

menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y

var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

if (rightedge<menuobj.contentwidth)
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX

if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility="visible"
return false
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}

function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
else{
while(source_el.id!="popmenu"){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
}
}
}

if (ie4||ns6)
document.onclick=hidemenu

</script>

jalves18
04-10-2003, 02:55 AM
that smiley should be ": orange"

cg9com
04-10-2003, 05:02 AM
Originally posted by jkd
Say what? Sure it can.
Thats not so nice to IE? :(

I figure JS is more common.

brothercake
04-10-2003, 10:05 AM
Originally posted by cg9com
Thats not so nice to IE? :(

I figure JS is more common.
It's not un-nice to IE; it just doesn't work - but you can make up for that with behaviors - http://www.brothercake.com/scripts/navmeister/page.php

JS is more common for menus at the moment, but pure JS menus are on the way out IMO; CSS or JS/CSS hybrid menus based on UL trees are fully accessible and semantically relevant to non javascript browsers :)

select sires
04-10-2003, 07:04 PM
Can a css menu target a div ?

similiar to a frame..

select sires
04-10-2003, 07:24 PM
new try (http://filebox.vt.edu/users/lkornhau/newtry.html)

that's the basic layout of the main page. I want to know if there is a way for the menu links to target the 'right' div, like it would work in a frames page.

I know css is just stylesheets, but i thought there would be some way of doing it, or maybe with a JS or something?

thank you for any help:thumbsup:

brothercake
04-10-2003, 07:28 PM
You can't "open a link in a div" like you can with windows.

But an <object> tag can source an external file for its contents, so you could do it by changing the href attribute through script.

select sires
04-10-2003, 07:58 PM
Ok great, that would definitely work.
Is there somewhere I can look to get an understanding of the <object > so I can use it properly?

jalves18
04-10-2003, 08:10 PM
That's all good and dandy but can anyone help me with my problem?