[英]Only one of my CSS style sheets work and DIV background-image doesn't work?
First time coding my own website and first time uploading it. 第一次编写我自己的网站,然后第一次上传。 First time for everything basically.
基本上是第一次。 Yes, I have multiple CSS style sheets, some of my pages have different layouts.
是的,我有多个CSS样式表,我的某些页面具有不同的布局。
My website works perfectly on my local drive, but of course falls apart when I upload it to Host Gator via FileZilla. 我的网站可以在本地驱动器上正常运行,但是当我通过FileZilla将其上传到Host Gator时,它当然会崩溃。 I ensured that I followed case-sensitivity for my links/directories/images etc.
我确保我对链接/目录/图像等保持区分大小写。
I believe it's just my DIV background images on the index page that aren't loading properly and then the CSS style sheets aren't being applied to the rest of my website- yet it works for the homepage. 我相信只是索引页面上的DIV背景图像无法正确加载,然后CSS样式表未应用于我的网站的其余部分,但仍可用于主页。 I have confirmed the images are accessible when you type their url in directly.
我确认您直接输入网址时可以访问这些图片。
I have no idea why only my one css style sheet works and not the rest, and why my DIV background images aren't loading properly. 我不知道为什么只有一个css样式表可以工作,而其余的都不可以,为什么我的DIV背景图像无法正确加载。 Any advice is greatly appreciated, I just want my website to go live finally!
任何建议都将不胜感激,我只希望我的网站最终上线!
Feel free to have a look: www.alanphunt.com and let me know what you think. 随时查看:www.alanphunt.com,让我知道您的想法。 I've only taken a semester of an introductory web development course so go easy on me!
我只上了一学期的Web开发入门课程,所以轻松一点吧!
Most likely the problem is with relative and absolute path usage. 最可能的问题是相对和绝对路径使用情况。 Check if you can open the given CSS from the source code of the page.
检查是否可以从页面的源代码中打开给定的CSS。 If you cannot it means that your browser can't do it either.
如果不能,则表示您的浏览器也无法执行。 If you can, the CSS should be loaded.
如果可以,则应加载CSS。
This is a problem with connecting your CSS to HTML or paths, for sure. 毫无疑问,这是将CSS连接到HTML或路径的问题。 You should double check every path on your code, sometimes I paste things and forget to change the path, look out for that.
您应该仔细检查代码中的每个路径,有时我会粘贴一些东西而忘记更改路径,请加以注意。
As other answers have stated, the problem is the relative paths. 正如其他答案所述,问题是相对路径。
As for your specific question: on the home page, the background images images/alan.jpg
and images/seemennt.jpg
are set in an external stylesheet. 关于您的特定问题:在主页上,背景图像
images/alan.jpg
和images/seemennt.jpg
在images/seemennt.jpg
中设置。 Because the path doesn't begin with a forward slash, they'll try to load relative to the location of the stylesheet, in this case the "css" folder. 因为路径不是以正斜杠开头,所以它们将尝试相对于样式表的位置(在本例中为“ css”文件夹)进行加载。 (You can hit F12 in your browser and look at the console to confirm this. It'll also help to diagnose exactly what isn't loading.)
(您可以在浏览器中按F12键,然后在控制台上进行确认。这也将有助于准确诊断未加载的内容。)
Try changing the paths to something like ../images/alan.jpg
and it should work. 尝试将路径更改为
../images/alan.jpg
,它应该可以工作。
Are you using Google Chrome? 您在使用Google Chrome吗? If you are, head to:
如果是,请前往:
Here, you will be able to view the outputted HTML that your browser is using to display your website. 在这里,您将能够查看浏览器用来显示网站的输出HTML。
After looking through the Source code of your Homepage, I can see the following URL, for your Stylesheet: 浏览完首页的源代码后,我可以看到以下URL,用于您的样式表:
css/indexcss.css?v=version2
I selected this URL and it brings up your Stylesheet. 我选择了该URL,它调出了样式表。 I then checked out the source code of your other pages ('Photography', 'Music', 'DJ Life' and 'Reach Out'), and can see that your stylesheets have been incorrectly inputted.
然后,我签出了其他页面的源代码(“摄影”,“音乐”,“ DJ Life”和“ Reach Out”),然后可以看到您的样式表输入错误。 You need to perform the following changes:
您需要执行以下更改:
photography.css
to css/photography.css
photography.css
到css/photography.css
musiccss.css
to css/musiccss.css
musiccss.css
到css/musiccss.css
djcss.css
to css/djcss.css
djcss.css
到css/djcss.css
reachoutcss.css
to css/reachoutcss.css
reachoutcss.css
到css/reachoutcss.css
This should resolve your issue. 这样可以解决您的问题。
Best of luck with your website! 祝您网站运气佳!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.