大约一周后,我遇到了加载CSS样式表的问题。我有以下代码:
版本1:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
<?PHP include_once "school.css"; ?>
</style>
</head>
第2版:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="school.css" />
</head>
我使用在线验证页面测试了样式表,并且没有错误消息。我使用以下浏览器:Chrome和Firefox在以下设备上:Windows XP,Windows 7,Nexus 7.所有这些都显示同样的问题:
我加载页面并且样式表似乎已加载,但未应用。当我浏览页面时,样式表仍未应用。应该应用相同的样式表,但不是。当我刷新或强制刷新页面时,正在应用样式表,从那时起一切正常。即使我更改样式表然后刷新页面,也会毫无问题地显示更改。只有第一次负担才有问题。
我有许多与样式表相似的页面,但它们仍然可以使用。这是样式表:
/***********
* 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;
}
}
有什么想法吗?提前谢谢。
哈德
答案 0 :(得分:0)
您可以使用此代码
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 -->