【问题标题】:Menu outside container / Background image vertical stretch容器外菜单/背景图像垂直拉伸
【发布时间】:2013-08-19 04:22:17
【问题描述】:

我在周末的大部分时间都在尝试解决这个问题,但我似乎无法做到这一点,我网站的基础知识已经完成,但有两件事:

  • ul.nav 适合所有按钮,但是,10-15 像素区域突出到左侧。离开 ul.nav。 (我使用的是 MS 表达式 web 4,它用对角红线标记。它会阻止菜单正确对齐,更糟糕的是,它会导致一个菜单按钮在以 1024*768 浏览网站时下降到其他菜单按钮下方。:-(

  • 容器 div 的背景图片(代码中称为“Div”)不会垂直拉伸,而是会重复自身。它会以这种方式产生烦人的线条。有没有办法让它伸展?

非常感谢您的建议。代码如下。

HTML:

<body>

<div id="container">
<div id="masthead" class="masthead" 
onclick="window.location.href='Index.html'"; style="cursor:pointer"></div>
<div id="top-nav" >     
        <ul class="nav">
            <li><a href="#"> Europe </a></li>
            <li><a href="ContentNA.html"> N. America </a></li>
            <li><a href="#"> S. America </a></li>
            <li><a href="#"> Asia </a></li>
            <li><a href="#"> Africa </a></li>
            <li><a href="#"> Australia </a></li>
            <li><a href="#"> Misc </a></li></ul>
            </div>
<br />
<br />
<div id="message">
<br clear="all" />
</div>

</body>

</html>

CSS

body {
background-size: 100% 100%;
background-position: center center;
font-family: sans-serif;
font-size: medium;
font-weight: normal;
font-style: normal;
font-variant: normal;
background-color: #FFFFFF;
padding: 0px;
margin: 0px;
body: ;
background-image: url('BG_MP.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
}
div {
border-radius: 15px;
border-width: 5px;
border-style: none;
width: 70%;
margin: 50px auto 10px auto;
padding: 10px;
background-image: url('parchment.jpg');
background-size: 100%;
left: auto;
right: auto;
}
#masthead {
border-radius: 15px;
background: transparent;
height: 220px;
width: 650px;
background-image: url('masthead.jpg');
background-repeat: no-repeat;
}
#top-nav {
height: 71px;
background : transparent;
list-style : none;
margin-top : 7px;
margin-bottom : 11px;
background-repeat: no-repeat;
text-align: center;
}
ul.nav {
border-radius: 15px;
background : transparent;
height : 57px;
line-height : 31px;
list-style : none;
font-size : 14px;
font-weight: bolder;
display: inline-block
}
ul.nav li {
display : inline;
padding : 0;
background : transparent;
}
ul.nav a {
font: 100%;
background: transparent;
height : 30px;
font-size : 12px;
color: #000000;
float : left;
padding: 11px 8px 11px 8px;
text-decoration : none;
border-top: 1px solid #252525;
border-bottom : 4px solid #252525;
border-left : 1px solid transparent;
border-right : 1px solid transparent;
border-radius : 4px;
-moz-border-radius : 4px;
-webkit-border-radius: 4px;
}
ul.nav a:hover {
background : #252525;
border-top : 1px solid #252525;
border-bottom : 4px solid #000;
border-left : 1px solid #252525;
border-right : 1px solid #252525;
color : #FFF;
padding : 11px 8px 11px 8px;
border-radius : 4px;
-moz-border-radius : 4px;
-webkit-border-radius: 4px;
}
#message {
background: transparent;
left: auto;
right: auto;
text-align: center

}

【问题讨论】:

    标签: image menu background alignment stretch


    【解决方案1】:

    要解决额外的 10-15px 间距问题,请将 padding:0; 添加到 ul.nav

    至于div的重复背景,在body中加入两行你曾经做同样的事情:将background-repeat: no-repeat; background-attachment: fixed;添加到div的CSS

    jsFiddle with the implemented changes

    【讨论】:

    • 感谢您对此进行调查,但不幸的是它不起作用。我仍然需要某种填充。我只是尝试在任何地方调整填充,但它不会修复它。
    • 使用您提供的确切代码,仅将padding:0; 添加到ul.nav 确实消除了额外的间距as seen in this jsfiddle。如果您的项目中仍有间距,那是由于您没有提供其他代码
    • 我复制/粘贴了 jsfiddle 代码,现在它可以工作了。不知道怎么样,但我很高兴。 :-) 谢谢 Zeaklous。
    猜你喜欢
    • 1970-01-01
    • 2016-03-26
    • 2017-04-22
    • 2017-10-12
    • 2011-11-12
    • 2020-01-31
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多