[英]CSS stylesheet not being applied
Since about a week I have a problem getting my CSS stylesheet loaded. 大约一个星期以来,我在加载CSS样式表时遇到了问题。 I have the following code:
我有以下代码:
Version 1: 版本1:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
<?PHP include_once "school.css"; ?>
</style>
</head>
Version 2: 版本2:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="school.css" />
</head>
I tested the stylesheet with online validation pages and there where no error messages. 我用在线验证页面测试了样式表,那里没有错误消息。 I use the following browsers: Chrome and Firefox on the following devices: Windows XP, Windows 7, Nexus 7. All of them show the same problem:
我使用以下浏览器:在以下设备上使用Chrome和Firefox:Windows XP,Windows 7,Nexus7。所有这些都显示相同的问题:
I load the page and the stylesheet seems to have been loaded, but it is not applied. 我加载了页面,样式表似乎已经加载,但是未应用。 When I navigate through the page, the stylesheet is still not applied.
当我浏览页面时,样式表仍未应用。 The same stylesheet should be applied, but isn't.
应该应用相同的样式表,但不是。 When I refresh, or force refresh the page, the stylesheet is being applied and everything is OK from that point on.
当我刷新或强制刷新页面时,正在应用样式表,从那时起一切正常。 Even if I change the stylesheet and then refresh the page the changes will be shown without any problem.
即使更改样式表然后刷新页面,更改也将毫无问题地显示出来。 ONLY ON THE FIRST LOAD THERE IS A PROBLEM.
仅在第一个负载上存在一个问题。
I have many similar pages with stylesheets and they still work. 我有很多带有样式表的相似页面,它们仍然可以工作。 Here is the stylesheet:
这是样式表:
/***********
* MY STYLE *
***********/
/* GENERAL */
html, body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
}
body {
font-family: "MS Gothic";
}
/* COLORS */
body {
color: black;
}
#banner a, h2, #tabbar a, th, input[type="submit"] {
color: #ffe6cc;
text-shadow:
0.05em 0.05em 0.05em #2f2200,
0.05em 0 0.05em #2f2200,
0.05em -0.05em 0.05em #2f2200,
0 0.05em 0.05em #2f2200,
0 -0.05em 0.05em #2f2200,
-0.05em 0.05em 0.05em #2f2200,
-0.05em 0 0.05em #2f2200,
-0.05em -0.05em 0.05em #2f2200;
}
body {
background-color: #ffe6cc;
}
#banner, h2, #tabbar a {
background-color: #665533;
}
th, input[type="submit"] {
background-color: #887755;
}
/* BORDERS */
.tablePrices tr:first-child > *, .tabbar, #imgTeacher, #aMap img, input[type="text"], input[type="submit"], input[type="tel"], input[type="email"], select, textarea {
border-top: 0.15em solid #2f2200;
}
.tablePrices tr:first-child > *:first-child, .tablePrices tr > *:first-child, #imgTeacher, #aMap img, input[type="text"], input[type="submit"], input[type="tel"], input[type="email"], select, textarea {
border-left: 0.15em solid #2f2200;
}
.tablePrices tr > *, .tabbar a, #imgTeacher, #aMap img, input[type="text"], input[type="submit"], input[type="tel"], input[type="email"], select, textarea {
border-right: 0.15em solid #2f2200;
}
h1, h2, #navMenu h2:last-child:last-child > div, h3, .tablePrices tr > *, #imgTeacher, #aMap img, input[type="text"], input[type="submit"], input[type="tel"], input[type="email"], select, textarea {
border-bottom: 0.15em solid #2f2200;
}
/* BANNER */
#banner {
position: fixed;
top: 0;
left: 0;
right: 0;
}
.banner h1 {
margin: 0;
padding: 0;
text-align: center;
background-repeat: no-repeat;
background-position: center center;
background-size: 100% 100%;
}
.banner a {
display: block;
font-weight: bold;
padding: 0.5em 0;
text-decoration: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
h2 {
margin: 0;
}
h2 span {
display: block;
}
/* TABBAR */
#tabbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
}
#tabbarDummy {
visibility: hidden;
}
.tabbar a {
display: inline-block;
font-weight: bold;
width: 20%;
margin: 0;
padding: 0;
text-align: center;
text-decoration: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.tabbar a:last-child {
border-right: 0;
}
/* ARTICLE */
article {
padding: 1em 1em 0 1em;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
article > *:last-child {
margin-bottom: 1em;
}
p {
margin: 0 0 0.5em 0;
}
/* COURSES */
.tablePrices {
border-collapse: separate;
border-spacing: 0;
width: 50%;
min-width: 15em;
margin: 0 auto 0.5em auto;
}
.tablePrices th {
padding: 0.2em;
}
.tablePrices td {
padding: 0.2em;
text-align: center;
}
.tablePrices tr:first-child > *:first-child {
-webkit-border-top-left-radius: 0.5em;
-moz-border-topleft-radius: 0.5em;
border-top-left-radius: 0.5em;
}
.tablePrices tr:first-child > *:last-child {
-webkit-border-top-right-radius: 0.5em;
-moz-border-topright-radius: 0.5em;
border-top-right-radius: 0.5em;
}
.tablePrices tr:last-child > *:first-child {
-webkit-border-bottom-left-radius: 0.5em;
-moz-border-bottomleft-radius: 0.5em;
border-bottom-left-radius: 0.5em;
}
.tablePrices tr:last-child > *:last-child {
-webkit-border-bottom-right-radius: 0.5em;
-moz-border-bottomright-radius: 0.5em;
border-bottom-right-radius: 0.5em;
}
/* TEACHER */
#imgTeacher {
float: right;
margin: 0 0 0.5em 0.5em;
max-width: 50%;
-webkit-border-radius: 0.5em;
-moz-border-radius: 0.5em;
border-radius: 0.5em;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#pTeacher {
margin-bottom: 1em;
}
#divTeacher {
clear: both;
margin-bottom: 0.5em;
}
/* MAP */
#aMap {
display: block;
margin: 0 0 0.5em 0;
padding: 0;
text-align: center;
}
#aMap img {
display: block;
width: 100%;
max-width: 600px;
margin: 0 auto;
-webkit-border-radius: 0.5em;
-moz-border-radius: 0.5em;
border-radius: 0.5em;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#divMap {
text-align: center;
}
#divMap p {
width: 100%;
max-width: 600px;
margin: 0 auto 0.5em auto;
text-align: left;
}
/* INQUIRY */
#tableInquiry {
border-collapse: collapse;
width: 100%;
max-width: 600px;
margin: 0 auto 1em auto;
}
#tableInquiry .tdLabel {
width: 1%;
white-space: nowrap;
padding: 0.1em;
text-align: right;
}
#tableInquiry .tdLabelLong {
padding: 0.1em;
text-align: left;
}
#tableInquiry .tdRed {
color: red;
}
#tableInquiry .tdField {
width: 99%;
padding: 0.1em;
}
#tableInquiry .tdTrial {
width: 100%;
text-align: center;
}
#tableInquiry .tdSpacer {
width: 100%;
height: 0.5em;
}
#tableInquiry .spanNoWrap {
white-space: nowrap;
}
#tableInquiry .tdButton {
padding: 0.1em;
text-align: right;
}
#pInquirySuccess {
color: #009900;
text-align: center;
}
/* INQUIRY: INPUT FIELDS */
input[type="text"], input[type="tel"], input[type="email"], select, textarea {
display: block;
width: 100%;
margin: 0;
padding: 0.1em;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-border-radius: 0.3em;
-moz-border-radius: 0.3em;
border-radius: 0.3em;
}
textarea {
height: 12em;
resize: vertical;
}
input[type="submit"] {
display: inline-block;
margin: 0;
padding: 0.2em 0.3em;
-webkit-border-radius: 0.3em;
-moz-border-radius: 0.3em;
border-radius: 0.3em;
}
/* BANNER IMAGE */
@media only screen and (max-width: 319px) {
#banner h1 {
background-image: url("/images/school/banner_small.jpg");
}
}
@media only screen and (min-width: 320px) and (max-width: 759px) {
#banner h1 {
background-image: url("/images/school/banner_medium.jpg");
}
}
@media only screen and (min-width: 760px) {
#banner h1 {
background-image: url("/images/school/banner.jpg");
}
}
/* PORTRAIT: FONT SIZE */
@media only screen and (orientation: portrait) and (max-width: 279px) {
* { font-size: 12px; }
}
@media only screen and (orientation: portrait) and (min-width: 280px) and (max-width: 319px) {
* { font-size: 14px; }
}
@media only screen and (orientation: portrait) and (min-width: 320px) and (max-width: 399px) {
* { font-size: 16px; }
}
@media only screen and (orientation: portrait) and (min-width: 400px) and (max-width: 479px) {
* { font-size: 20px; }
}
@media only screen and (orientation: portrait) and (min-width: 480px) {
* { font-size: 24px; }
}
/* LANDSCAPE: FONT SIZE */
@media only screen and (orientation: landscape) and (max-width: 419px) {
* { font-size: 12px; }
}
@media only screen and (orientation: landscape) and (min-width: 420px) and (max-width: 479px) {
* { font-size: 14px; }
}
@media only screen and (orientation: landscape) and (min-width: 480px) and (max-width: 599px) {
* { font-size: 16px; }
}
@media only screen and (orientation: landscape) and (min-width: 600px) and (max-width: 719px) {
* { font-size: 20px; }
}
@media only screen and (orientation: landscape) and (min-width: 720px) {
* { font-size: 24px; }
}
/* PORTRAIT */
@media only screen and (orientation: portrait) {
.banner a {
font-size: 200%;
}
h2 {
padding: 1em 1em;
}
h2 span {
font-size: 150%;
}
.tabbar img {
display: block;
width: 2em;
margin: 0.5em auto;
}
.tabbar span {
font-size: 75%;
display: block;
text-align: center;
padding: 0 0 0.666em 0;
}
}
/* LANDSCAPE */
@media only screen and (orientation: landscape) {
.banner a {
font-size: 150%;
}
h2 {
padding: 0.5em 1em;
}
h2 span {
font-size: 125%;
}
.tabbar img {
display: inline-block;
width: 2em;
margin: 0.25em 0.5em 0.25em 0;
vertical-align: middle;
}
.tabbar span {
font-size: 75%;
display: inline-block;
padding: 0;
vertical-align: middle;
}
}
Any ideas? 有任何想法吗? Thanks in advance.
提前致谢。
Bernhard 伯恩哈德
You can use this code 您可以使用此代码
Version 1 : <?php function my_theme_enqueue_styles() { $parent_style = 'adforest-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/school.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/school.css', array( $parent_style ), wp_get_theme() >get('1.0.0') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); ?> @import url("../css/school.css"); Version 2 : <link rel="stylesheet" type="text/css" href="css/school.css" />
<!-- begin snippet: js hide: false console: true babel: false -->
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.