【问题标题】:My background image is not fully extended when i adjust my browser当我调整浏览器时,我的背景图像没有完全扩展
【发布时间】:2015-03-16 07:46:29
【问题描述】:

我的标题使用背景图片,当我调整浏览器时,它不会完全扩展。我希望我的背景看起来像extalia.net。这是它的图片:

这是我的导航和标题的 HTML 代码

<nav>
    <div id="nav-container">
        <ul>
            <li class="select"><a href="">Home</a></li>
            <li><a href="">Gallery</a></li>
            <li><a href="">Song</a></li>
            <li><a href="">About</a></li>
            <li><a href="">Login</a></li>
            <li><a href="">Register</a></li>
        </ul>
    </div>
</nav>
<header>
    <div id="header-container">
        <div class="header-container-left">
            <img src="pic/logo2.gif">
        </div>
        <div class="header-container-right">
            <h1>This is my first photoshop web design :)</h1>
            <button class="header-button">More info <3</button>
        </div>
    </div>
</header>

这是我的css

nav{
    width: 100%;
    height: 50px;
    background-color: #54598f;
}

#nav-container{
    width: 1200px;
    height: 50px;
    margin: 0 auto;
    background-color: #54598f;
}

#nav-container li, a{
    display: inline-block;
    text-decoration: none;
    color: white;
    font-family: 'agentorange';
    font-size: 17pt;
    margin-right: 10px;
    line-height: 50px;
    text-align: center;
}

.select a{
    color: white;
    background-color: #363a60;
    padding-left: 15px;
    padding-right: 15px;
}

/*header*/

header{
    width: 100%;
    height: 250px;
    background: url('../pic/header.jpg') center;
}

#header-container{
    width: 1200px;
    height: 250px;
    margin: 0px auto;
}
.header-container-left{
    width: 270px;
    height: 250px;
    float: left;
    margin-top: 30px;
}

.header-container-right{
    width: 930px;
    height: 250px;
    margin-left: 280px;
    padding-top: 33px;
}
.header-container-right h1{
    font-family: 'agentorange';
    font-size: 18pt;
    color: white;
}
.header-button{
    border-radius: 10px;
    background-color: rgb( 54, 58, 95 );
    box-shadow: 2.5px 4.33px 5px 0px rgb( 0, 0, 0 );
    width: 220px;
    height: 50px;
    border: none;
    font-size: 16pt;
    color: white;
    font-family: 'agentorange';
    margin-top: 20px; 
}

【问题讨论】:

  • 尝试在 .header 类上设置 background-size:100%。

标签: html css


【解决方案1】:

我建议使用 SVG 图像。
虽然您可以让浏览器缩放 jpeg、png、gif 等。
SVG 是按比例制作的。

浏览器的传统图像缩放会引入图像失真并减慢页面加载时间。

CSS 缩放在这里被“覆盖”:Automatically resize images with browser size using CSS

【讨论】:

  • 哇,这正是我需要的:D
【解决方案2】:

我的小提琴:http://jsfiddle.net/8s74zfvw/

<nav>
    <div id="nav-container">
        <ul>
            <li class="select"><a href="">Home</a></li>
            <li><a href="">Gallery</a></li>
            <li><a href="">Song</a></li>
            <li><a href="">About</a></li>
            <li><a href="">Login</a></li>
            <li><a href="">Register</a></li>
        </ul>
    </div>
</nav>
<header>
    <div id="header-container">
        <div class="header-container-left">
            <img src="http://lorempixel.com/250/200/sports/">
        </div>
        <div class="header-container-right">
            <h1>This is my first photoshop web design :)</h1>
            <button class="header-button">More info <3</button>
        </div>
    </div>
</header>

CSS:

header{
    width: 100%;
    height: 250px;
    background: url('http://lorempixel.com/400/300/nature/') center;
    background-size:cover;
}

在小提琴中查看详细信息。

【讨论】:

    【解决方案3】:
    <div id="header-container">
       <div class="header-container-left">
          <img src="test.jpg">
       </div>
    

    你是&lt;div class="header-container-left"&gt;,宽度为:270px; 这就是问题所在。因此,即使您为图像提供 100% 的宽度,它也只会继承其父级的宽度,在本例中为 &lt;div class="header-container-left"&gt;。

    所以要么让父级:&lt;div class="header-container-left"&gt; width: 100% 或者只是将图像上一级,使其成为.header-container 的直接子代,如下所示:

    看看这个小提琴:http://jsfiddle.net/yux2jr1n/6/ 选项 1 看看这个小提琴:http://jsfiddle.net/yux2jr1n/6/ 选项 2

    如果您需要更多帮助,请告诉我。 干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 2013-04-19
      • 2020-08-10
      相关资源
      最近更新 更多