[英]Can't get bg img to do what I want in CSS
I have been reading forums all night & still can't figure this one out. 我整夜都在阅读论坛,但仍然无法弄清楚。
I want to have one of my divs as the background for everything else in my site. 我想将我的一个div作为我网站上其他所有内容的背景。 I also want it to start from a particular spot, ie it doesn't take up the whole page.
我也希望它从特定位置开始,即它不会占用整个页面。
This div (class the_background) is a child of my container div which is a child of the body, as follows: 该div(the_background类)是我的容器div的子级,它是主体的子级,如下所示:
head tag(Usual stuff in here)closing head tag 头标签(此处为常用物品)
<body>
<div class="container">
<div class="header">
<img src="images/open-access/header.png">
</div>
<br/>
<div class="signout">
login name | <a href="#">signout</a>
</div>
<br/>
<div class="menu">
<ul>
<li><a href="#">Bunch of links etc.</a></li>
</ul>
<div class="under_menu">
</div>
</div>
<div class="welcome">
Welcome, name!
</div>
<div class="the_background"></div>
etc. 等等
The following is the code for my external stylesheet: 以下是我的外部样式表的代码:
.container {margin:0 2em;
text-align: center;
position: relative;}
(bunch of code, and then:) (代码段,然后:)
.under_menu{background-color: rgb(141, 0, 212);
width:auto;
height: 1em;
padding-bottom: 0;}
.the_background{background-color: yellow;
background-image: url('images/bg.png');
width: auto;
height: 100%;
background-size: cover;
z-index: -10;
position: absolute;
left: 0;}
(bunch more code, etc.) (添加更多代码等)
What I eventually want (as I can't post images) is for the background image to begin at the bottom of the under_menu div, to occupy the same width as it too, and to continue for the rest of the length of the page. 我最终想要的(因为我无法发布图像)是使背景图像从under_menu div的底部开始,也要占据相同的宽度,并在页面的其余部分继续。 At the moment, the under_menu div is perfect- it goes across the whole page but for a small margin at each side (of 50%) and is a nice slim height of 1em.
目前,under_menu div很完美-它遍历整个页面,但每边的边距很小(为50%),并且高度仅为1em。
This code as I've currently copied it gives me nothing. 我当前复制的这段代码没有任何帮助。 Why on earth is that so???!!!
到底为什么呢? I have been playing with this ALL day, and managed to get either the yellow fallback colour or the background image to display at certain times, but I cannot for the life of me control its width or height.
我整天都在玩游戏,设法在某些时候显示黄色的备用颜色或背景图片,但是我一生无法控制它的宽度或高度。 I have tinkered with EVERY relevant property that I can identify!
我已经修补了所有我可以识别的相关财产! If someone could please help me I would be all kinds of grateful.
如果有人可以帮助我,我将不胜感激。 If someone could also please explain why the code I have pasted there doesn't work, that would be great too.
如果有人也可以解释为什么我粘贴的代码不起作用,那也很好。
Thank you very very much in advance!!! 提前非常感谢你!!!
ps yes I have been triple checking spelling & syntax etc. :/ ps是的,我一直在三遍检查拼写和语法等。:/
This one is tough without a good jsfiddle that includes your images. 如果没有包含您的图像的良好jsfiddle,这一点很难。 Could you please set that up for us?
您能为我们设置一下吗?
In the meantime, try this CSS: 同时,请尝试以下CSS:
.the_background {
background: yellow url('images/bg.png') 50% 0;
width: 100%;
height: 100%;
z-index: -10;
position: absolute;
left: 0;
top: 1em
}
Result: http://jsfiddle.net/jJxCs/ 结果: http : //jsfiddle.net/jJxCs/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.