CSS 文件链接在 PHP 页面上不起作用

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

CSS file link is not working on PHP page

phpcss

提问by arun thakur

I have a Php page the code for which is below, I am trying to apply this signup.css but its not working. In PHP admin I can see the CSS shows up under Styles as SignUp.css, I have just placed this css in my theme directory under my theme as SignUp.css, I have tried "Signup.css" , created a css folder and put this css in there and tried "css/SignUp.css" but that did not work either. Please help . Thanks for your time

我有一个 PHP 页面,其代码如下,我正在尝试应用此 signup.css 但它不起作用。在 PHP 管理中,我可以看到 CSS 在样式下显示为 SignUp.css,我刚刚将此 css 放在我的主题目录下作为 SignUp.css,我尝试了 "Signup.css" ,创建了一个 css 文件夹并放入这个css在那里并尝试了“css/SignUp.css”,但这也不起作用。请帮忙 。谢谢你的时间

<html>
<link href="Styles/Signup.css" media="all" rel="stylesheet" type="text/css"/>

    <head>
        <title>Create</title>
        </head>
<body>

<?php

if($_POST['action']=='create'){
    //include database configuration
    $dbhost = "localhost";
     $dbuser = "abc";
     $dbpass = "xyz";
     $dbname = "test";

     $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
     mysql_select_db($dbname) or die ('Unable to select database!');


    //sql insert statement
    $sql="insert into user ( firstname, lastname, username, Email, password )
            values ('{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['Email']}','{$_POST['username']}','{$_POST['password']}')"; 

    //insert query to the database
    if(mysql_query($sql)){
        //if successful query
        echo "New record was saved.";
    }else{
        //if query failed
        die($sql.">>".mysql_error());
    }
}
?>

<!--we have our html form here where user information will be entered-->
<div id="stylized" class="myform">
<form id="form" name="form" method="post" action="index.html">
<h1>Sign-up form</h1>


<label>Name
<span class="small"></span>
</label>
<input type="text" name="name" id="name" />

<label>Email
<span class="small"></span>
</label>
<input type="text" name="email" id="email" />

<label>Password
<span class="small">Min. size 6 chars</span>
</label>
<input type="text" name="password" id="password" />

<button type="submit">Sign-up</button>
<div class="spacer"></div>

</form>
</div>

</body>
</html>

回答by MichD

From you comments on existing answers, it doesn't look like something we could find out based on the provided code. Here are a couple of things that could help you diagnose the problem though.

从您对现有答案的评论来看,它看起来不像我们可以根据提供的代码找到的东西。不过,这里有几件事可以帮助您诊断问题。

In your browser, open up developer tools. (For Firefox, get Firebugand hit F12, For Chrome or Opera, just hit F12 for the built in tools.)

在浏览器中,打开开发人员工具。(对于 Firefox,获取Firebug并按 F12,对于 Chrome 或 Opera,只需按 F12 即可获取内置工具。)

Then you want to open up the network tab ('Net' in Firebug, 'Network' in Chrome)

然后你想打开网络选项卡(Firebug 中的“Net”,Chrome 中的“Network”)

Once you have that open, reload the page and look at the server requests. One of them will be for your CSS file. What you want to look for is the HTTP status. If that Status is anything starting with a 4, you've got trouble. Either it's a 403 which means you don't have the correct permissions to load the file, or you'll have a 404, as we all know, 'not found', which would indicate that your URL is faulty.

打开后,重新加载页面并查看服务器请求。其中之一将用于您的 CSS 文件。您要查找的是 HTTP 状态。如果该状态是以 4 开头的任何内容,那么您就有麻烦了。要么是 403,这意味着您没有正确的权限来加载文件,要么是 404,众所周知,“未找到”,这表明您的 URL 有问题。



Another way to quickly find out whether the file is actually loading is to view the source of the page in the browser, and click the link to the CSS file. In Firefox, doing that makes the source viewer load the contents of the CSS file instead. If that doesn't work out, you also get an idea that it can't be accessed. It's worth noting that the first method will make it clearer what exactly the issue is though.

另一种快速查明文件是否真正加载的方法是在浏览器中查看页面的源代码,然后单击指向 CSS 文件的链接。在 Firefox 中,这样做会使源代码查看器加载 CSS 文件的内容。如果这不起作用,您还会知道它无法访问。值得注意的是,第一种方法将更清楚地说明问题究竟是什么。

Most likely I assume you have a typo in your capitalisation of the file name or path. If it is hosted on a non-windows server, that almost certainly makes a difference.

我很可能认为您的文件名或路径的大小写有误。如果它托管在非 Windows 服务器上,那几乎肯定会有所不同。

回答by Jason Sebring

The <link> tag should be within your <head> tag, also consider using absolute "/" path rather than relative if you have sub directories.

<link> 标签应该在你的 <head> 标签内,如果你有子目录,也可以考虑使用绝对的“/”路径而不是相对路径。

回答by konsolenfreddy

Use an absolute Path for the stylesheet based on your website:

根据您的网站为样式表使用绝对路径:

<link href="/Styles/Signup.css" media="all" rel="stylesheet" type="text/css"/>

(Note the slash before Styles).

(注意前面的斜线Styles)。

Also, put the style within your <head>tags.

另外,将样式放在<head>标签中。