Jquery 背景图像:url(“images/plaid.jpg”)不重复;不会出现
我似乎无法将我的plaid.jpg作为任何页面的背景,更不用说所有页面了,我已经尝试通过body、html、*“home”的特定id来选择它。什么都不管用。图像为300 x 421像素。我不需要它表现得漂亮,我只想它表现出来,在一切的背后。我的css将如何寻找这个?plaid.jpg图片与index.html文件位于同一目录下的my images文件夹中。此链接位于我的index.html文件的顶部。我的样式表位于名为mystyles.css的样式表文件夹中Jquery 背景图像:url(“images/plaid.jpg”)不重复;不会出现,jquery,css,background,stylesheet,Jquery,Css,Background,Stylesheet,我似乎无法将我的plaid.jpg作为任何页面的背景,更不用说所有页面了,我已经尝试通过body、html、*“home”的特定id来选择它。什么都不管用。图像为300 x 421像素。我不需要它表现得漂亮,我只想它表现出来,在一切的背后。我的css将如何寻找这个?plaid.jpg图片与index.html文件位于同一目录下的my images文件夹中。此链接位于我的index.html文件的顶部。我的样式表位于名为mystyles.css的样式表文件夹中 <link rel="styl
<link rel="stylesheet" type="text/css" href="stylesheets/mystyles.css">
index.html
<body>
<!-- Page: home -->
<div id="home"
data-role="page"
data-title="Home">
<div data-role="header"
data-position="fixed"
data-theme="b">
<h1>Home</h1>
<a href="#info"
data-icon="info"
data-iconpos="notext"
data-rel="dialog"
class="ui-btn-right"
>Info</a>
</div><!-- header -->
<div data-role="content">
<div data-role="controlgroup" data-theme="e">
<a href="#blog"
data-role="button"
data-icon="arrow-r"
data-theme="e"
>Blog</a>
<a href="#videos"
data-role="button"
data-icon="arrow-r"
data-theme="e"
>Videos</a>
<a href="#photos"
data-role="button"
data-icon="arrow-r"
data-theme="e"
>Photos</a>
<a href="#tweets"
data-role="button"
data-icon="arrow-r"
data-theme="e"
>Tweets</a>
</div><!-- links -->
</div> <!-- content -->
</div><!-- page -->
这也是我的想法
<head>
<meta charset="utf-8" />
<title>Mob App</title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="shortcut icon" href="images/favicon.ico" />
<!--<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />-->
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="javascripts/myscript.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheets/mystyles.css" />
</head>
移动应用程序
如果CSS文件中只有这些内容,那么是的,不会发生任何事情。您需要一个选择器,即使它像body
一样简单:
body {
background-image: url(...);
}
试试这个:
body
{
background:url("images/plaid.jpg") no-repeat fixed center;
}
jsidle示例:您可以使用:
background-image: url("images/plaid.jpg");
background-repeat: no-repeat;
。。。或
background: transparent url("images/plaid.jpg") top left no-repeat;
。。。但肯定不是
background-image: url("images/plaid.jpg") no-repeat;
编辑:使用绝对路径在进行演示(以防您无法使用相对路径引用图像)。最重要的
background-image: url("images/plaid.jpg") no-repeat;
请记住,相对URL是从样式表的URL解析的
因此,如果文件夹images
位于stylesheets
文件夹中,它将起作用
根据您的描述,您需要将其更改为
url("../images/plaid.jpg")
或
附加1 此外,您不能没有选择器 CSS通过选择器应用
额外2个 您应该使用速记
background
这样传递多个值
background: url("../images/plaid.jpg") no-repeat;
或单独指定每个属性的详细语法
background-image: url("../images/plaid.jpg");
background-repeat:no-repeat;
您可以使用两种方式进行调试:
<style>
background: url(images/Untitled-2.fw.png);
background-repeat:no-repeat;
background-position:center;
background-size: cover;
</style>
背景:url(images/Untitled-2.fw.png);
背景重复:无重复;
背景位置:中心;
背景尺寸:封面;
浏览器控制台中有任何内容吗?如果您的CSS不工作,请检查以确保您的HTML和CSS有效。控制台中没有错误。当我查看源代码时,它会看到我的.css文件,因此它的链接正确。@codeyb检查控制台与验证不同。你知道什么会很有趣吗?如果背景图像正在加载,但由于主体
已完全折叠,而其所有子对象都处于浮动状态(没有clearfix)或绝对位置,因此您无法看到它。一切都很重要。在你发现问题之前,切掉所有看起来不属于问题一部分的细节。这就是调试的方式。背景颜色
和背景位置
是完全可选的(透明
和左上
是这些属性的值,如果没有指定)@cimmanon:同意。我只是想说明一下速记的全部特性,我给了他们两个人一个机会,但都没有成功。另一张海报说不要使用url(“images/plaid.jpg”),而是使用url(“images/plaid.jpg”),我尝试了这些方法,总共有4种变体。我不知道该相信什么,我的plaid.jpg文件在根目录下的images文件夹中,也就是与index.html相同的位置,而我的.css文件在同一根目录下的stylesheets文件夹中。因此其链接并查看文件,只是拒绝遵守选择器和样式。我还尝试将plaid.jpg文件放在stylesheets文件夹中,并更改.css文件中的路径确保您知道图像的确切位置,否则使用绝对路径。我使用了绝对路径,但没有成功“”如果我将图像放入浏览器,它会显示该图像,但当我使用绝对路径作为背景图像的位置时,它不会显示该图像作为背景。更改为此,它仍然无法工作体{background image:url(“/images/plaid.jpg”);background repeat:no repeat;}我也使用选择器,但我没有包括任何选择器,因为我使用了15-20,写下所有的变量并不重要。body或html应该在其最通用的形式中充当选择器,但我不知道它如何知道它们的维度是什么。我还将plaid.jpg文件放在我的样式表文件夹中,并将路径更改为/stylesheets/plaid.jpg,但它也不起作用。它不允许我编辑我以前的post@codeyb当你给出一个异常不完整的样本时,每个人都会期望得到最坏的结果(特别是当你说没有选择器时)。我们需要足够的信息来知道你没有犯完全错误。我声明这是我的css文件中减去选择器的内容,我使用了所有可能的选择器。我首先尝试了第一种技术,我如何设置img的高度和宽度,以便.css接受它?我试过在photoshop cs6中编辑它。第一个技巧是调试mystyles.css是否包含正确的路径。你必须试试第二种技巧,它很快。您可以在frebug中设置图像路径、设置图像高度和宽度。
background-image: url("../images/plaid.jpg");
background-repeat:no-repeat;
<style>
background: url(images/Untitled-2.fw.png);
background-repeat:no-repeat;
background-position:center;
background-size: cover;
</style>