【发布时间】:2021-06-17 18:36:27
【问题描述】:
我正在尝试使用外部样式表来放置我的 CSS 代码,当我将 CSS 放在同一个文件中时它可以工作,但是当 CSS 代码位于外部工作表中时它什么也不做, 为了测试,我创建了一个带有输入字段的 php 文件,并使用 css 作为页面的背景颜色和名为“account_name”的输入字段的样式:
这是我的代码与 css 代码在同一个文件中:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
<title>Add Account</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.6/dist/css/bootstrap.min.css">
<script type="text/javascript" src="bootstrap-3.3.6/js/tests/vendor/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap-3.3.6/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.10.3/ui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jquery-ui-themes-1.10.3/jquery-ui-themes-1.10.3/themes/black-tie/jquery-ui.css">
<!-- Alertify Librery-->
<link rel="stylesheet" type="text/css" href="alertify/css/alertify.css">
<link rel="stylesheet" type="text/css" href="alertify/css/themes/bootstrap.css">
<script src="alertify/alertify.js"></script>
<!-- Modal librery-->
<script type="text/javascript" src="librerias/js/sweetalert2.js"></script>
<script type="text/javascript" src="librerias/js/sweetalert2.min.js"></script>
<link rel="stylesheet" href="librerias/css/sweetalert2.css" type="text/css">
<link rel="stylesheet" href="librerias/css/sweetalert2.min.css" type="text/css">
<style type="text/css">
body{
color: #fff;
background: #3598dc;
font-family: 'Roboto', sans-serif;
}
.signup-form {
width: 600px;
margin: 0 auto;
padding: 5px 0;
}
.signup-form form {
color: #9ba5a8;
border-radius: 3px;
margin-bottom: 15px;
background: #F0FFF0;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
padding: 30px;
}
.signup-form h2 {
color: #333;
font-weight: bold;
margin-top: 0;
}
input#account_name {
border-radius: 10px;
border: 1px solid #73AD21;
padding: 5px;
width: 400px;
height: 35px;
float: left;
color: #0000CD;
background-color : #ffee88;
}
</style>
</head>
<body>
</br>
</br>
<div class="signup-form">
<form method="post" id="add_form">
<h2>Add Account</h2>
<hr>
<div class="form-group">
<div class="row">
<div class="col-xs-6">
<label>Please Enter Account Name</label>
<input type="text" class="form-control" id="account_name" name="account_name" required="required">
<input type="hidden" name="key" value="addcuenta" >
</div>
</div>
</br>
</br>
</br>
</br>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Accept</button>
</div>
</form>
</div>
</body>
</html>
<script>
//Send Data to Add
$(document).on('submit', '#add_form', function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
//Send Data To add
url: 'processAddAccount.php',
type: 'POST',
dataType: 'json',
data : data,
success: function(data)
{
alert('Account Add');
},
error: function(errorThrown)
{
alert(errorThrown);
}
});
});
</script>
但是,如果我将 css 代码放在名为“style.css”的外部工作表中,css 格式不会产生任何影响,这些是 php 和 css 文件: php代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
<title>Add Account</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.6/dist/css/bootstrap.min.css">
<script type="text/javascript" src="bootstrap-3.3.6/js/tests/vendor/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap-3.3.6/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.10.3/ui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jquery-ui-themes-1.10.3/jquery-ui-themes-1.10.3/themes/black-tie/jquery-ui.css">
<!-- Load css style file-->
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- Alertify Librery-->
<link rel="stylesheet" type="text/css" href="alertify/css/alertify.css">
<link rel="stylesheet" type="text/css" href="alertify/css/themes/bootstrap.css">
<script src="alertify/alertify.js"></script>
<!-- Modal librery-->
<script type="text/javascript" src="librerias/js/sweetalert2.js"></script>
<script type="text/javascript" src="librerias/js/sweetalert2.min.js"></script>
<link rel="stylesheet" href="librerias/css/sweetalert2.css" type="text/css">
<link rel="stylesheet" href="librerias/css/sweetalert2.min.css" type="text/css">
</head>
<body>
</br>
</br>
<div class="signup-form">
<form method="post" id="add_form">
<h2>Add Account</h2>
<hr>
<div class="form-group">
<div class="row">
<div class="col-xs-6">
<label>Please Enter Account Name</label>
<input type="text" class="form-control" id="account_name" name="account_name" required="required">
<input type="hidden" name="key" value="addcuenta" >
</div>
</div>
</br>
</br>
</br>
</br>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Accept</button>
</div>
</form>
</div>
</body>
</html>
<script>
//Send Data to Add
$(document).on('submit', '#add_form', function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
//Send Data To add
url: 'processAddAccount.php',
type: 'POST',
dataType: 'json',
data : data,
success: function(data)
{
alert('Account Add');
},
error: function(errorThrown)
{
alert(errorThrown);
}
});
});
</script>
css文件style.css:
body{
color: #fff;
background: #3598dc;
font-family: 'Roboto', sans-serif;
}
.signup-form {
width: 600px;
margin: 0 auto;
padding: 5px 0;
}
.signup-form form {
color: #9ba5a8;
border-radius: 3px;
margin-bottom: 15px;
background: #F0FFF0;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
padding: 30px;
}
.signup-form h2 {
color: #333;
font-weight: bold;
margin-top: 0;
}
input#account_name {
border-radius: 10px;
border: 1px solid #73AD21;
padding: 5px;
width: 400px;
height: 35px;
float: left;
color: #0000CD;
background-color : #ffee88;
}
请问有什么想法吗?
【问题讨论】:
-
请检查css文件路径是否正确
-
@Uzair 说了什么。检查控制台是否有错误?
-
Protip:布局时不要使用换行符(更不用说成堆的了)。在 CSS 中使用边距。
-
Thnaks,我正在使用 mozilla,我可以通过按 Ctrl+Shift+J 在 mozilla 控制台上看到错误吗?