Wednesday, April 13, 2011

html css in asp.net mvc default project

The default code shows the Home menu item aligned to the right. I changed the ul:menu and added attribute float:left to get the 'Home' menu too be aligned to the left of the page but to no avail.

Is there way to show the 'home' menu to be on the left end of the page. I am trying to create a menu bar similar to SO as a learning project

From stackoverflow
  • its a CSS issue but in site.css you can make following changes:

    #menucontainer
    {
        margin-top:40px;
        clear: both; /* Add this*/
    }
    
    and also
    
    ul#menu
    {
        border-bottom: 1px #5C87B2 solid;
        padding: 0 0 2px;
        position: relative;
        margin: 0;
        text-align: left; /* Change from right to left */
    }
    

    Work for this Site.Master

    <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <asp:ContentPlaceHolder ID="head" runat="server">
            <title></title>
        </asp:ContentPlaceHolder>
        <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    </head>
    
    <body>
        <div class="page">
            <div id="header">
                <div id="title">
                    <h1>My MVC Application</h1>
                </div>
                <div id="logindisplay">
                    <% Html.RenderPartial("LogOnUserControl"); %>
                </div> 
                <div id="menucontainer">
                    <ul id="menu">              
                        <li><%= Html.ActionLink("Home", "Index", "Home")%></li>
                        <li><%= Html.ActionLink("About", "About", "Home")%></li>
                    </ul>
                </div>
            </div>
            <div id="main">
                <asp:ContentPlaceHolder ID="MainContent" runat="server" />
                <div id="footer">
                </div>
            </div>
        </div>
    </body>
    </html>
    
    Claus Thomsen : the "clear: both;" is the key

0 comments:

Post a Comment