【问题标题】:CSS not working with PHP scriptCSS 不适用于 PHP 脚本
【发布时间】:2012-11-04 23:00:16
【问题描述】:

您好,我正在按照本教程制作一个 php 日历

http://www.youtube.com/watch?v=l76uglZBjpk

我有三个文件

show_calendar.php

 <!DOCTYPE html>
<html>
<head>
<link href="calCss.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<?php include ("calendar_start.php"); ?>
</body>
</html>

日历开始.php

<?php
//$showmonth = $_POST['showmonth'];
//$showyear = $_POST['showyear'];
$showmonth = 11;
$showyear = 2012;

$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear);
$pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear));
$post_days = (6 - (date('w', mktime(0,0,0, $showmonth, $day_count,$showyear))));

echo '<div id="calendar_wrap">';
echo '<div class="title_bar">';
echo '<div class="previous_month"></div>';
echo 'div class="show_month">' . $showmonth . '/' . $showyear . '</div>';
echo '<div class="next_month"></div>';
echo '</div>';
echo '<div class="week_days">';
echo '<div class="days_of_the_week">Sun</div>';
echo '<div class="days_of_the_week">Mon</div>';
echo '<div class="days_of_the_week">Tue</div>';
echo '<div class="days_of_the_week">Wed</div>';
echo '<div class="days_of_the_week">Thur</div>';
echo '<div class="days_of_the_week">Fri</div>';
echo '<div class="days_of_the_week">Sat</div>';
echo '<div class="clear"></div>';
echo '</div>';

/* Previous Month Filler Days */
if ($pre_days != 0) {
for($i = 1 ; $i<=$pre_days;$i++) {
    echo '<div class="non_cal_day"></div>';
}
}

/* Current Month */
for($i=1; $i<= $day_count; $i++) {
echo '<div class="cal_day">';
echo '<div class="day_heading">' . $i . '</div>';
echo '</div>';

}
/* Next Month Filler Days */
if ($post_days != 0) {
for ($i=1; $i<=$post_days; $i++) {
     echo '<div class="non_cal_day"></div>';
}
}
echo '</div>';
?>

还有css文件calCss.css

#calendar_wrap {
width: 924px;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
.title_bar {
width: 100%; 
height: 30px;
}
.previous_month {
float: left;
width: 308px;
height: 30px;
text-align: left;
}
.show_month {
float: left;
width: 308px;
height: 30px;
text-align: center;
}
.next_month {
float: left;
width: 308px;
height: 30px;
text-align: right;
}
.week_days {
width: 100%;
}       
.days_of_week  {
float: left;
width: 14%;
text-align: center;
}      
.cal_day {
position: relative;
float: left;
margin-right: 4px;
margin-bottom: 4px;
width: 128px;
height: 95px;
background-color: #9C9;
}
.day_heading {
position: relative;
float: left;
width: 40px;
height: 16px;
padding: 6px;
color: #000;
font-family: Arial;
font-size: 14px;
}    
.openings {
width: 100%;
clear:left;
text-align: center;
}
.non_cal_day {
position: relative;
float: left;
margin-right: 4px;
margin-bottom: 4px;
width: 128px;
height: 95px;
background-color: #CCC;
}

.clear {
clear: both;
}

我的问题是 show_calendar.php 没有显示任何仅显示星期几和月份数字的 CSS 文本。我不确定我做错了什么,有人有什么想法吗?我使用 xampp 本地服务器查看 php 文件。谢谢

【问题讨论】:

  • 你试过在浏览器中打开 calCss.css 吗?是否显示正确的内容?
  • 你的 .css 在哪里?在哪个文件夹?
  • 根据您的 PHP,您的 CSS 应该位于根文件夹中(与 PHP 文件相同),因此请确保它确实存在 - 或调用 CSS 文件的正确位置。
  • 在样式方面,只有生成的 HTML(和 CSS)很重要,而不是创建它的 PHP。
  • 可能是一个错字,但您的 CSS 中有 .days_of_week,而 HTML 中的 div 类有 days_of_the_week

标签: php css


【解决方案1】:

我只看到一个小错误:

你忘了一个echo 'div class="show_month">' . $showmonth . '/' . $showyear . '</div>';

我这样测试过,对我来说效果很好..

【讨论】:

  • css 仍然无法正常工作,但它确实修复了出现的月份(之前没有)
  • 并且您确定 css 文件与您调用的文件具有完全相同的名称?奇怪的idd..
  • 您实际使用的是什么浏览器(和版本)?
【解决方案2】:

例如,如果您使用像 (dreamweaver) 这样的 IDE,请确保将 localhost 的 Web URL 设置为 (localhost/myProject) 而不是 (localhost/myProject/index.php) .. 因为它有时会出错, 到达 css 目录.. 我有那个错误, 并且修复了它, 希望它对你有用:)

【讨论】:

    【解决方案3】:

    我已经检查了所有内容,但没有发现这不起作用的原因。可能无法加载您的 css 文件。您应该检查浏览器控制台的内容。

    这是调试此问题的方法:

    • 在浏览器中启动脚本

    • shift + strg + j 启动开发者工具(如果你有 IE,这个快捷方式适用于 Forefox 和 Chrome f12)

    • 选择“控制台”

    • 检查您的 css 是否存在加载错误

      如果您使用的是 Windows,那么第二个问题来源可能是隐藏的文件扩展名。也许您的文件名不是 calCss.css 而是 calCss.css.txt 或类似名称。这只是一个猜测,但我之前遇到过这类问题。如果它适用于您的问题this is how you can display hidden file extensions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      相关资源
      最近更新 更多