Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Link Padding Clickable

The padding around the link for my dropdown menu isn't clickable. When I mouse over the actual text, it changes color and becomes clickable. How can I make the padding clickable? I read that I should style it as an inline-block, but that didn't work. This is also my first post, so correct me for the countless things that I probably did wrong. CSS:

    body {
  font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  padding: 20px 50px 150px;
  font-size: 13px;
  text-align: left;
  background-position:center;
  background-image:url(sun.jpg);
}
a {
    display:inline-block;
    color: #6FF;
    text-decoration: none;
}
a:hover {
    color: #FFF;
}
ul {
    color:#6FF
  text-align: left;
  display: inline-block;
  margin: 0;
  padding: 1px 1px 1px 0;
  list-style: none;
}
ul li {
    color: purple;
  font: bold 12px/18px sans-serif;
  display: inline-block;
  margin-right: -10px;
  position: relative;
  padding: 20px 20px;
  background: #fff;
  cursor: pointer;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
  -ms-transition: all 0.5s;
  -o-transition: all 0.5s;
  transition: all 0.5s;
}
ul li:hover {
  background: #555;
  color: #fff;
}
ul li ul {
  padding:0;
  position:absolute;
  top: 54px;
  left: 0;
  width: 150px;
  display: none;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.5s;
  -moz-transition: opacity 0.5s;
  -ms-transition: opacity 0.5s;
  -o-transition: opacity 0.5s;
  -transition: opacity 0.5s;
}
ul li ul li { 
  background-color:#555;
  color:#6FF; 
  display: block; 
}
ul li ul li:hover { background: #555; }
ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
}
like image 473
Aerish Avatar asked Mar 16 '23 13:03

Aerish


1 Answers

You should put the padding to the link, no the list item because the link is what is clickable.

    body {
        font-family:'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
        padding: 20px 50px 150px;
        font-size: 13px;
        text-align: left;
        background-position:center;
        background-image:url(sun.jpg);
    }
    a {
        padding: 20px 20px;
        display:inline-block;
        color: #6FF;
        text-decoration: none;
    }
    a:hover {
        color: #FFF;
    }
    ul {
        color:#6FF text-align: left;
        display: inline-block;
        margin: 0;
        padding: 1px 1px 1px 0;
        list-style: none;
    }
    ul li {
        color: purple;
        font: bold 12px/18px sans-serif;
        display: inline-block;
        margin-right: -10px;
        position: relative;
        background: #fff;
        cursor: pointer;
        -webkit-transition: all 0.5s;
        -moz-transition: all 0.5s;
        -ms-transition: all 0.5s;
        -o-transition: all 0.5s;
        transition: all 0.5s;
    }
    ul li:hover {
        background: #555;
        color: #fff;
    }
    ul li ul {
        padding:0;
        position:absolute;
        top: 54px;
        left: 0;
        width: 150px;
        display: none;
        opacity: 0;
        visibility: hidden;
        -webkit-transiton: opacity 0.5s;
        -moz-transition: opacity 0.5s;
        -ms-transition: opacity 0.5s;
        -o-transition: opacity 0.5s;
        -transition: opacity 0.5s;
    }
    ul li ul li {
        background-color:#555;
        color:#6FF;
        display: block;
    }
    ul li ul li:hover {
        background: #555;
    }
    ul li:hover ul {
        display: block;
        opacity: 1;
        visibility: visible;
    }
<ul>
    <li><a href="#">First link</a>
    </li>
    <li><a href="#">First link</a>
    </li>
    <li><a href="#">First link</a>
    </li>
    <li><a href="#">First link</a>
    </li>
    <li><a href="#">First link</a>
    </li>
    <li><a href="#">First link</a>
    </li>
</ul>
like image 101
aleksandar Avatar answered Mar 24 '23 19:03

aleksandar