Html 为什么我不能在标题中缩放此图像?

Html 为什么我不能在标题中缩放此图像?,html,css,header,background-image,Html,Css,Header,Background Image,我是HTML/CSS新手,我正在尝试我迄今所学的东西 我有一个标题设置,但我想在标题内的背景图像。无论我做什么,我都无法使图像在标题中处于比例。它要么是平铺的,要么太大,以至于我看不到标题中的图像 以下是我目前的工作代码: <style> header { text-align: center; font-family: 'Permanent Marker', cursive; color: #AA1166; max-h

我是HTML/CSS新手,我正在尝试我迄今所学的东西

我有一个标题设置,但我想在标题内的背景图像。无论我做什么,我都无法使图像在标题中处于比例。它要么是平铺的,要么太大,以至于我看不到标题中的图像

以下是我目前的工作代码:

<style>
header {
        text-align: center;
        font-family: 'Permanent Marker', cursive;
        color: #AA1166;
        max-height: 500px;
        background-image: url("http://i.imgur.com/8ClzWQ5.jpg");
        background-repeat: no-repeat;
        background-size: cover;
再说一次,我是新手,所以可能我正在尝试完成一些我还没有学会正确代码的事情。有人能帮我照点光吗?

您缺少高度属性

我希望标题中有背景图像

请检查下面的代码

<style type="text/css">
header {
text-align: center;
font-family: 'Permanent Marker', cursive;
color: #AA1166;
background-image: url("http://i.imgur.com/b6y6Xvb.jpg");
background-repeat: no-repeat;
background-size: cover;
background-color: #666;
width:960px;
height: 200px;
margin: 0 auto;
}
你可以这样做

header {
   background: url(http://i.imgur.com/8ClzWQ5.jpg) no-repeat center center fixed; 
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
   background-size: cover;
   text-align: center;
   font-family: 'Permanent Marker', cursive;
   color: #AA1166;
   min-height:300px;
   max-height: 500px;
} 
请参见下面的代码

header {
        text-align: center;
        font-family: 'Permanent Marker', cursive;
        color: #AA1166;
        height: 500px;
        background-image: url("http://i.imgur.com/8ClzWQ5.jpg");
        background-repeat: no-repeat;
        background-position: center top;
        background-size: 100% auto;
}

你做得对,你应该澄清你的问题,你到底期望什么?例如,也可以尝试将背景位置更改为顶部,看看是否有帮助。你最好使用一个与标题元素比例相同的矩形图像。我下载了一张400x310的照片,我希望看到整个照片都在标题中,但是,它只显示部分内容或平铺。这是学习的第3天,所以我不确定我的第一个问题是能否在页眉内缩放照片……它是否包含您要查找的内容?