2

Small question on how to achieve some styling on a HTML / CSS UL menu.

I have a standard UL menu, but having some issues getting my head around how to achieve a certain look to the styling. The UL menu as it currently stands is shown here:

http://jsfiddle.net/WMQqt/

(HTML)

<ul id="nav">
    <li><a href="#">CONTACT US</a>
    </li>
    <li><a href="#">HOME</a>
    </li>
</ul>

(CSS)

#nav {
    list-style: none;
    margin-bottom: 10px;
    */ margin-top: -6px;
    position: relative;
    right: 286px;
    z-index: 9;
    height: 26px;
    padding: 4px 4px 4px 4px;
    font-weight: bold;
}
    #nav li {
    float: right;
    margin-right: 10px;
}

#nav a {
    display: block;
    padding: 5px;
    color: #444444;
    background: #fff;
    text-decoration: none;
    border: 1px solid grey;
}

#nav a:hover {
    color: #fff;
    background: #04B431;
}

I'd like the menu buttons to have a small 1px border, but then some white space padding of around 3px before the background color starts.

Similar to how this looks:

http://jsfiddle.net/6PY7z/

Can this be done using the UL menu method?

Thanks for any advice, I'm no expert with HTML / CSS.

1
  • Just apply border to LI and background to A (as you did with DIVs). Commented Mar 15, 2013 at 11:21

3 Answers 3

5

Add margin to a tag and move border to li

#nav li
{
    float: right;
    margin-right: 10px;

    border: 1px solid grey;
}

    #nav a
    {
        display: block;
        padding: 5px;
        color: #444444;
        background: #ccc;
        text-decoration: none;
        margin:3px;    
    }

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much - I am still learning and fail to spot these things sometimes. Appreciate the explanation.
@Harry u r welcme and all the best
2

you can use the following styles to achieve what you want:

#nav li
{
    float: right;
    margin-right: 10px;
border: 1px solid grey; /*put original border here*/
}

#nav a
{
    display: block;
    padding: 5px;
    color: #444444;
    background: #d8d8d8; /*new background-color*/
    text-decoration: none;  
    border: 3px solid white; /*add white padding here*/
}

http://jsfiddle.net/WMQqt/4/

Comments

0

ok

in html go

<dl><div><dt>F</dt><dd>T</dd></div>
     <div><dt>F</dt><dd>T</dd></div>
     <div><dt>F</dt><dd>T</dd></div>
     <div><dt>F</dt><dd>T</dd></div>
</dl>

in css

dl { display: flex;
flex-direction: column;}

some hints...

dt float left AND dd float right

1 Comment

The description list <dl> tag has a different semantic meaning than the <ul> tag. These should not be used interchangeably and you do not explain in your answer why you recommend a <dl>, not how it would solve OP's question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.