Anonoymous
Anonoymous

Reputation: 142

CSS display block not working with anchor links

I am trying to make a dropdown-menu. So for this purpose, I've created a div and some anchor links inside, but the display: block; is not working. The cursor is default & the anchor does not seem to be a link.

Here is my HTML:

<div id="custom-wrapper">
    <ul>
        <li><a href="#">View full profile</a></li>
        <li><a href="#">Logout</a></li>
    </ul>
</div> 

The CSS:

div#custom-wrapper
{
    width: 200px;
    height: auto;
    position: fixed;
    right: 15px;
    top: 38px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid lightgrey;
}
div#custom-wrapper ul
{
    list-style-type: none;
}
div#custom-wrapper ul li
{
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
}
div#custom-wrapper ul li a
{
    text-decoration: none;
    display: block;
    color: grey;
    font-family: sans-serif;
    border-bottom: 1px solid lightgrey;
}

What's wrong with my code?

Upvotes: 1

Views: 3011

Answers (3)

Sayed Rafeeq
Sayed Rafeeq

Reputation: 1219

Display block element works perfect, Just you need to remove padding and margin for ul element.

 /*** Default CSS Attributes ***/
 #custom-wrapper ul {
    margin: 0;
    padding: 0;
 }

 /*** Overwrite CSS Attributes ***/
 #custom-wrapper ul {
    margin: 0 !important;
    padding: 0 !important;
 }

div#custom-wrapper {
    width: 200px;
    height: auto;
    position: fixed;
    right: 15px;
    top: 38px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid lightgrey;
}
div#custom-wrapper ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
div#custom-wrapper ul li {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
   }
div#custom-wrapper ul li a {
    text-decoration: none;
    display: block;
    color: grey;
    font-family: sans-serif;
    border-bottom: 1px solid lightgrey;
}
<div id="custom-wrapper">
    <ul>
        <li><a href="#">View full profile</a></li>
        <li><a href="#">Logout</a></li>
    </ul>
</div> 

Upvotes: 4

Arun Ghosh
Arun Ghosh

Reputation: 7744

There is a padding for ul. Remove it:

div#custom-wrapper ul
{
    list-style-type: none;
    padding:0;
}

Upvotes: 0

FDavidov
FDavidov

Reputation: 3675

That is not the right way to build a dropdown. Check this (you would need to include Bootstrap library though, which by the way may make your life much easier).

Upvotes: -1

Related Questions