L8NIT3TR0UBL3
L8NIT3TR0UBL3

Reputation: 101

html drop down issues

ok so here goes. Im working on expanding my html, css, and javascript knowledge. To do this i began writing a few basic website designs (on a live server, but all made up and fake). On my most recent one, I've decided to go for dropdown menu's. To space this all properly i decided to go with a table element, and use some very basic (which is all i know right now) javascript. I am currently using a .dropdown and a .dropdown:hover to make my menus work. However since i used the table element, each time i "dropdown" my menu on my test page, the other menus titles resize to the size of the dropdown window. Any ideas how to combat this? heres my code....

CSS

    .dropdown ul {
        display: none
    }
    .dropdown:hover ul {
        display: block;
        background-color: white;
    }
    body {
        margin: 0;
        padding: 0;
        background: -moz-linear-gradient(AliceBlue, White);
        background: -webkit-linear-gradient(AliceBlue, White);
        background: linear-gradient(AliceBlue, White);
    }
    table {
        align: center;
        font-family: cursive;
        font-decoration: underline;
    }
    td {
        border: solid 1px Lavender;
        padding: 4px;
        margin-left: 6px;
        margin-right: 6px;
        cell-spacing: 6px;
    }
    h1 {
        font-size: 14px;
    }

HTML

<div style="text-align: center">
    <img src="http://satasurfer.byethost33.com/2/logo.jpg" height="150px" width="70%" align="center">
</div>
<table>
    <td class="dropdown">
        <h1>
        Search By Department
        <ul>
        <li><a href="FILLER">Computers and Laptops</a>
        <li><a href="FILLER">Computer Components</a>
        <li><a href="FILLER">Office Supplies</a>
        <li><a href="FILLER">Phones and PDAs</a>
        <li><a href="FILLER">Speakers and Audio</a>
        <li><a href="FILLER">Tablets and Ipads</a>
        </h1>
    </td>
    <td class="dropdown">
        <h1>
        Search by Company
        <ul>
        <li><a href="FILLER">ACER</a></li>
        <li><a href="FILLER">AMD</a></li>
        <li><a href="FILLER">APPLE</a></li>
        <li><a href="FILLER">BELKIN</a></li>
        <li><a href="FILLER">BOSE</a></li>
        <li><a href="FILLER">COBY</a></li>
        <li><a href="FILLER">DELL</a></li>
        <li><a href="FILLER">HP</a></li>
        <li><a href="FILLER">HTC</a></li>
        <li><a href="FILLER">JVC</a></li>
        <li><a href="FILLER">LG</a></li>
        <li><a href="FILLER">PANASONIC</a></li>
        <li><a href="FILLER">SAMSUNG</a></li>
        <li><a href="FILLER">SONY</a></li>
        </h1>
    </td>

Upvotes: 0

Views: 108

Answers (3)

nsthethunderbolt
nsthethunderbolt

Reputation: 2097

If you wish to use plain javascript. That should work fine.

<html>
<head>    
    <style type="text/css">


    body {
            margin: 0;
            padding: 0;
            background: -moz-linear-gradient(AliceBlue, White);
            background: -webkit-linear-gradient(AliceBlue, White);
            background: linear-gradient(AliceBlue, White);
        }

    table {
            align: center;
            font-family: cursive;
            font-decoration: underline;
        }

    td {
        border: solid 1px Lavender;
        padding: 4px;
        margin-left: 6px;
        margin-right: 6px;
        cell-spacing: 6px;
        }

    h1 {
        font-size: 14px;
        }   
.dd1,.dd2{display:none;}

    </style>

    <title>Discount Electronics</title>

</head>

<body>

    <div style="text-align: center">
    <img src="http://satasurfer.byethost33.com/2/logo.jpg" height="150px" width="70%" align="center">
    </div>

    <table>
<tr>
    <td onmouseover="fun('dd1')">    Search By Department</td>

    <td  onmouseover="fun('dd2')">    Search by Company</td>
</tr>
<tr><td>
<div class='dd1 dropdown'>
<h1>

    <ul>
    <li><a href="FILLER">Computers and Laptops</a>
    <li><a href="FILLER">Computer Components</a>
    <li><a href="FILLER">Office Supplies</a>
    <li><a href="FILLER">Phones and PDAs</a>
    <li><a href="FILLER">Speakers and Audio</a>
    <li><a href="FILLER">Tablets and Ipads</a>
    </h1>
</div>
</td>
<td>
<div class='dd2 dropdown'>
<h1>

    <ul>
    <li><a href="FILLER">ACER</a></li>
    <li><a href="FILLER">AMD</a></li>
    <li><a href="FILLER">APPLE</a></li>
    <li><a href="FILLER">BELKIN</a></li>
    <li><a href="FILLER">BOSE</a></li>
    <li><a href="FILLER">COBY</a></li>
    <li><a href="FILLER">DELL</a></li>
    <li><a href="FILLER">HP</a></li>
    <li><a href="FILLER">HTC</a></li>
    <li><a href="FILLER">JVC</a></li>
    <li><a href="FILLER">LG</a></li>
    <li><a href="FILLER">PANASONIC</a></li>
    <li><a href="FILLER">SAMSUNG</a></li>
    <li><a href="FILLER">SONY</a></li>
    </h1>
</div>
</td></tr>
</table>
<script type='text/javascript'>
function fun(cls){
var arr=document.getElementsByClassName('dropdown');
for(i=0;i<arr.length;i++)
{
arr[i].style.display='none';
}
document.getElementsByClassName(cls)[0].style.display='block'

}
</script>
</body>
</html>

Upvotes: -1

Jan Misker
Jan Misker

Reputation: 2149

You seem to have guessed it already: don't use table, besides being semantically incorrect (<table> is meant for tables with data) it gives you all kinds of other issues because of their default styling.

Use a straightforward (embedded) ul and position the sub menus absolute, make sure to make the top level menu items (li) position: relative; and display: inline-block; and it should be pretty straightforward from there.

Upvotes: 4

DasBeasto
DasBeasto

Reputation: 2282

One way to accomplish this is in you td {} style give a specific height such as 'height: 50px' and the float them 'float: left'. might not be the best option but it seems to accomplish it.

Upvotes: 2

Related Questions