Html 在每页 CSS 的顶部插入横幅图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21299263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inserting a Banner Image on Top of Every Page CSS
提问by user1404664
I am learning how to create a website and I have stumbled upon a problem I can't figure out. I want to place a banner on the top of every webpage page of the site, and I was wondering if this can be done using a .CSS. I have a background already on the .CSS but I can't seem to insert a picture properly on top. This is my code:
我正在学习如何创建一个网站,但我偶然发现了一个我无法弄清楚的问题。我想在网站的每个网页页面的顶部放置一个横幅,我想知道是否可以使用 .CSS 来完成。我已经有了 .CSS 的背景,但我似乎无法在顶部正确插入图片。这是我的代码:
hr {color:sienna;}
p {margin-left:20px;}
body {
background-image:url("pic2.png");
}
And then I would call it on every page like (the css file name is style.css):
然后我会在每个页面上调用它(css文件名是style.css):
<link rel="stylesheet" type="text/css" href="style.css">
回答by Nicholas Hazel
Like this...?
像这样...?
JS Fiddle: http://jsfiddle.net/SinisterSystems/Yd4d6/
JS小提琴:http: //jsfiddle.net/SinisterSystems/Yd4d6/
<div id="banner"></div>
<div id="content">
Hello world
</div>
#banner {
background:url('http://sweetclipart.com/multisite/sweetclipart/files/imagecache/middle/banner_white.png');
width:100%;
min-height:189px;
}
Or do you want it to dynamically apply the element to your page?
或者您希望它动态地将元素应用到您的页面?
For further insight, we need more data:
为了进一步了解,我们需要更多数据:
- Will your bannerbe static, that is, always the same size and same place?
- Will this show up on EVERY page, and do you want it just PLACED into the DOM?
- 您的横幅会是静态的,即始终保持相同的大小和相同的位置吗?
- 这会显示在每个页面上,您是否希望它只是放置在 DOM 中?
If you are trying to actually add elementsto your page, CSSonly allows to perform pseudo operationswith existing elements on your page.
如果您尝试向页面实际添加元素,CSS仅允许对pseudo operations页面上的现有元素执行。
回答by Andrew Liu
I found one syntax error in you codes.
我在你的代码中发现了一个语法错误。
you can use only either use
你只能使用任何一种使用
background-image:url("pic2.png");
background-repeat:repeat;
or
或者
background:url("pic2.png") repeat;

