简体   繁体   English

无法获取bg img做我想要的CSS

[英]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.

相关问题 CSS 无论我做什么,网格布局都无法按照我想要的方式进行布局 - CSS Grid layout can't get layout to behave the way I want no matter what I do 想要从容器复制url,然后将其用作bg,但我不能 - Want to copy url from container and then use it as bg but I can't 我无法获得此脚本来滚动更改IMG的CSS - I can't get this script to change the CSS of a IMG on scroll 我的<header>背景 img(也不是页脚 bg)的行为不符合预期,我该如何更改我的 HTML/CSS 来解决这个问题? - My <header> background img (nor footer bg) is not behaving as intended, how can I change my HTML/CSS to fix this? 似乎无法达到我想要的行距 - Can't seem to get line spacing to what I want 无论我尝试什么,HTML img都不会使用CSS调整大小 - HTML img won't resize with CSS, no matter what I try 在我的CSS中,即使我在bg img之后设置背景大小属性也无法正常工作? - In my CSS, background size property is not working properly, even if i set after bg img? CSS:无法:hover正常工作,我想念什么? - CSS: Can't get :hover to work, what am I missing? 拿不到<img>标题属性贴在<img>使用 jquery + css - Can't get <img> title attribute to stick under the <img> using jquery + css 为什么我无法正确插入Inline CSS(我希望Left和Right处于同一行) - Why can't I get the Inline CSS right (I want Left and Right same line)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM