【发布时间】:2020-09-19 08:26:29
【问题描述】:
大家。我正在按照教程创建注册和登录系统,我是第一次这样做。我无法为 PHP 文件中的 HTML 表单设置样式。我只有一个文件夹,里面有 6 个文件(error.php、index.php、login.php、register.php、server.php、style.css) 到目前为止,我刚刚在 register.php 和 style.css 文件中编写了代码。 我从 register.php 文件中的控制台获取此消息: 1-“样式表http://localhost/registration/register.php/style.css 被加载为 CSS,即使它的 MIME 类型“text/html”不是“text/css”。”
2-“由于选择器错误,规则集被忽略。”
怎么了?我正在使用 XAMPP
这是代码:
注册.php:
<?php
include('server.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Registration system PHP and MySQL</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Register</h2>
</div>
<form method="post" action="register.php">
<?php
include('errors.php');
?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php
echo $username;
?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php
echo $email;
?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn" name="reg_user">Register</button>
</div>
<p>
Already a member? <a href="login.php">Sign in</a>
</p>
</form>
</body>
</html>
style.css:
* {
margin: 0px;
padding: 0px;
}
body {
font-size: 120%;
background: #F8F8FF;
}
.header {
width: 30%;
margin: 50px auto 0px;
color: white;
background: #5F9EA0;
text-align: center;
border: 1px solid #B0C4DE;
border-bottom: none;
border-radius: 10px 10px 0px 0px;
padding: 20px;
}
form, .content {
width: 30%;
margin: 0px auto;
padding: 20px;
border: 1px solid #B0C4DE;
background: white;
border-radius: 0px 0px 10px 10px;
}
.input-group {
margin: 10px 0px 10px 0px;
}
.input-group label {
display: block;
text-align: left;
margin: 3px;
}
.input-group input {
height: 30px;
width: 93%;
padding: 5px 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid gray;
}
.btn {
padding: 10px;
font-size: 15px;
color: white;
background: #5F9EA0;
border: none;
border-radius: 5px;
}
.error {
width: 92%;
margin: 0px auto;
padding: 10px;
border: 1px solid #a94442;
color: #a94442;
background: #f2dede;
border-radius: 5px;
text-align: left;
}
.success {
color: #3c763d;
background: #dff0d8;
border: 1px solid #3c763d;
margin-bottom: 20px;
}
【问题讨论】:
-
您是否尝试将
href="style.css"替换为href="./style.css",您必须将css 指向与您的php 文件相同的目录 -
Van Tho,同样的结果。
-
href="/registration/style.css"怎么样 -
Van Tho,成功了,非常感谢。为什么这有效?
-
因为你的css文件在文件夹注册中,而不是
registration/register.php/style.css,一般./style.css会起作用,但是这种情况你可能需要使用/registration/style.css