ASP.Net MVC音乐商店教程CSS布局问题

时间:2011-06-06 19:12:48

标签: css asp.net-mvc

我刚刚完成了MVC tutorial,但我的部分网页看起来并不正确。这是我的:Screenshot of my webpage

但它应该是这样的:enter image description here

此页面的代码为:

@model MvcSuper.Models.MusicStore.Genre

@{ 
    ViewBag.Title = "Browse Albums"; 
} 

<div class="genre"> 
    <h3><em>@Model.Name</em> Albums</h3> 

    <ul id="album-list"> 
        @foreach (var album in Model.Albums) 
        { 
            <li> 
                <a href="@Url.Action("Details",  
                    new { id = album.AlbumId })"> 
                    <img alt="@album.Title"  
                        src="@album.AlbumArtUrl" /> 
                    <span>@album.Title</span> 
                </a> 
            </li> 
        } 
    </ul> 
</div>

左侧菜单(局部视图):

@model IEnumerable<MvcSuper.Models.MusicStore.Genre>
<ul id="categories"> 
    @foreach (var genre in Model) 
    { 
        <li>@Html.ActionLink(genre.Name, 
                "Browse", "MusicStore",  
                new { Genre = genre.Name }, null) 
        </li> 
    } 
</ul>

整个CSS:

{
    margin: 0px;
    padding: 0px;
    border: none;
}

body
{
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    background-color: #FBF9EF;
    padding: 0px 6%;
}

#container
{
    float: left;
}

#header
{
    float: left;
    width: 100%;
    border-bottom: 1px dotted #5D5A53;
    margin-bottom: 10px;
}

#header h1
{
    font-size: 18px;
    float: left;
    background: url(/content/Images/logo.png) no-repeat;
    padding: 45px 0px 5px 0px;
}

#promotion
{
    height: 300px; 
    width: 700px; 
    background: url(/content/Images/home-showcase.png) no-repeat;
}

ul li a
{
    font-size: 16px;
}

#main
{
    overflow: hidden;
    padding: 0 0 15px 10px;
    float: left;
}

ul
{
    list-style-type: square;
    margin-left: 25px;
    font-size: 14px;
}

ul#album-list
{
    list-style: none;
    margin-left: 0px;
}

ul#album-list li
{
    height: 130px;
    width: 100px;
    float: left;
    margin: 10px;
    text-align: center;
}

ul#album-list li a, ul#album-list li .button
{
    font-size: 13px;
    float: left;
}

ul#album-list li a span
{
    color: #9b9993;
    text-decoration: underline;
}

#cart
{
    float: right;
}

#update-message
{
    color: #F6855E;
    font-weight: bold;
}

.button, input[type=submit]
{
    clear: both;
    display: inline-block;
    padding: 5px;
    margin-top: 10px; 
    border: 1px;
    background: #5e5b54;
    color: #fff;
    font-weight: bold;
}

.button a
{
    color: #fff !important;
}

#footer
{
    clear: both;
    padding: 10px;
    text-align: right;
    border-top: 1px dotted #8A8575;
    border-bottom: 1px dotted #8A8575;
    font-family: Constantia, Georgia, serif;
}

/******************** Top Navigation ************************/
ul#navlist
{
    float: right;
}

ul#navlist li
{
    display: inline;
}

ul#navlist li a
{
    border-left: 1px dotted #8A8575;
    padding: 10px;
    margin-top: 10px;
    color: #8A8575;
    text-decoration: none;
    float: left;
}

ul#navlist li:first-child a
{
    border: none;
}

ul#navlist li a:hover
{
    color: #F6855E;
}

/********************* End top navigation ***************************/

p
{
    margin-bottom: 15px;
    margin-top: 0px;
}

h2
{
    color: #5e5b54;
}

h2, h3
{
    margin-bottom: 10px;
    font-size: 16px;
    font-style: italic;
    font-weight: bold;
}

h3
{
    color: #9B9993;
}

#header h1 a, h3 em
{
    color: #5E5B54;
}

a:link, a:visited
{
    color: #F6855E;
    text-decoration: none;
    font-weight: bold;
}

a:hover
{
    color: #333333;
    text-decoration: none;
    font-weight: bold;
}

a:active
{
    color: #006633;
    text-decoration: none;
    font-weight: bold;
}

/***************************** sidebar navigation ****************************/

#categories
{
    font-family: Constantia, Georgia, serif;
    list-style-type: none;
    border-right: #5d5a53 1px dotted;
    padding-right: 10px;
    margin: 0 25px 0 0;
    float: left;
}

#categories a:link, #categories a:visited
{
    color: #9B9993;
    text-decoration: none;
}

#categories a:hover
{
    color: #F46739;
}

div#album-details p
{
    margin-bottom: 5px;
    color: #5e5b54;
    font-weight: bold;
}

p em
{
    color: #9b9993;
}

/* Form styles */
legend
{
    padding: 10px;
    font-weight: bold;
}

fieldset
{
    border: #9b9993 1px solid;
    padding: 0 10px;
    margin-bottom: 10px;
    clear: left;
}

div.editor-field
{
    margin-bottom: 10px;
}

input[type=text], input[type=password], select
{
    border: 1px solid #8A8575;
    width: 300px;
}

/* Styles for validation helpers */
.field-validation-error {
    color: #ff0000;
}

.field-validation-valid {
    display: none;
}

.input-validation-error {
    border: 1px solid #ff0000;
    background-color: #ffeeee;
}

.validation-summary-errors {
    font-weight: bold;
    color: #ff0000;
}

.validation-summary-valid {
    display: none;
}

/* Tables */
table
{
    border: 1px solid #000;
    border-collapse: collapse;
    color: #666666;
    min-width: 500px;
    width: 100%;
}

tr
{
    border: 1px solid #000;
    line-height: 25px;
}

th
{
    background-color: #9b9993;
    color: #000;
    font-size: 13px;
    text-align: left;
}

th, td
{
    padding-left: 5px;
}

tr:hover
{
    background-color: #fff;
}

我确实下载了源代码(作者的完成版本),当我运行时它就像我的一样。最顶级的截图来自XP上的FF4,但它在XP上的IE8中看起来是一样的。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

将相册列表推回到正确的位置,让您放心......

为主css类添加宽度:

#main
{
    overflow: hidden;
    padding: 0 0 15px 10px;
    float: left;
    width: 500px;
}

还向第一个css类添加*

*{
    margin: 0px;
    padding: 0px;
    border: none;
}

答案 1 :(得分:1)

放轻松。我很确定这是特定浏览器或一些额外棘手的CSS代码的情况,仅此而已。确保你理解教程所说的所有内容并让屏幕保持原样