Contact

DotNetNuke Tips for Skinning, CSS, and Design

Ralph Williams Blog

Feb 25

Written by: Ralph Williams
Thursday, February 25, 2010 11:19 PM  RssIcon

When I first started using DotNetNuke, it was somewhere in version 3.x. Learning this new system was a bit of a challenge at the time. Probably my biggest issue was the core, SolPart menu. I had so much trouble with it. Not much later our company switched to the RadMenu by Telerik, and I never looked back for about 4 years. That is, until I was working on my skin for the DotNetNuke Design Challenge. I wanted to use the core menu and did some digging to find a post on the DotNetNuke forum (see Jan Olsmar’s post) discussing how it can be rendered as an unordered list. You can also check out the blog post by Mike Van der Meulen “New CSS Menu Features In DotNetNuke 5”. This blog gives a nice description on the available attributes and class names which I will be referring to in my style sheet.

DotNetNuke Menu as an Unordered List

Half of the Battle

Okay, getting the menu to show up as an unordered list is great! But, that just means you get an ugly bulleted list of your menu. Enter Css. We can make our bulleted list look just like a normal menu. As a matter of fact, this is the accepted, or should I say, expected way to display a website’s menu.

On to the how to:

Setting up the DNN Menu as an unordered list:

  1. In your skin file (I tend to work in the .ascx file directly, not sure if will work the same as HTML) you need to add the register tags for the menu and the CustomAttribute.
    <%@ Register TagPrefix="dnn" TagName="NAV" Src="~/Admin/Skins/nav.ascx" %>
    <%@ Register TagPrefix="dnn" Namespace="DotNetNuke.UI.Skins" Assembly="DotNetNuke" %>
  2. Next, add the menu. Make sure to specify the “csscontrol”, as this will make sure that we style only our main menu and not all menus, including the Module dropdown menus.
    <dnn:NAV runat="server" id="dnnNav" csscontrol="mainMenu" IndicateChildren="false" ProviderName="DNNMenuNavigationProvider">
    </dnn:NAV>
  3. Now we need to render it as an unordered list. Add the CustomAttributes and it will look like this:
    <dnn:NAV runat="server" id="dnnNav" csscontrol="mainMenu" IndicateChildren="false" ProviderName="DNNMenuNavigationProvider">
        <CustomAttributes>
            <dnn:CustomAttribute Name="RenderMode" Value="UnorderedList" />
        </CustomAttributes>
    </dnn:NAV>

This will get us an unordered list like this:

  • Home
  • About
  • Services
    • Services 1
    • Services 2
  • FAQ’s
  • Contact

As we mentioned earlier, this is only half of the battle.

Styling the DotNetNuke menu unordered list:

The first thing that we will need to do, is to style it to not appear as a list.
  1. Set the display to block.
    .mainMenu .root {
        display:block; /* converts to block element */
    }
  2. The next thing will be to stack them side by side. Add a float left.
    .mainMenu .root {
        display:block; /* converts to block element */
        float:left; /* float left */
    }
  3. The third thing is to remove the bullets from the list.
    .mainMenu .root {
        display:block; /* converts to block element */
        float:left; /* float left */
        list-style:none; /* removes bullets */
    }
Next, we will style the actual links of the menu. By setting our paddings and sizes with the links, it ensures that the menu will not have dead spots on mouseover.
  1. Set the all links on the menu to be box elements by setting the display to block. We can also set the text color and remove the underline.
    .mainMenu .mi a{ 
        display:block; /* converts to block element */
        color:#FFF; /* text color */
        text-decoration:none!important; /* removes underline in links */
    }
  2. Next, we will set the main menu settings.
    .mainMenu .root a{
        font-size:18px; /* text size for menu */
        padding:16px 30px; /* gives padding around link */
    }
  3. Set the text hover color.
    .mainMenu .root a:hover{
        color:#D2B1A4; /* hover text color */
    }
We will now style the dropdown submenu.
  1. Make the submenu not stack side by side by removing the float. Set the background color of the dropdown.
    *Note: this is not the same as clearing a float.
    .mainMenu .m{
        float:none; /* removes float */
        background:#000!important; /* dropdown background color */
    }
  2. Set the sub menu settings.
    .mainMenu .m a{
        font-size:13px; /* font size for submenu text */
        padding:7px 10px; /* gives padding around link */
    }
  3. Set the hover background color.
    .mainMenu .m a:hover{
        background:#333; /* hover background color */
    }
  4. One last thing is to make sure the that icons on the submenu, such as the Admin and Host submenus, don’t bump up against the text.
    .mainMenu .m img{
        padding-right:5px; /* adds padding to right of menu icon on dropdown */
    }

Here is the full code for the css that you will place in your skin.css.

Tags:
Categories: Skinning

4 comment(s) so far...


Gravatar

Re: Rendering the DotNetNuke Menu as Unordered List & Styling It

Thanks Ralph, that's nice and clear.

By BarryS on   Thursday, March 11, 2010 5:18 PM
Gravatar

Re: Rendering the DotNetNuke Menu as Unordered List & Styling It

Thanks for this, Ralph. It helped immensely. I'm having trouble getting the .icn class to work (trying to display a bg image)in dnn 5.3.1. How would you go about referencing it? I've tried:

.mainMenu .m .icn, .mainMenu .m a .icn, .mainMenu .m a.icn, .mainMenu .m .bc .icn, .mainMenu .icn, .mainMenu li.icn, .mainMenu li .icn{width: 10px;background:#ccc url('images/arrow-gray.gif') no-repeat center center;}

Nothing works. Would really appreciate any ideas. Thanks in advance

By Jeff on   Thursday, June 24, 2010 2:28 PM
Gravatar

Re: Rendering the DotNetNuke Menu as Unordered List & Styling It

Hi,

That looks like just what I want (thanks for the reply to my question on the DNN forum pointing me here)

Except that when I try your code for the menu control I get the following style attribute on every li element: style="display: inline; list-style: none outside none;"

Given this is an inline element style I cannot override it from the stylesheet so I cannot get the menu items to have display block (or even to appear as an unordered list). I therefore assume you didn't have this inline style attribute? Any ideas where it has come from and how to get rid of it?

By Adam on   Wednesday, July 28, 2010 9:05 AM
Gravatar

Re: Rendering the DotNetNuke Menu as Unordered List & Styling It

Hey Adam,

I am glad this was helpful. I don't know why it would be adding the inline elements to your code. I have a working example of it with my 2010 DNN Skinning Contest entry Reasonable Design. See a live example here and download it here.

As much as I try to avoid it, you could always add an "display:blog!important;" to your CSS to override the inline styles.

By Ralph Williams on   Wednesday, July 28, 2010 9:19 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

Send me a message.

Name:*
Email Address:*
Message:*
Security Code:
CAPTCHA
Enter the code shown above in the box below
* required Submit   Cancel