Html Bootstrap - 设置容器的背景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17098212/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:26:03  来源:igfitidea点击:

Bootstrap - Set the Background of a Container

htmlcsstwitter-bootstrap

提问by Hyman

So for example the picture below I'm having typing giving each class="container" it's separate background colour/picture.

因此,例如下面的图片,我正在输入每个 class="container" 它是单独的背景颜色/图片。

<div id="p" class="container">
</div>

style sheet

样式表

p.container {
     background-image: url(img/this_is_top.png) repeat;
}

CHANGING QUESTION for some reason I have having trouble in setting a background Image* for it.

出于某种原因更改问题我在为其设置背景图像* 时遇到问题。

enter image description here

enter image description here

回答by adaam

Regarding your background image problem you currently have

关于您目前遇到的背景图片问题

background-image: url(img/this_is_top.png) repeat;

This is wrong. But you are thinking of the background shorthand CSS property which follows this syntax:

这是错误的。但是您正在考虑遵循以下语法的背景速记 CSS 属性:

#p.container {background:#ffffff url('img/this_is_top.png') no-repeat center center;}

And if you are styling in your stylesheet and your folder hierarchy is the usual (/~/>/img etc) then it should be:

如果您在样式表中设置样式并且您的文件夹层次结构是通常的(/~/>/img 等),那么它应该是:

#p.container {
     background-image: #ffffff url('../img/this_is_top.png') repeat center center;
}

Notice the double dots before the url to tell CSS to look up a level for the img folder

注意 url 前的双点告诉 CSS 查找 img 文件夹的级别

回答by David Taiaroa

For starters, having multiple id's with the same name on the same page is not such a great idea. http://css-tricks.com/the-difference-between-id-and-class/

对于初学者来说,在同一个页面上有多个同名的 id 并不是一个好主意。http://css-tricks.com/the-difference-between-id-and-class/