我想從一個文件夾中取出一些圖像,並以整潔和可視的方式顯示它。爲此,我使用PHP從文件夾中獲取圖像。如何使用css和php一起使用?
下面是代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/custom.css">
<title>Load Images from a folder</title>
</head>
<body>
<?php
$files = glob("*.JPG");
$fileCount = count(glob("*.JPG"));
echo '<ul id = \"gallery\">';
for ($i = ($fileCount -1); $i >= (0); $i--) {
echo '<li> <img src="' . $files[$i] . '" alt="image" /> </li>';
}
echo '</ul>';
?>
</body>
</html>
與此相伴,我使用了下面的CSS。下面的custom.css文件與上面的index.php文件位於同一個文件夾中。
#gallery li {
display: inline;
list-style: none;
max-width: 250px;
max-height: 250px;
float: left;
margin: 0px 20px 20px 0px;
text-align: center;
}
但是,它不工作。我得到的圖像一個在另一個下面(每個圖像都有一個子彈),而不是像我期望的那樣一個。
我試圖重新命名CSS文件與文本轉換爲.php:
<?php "header("Content-type: text/css");" ?>
在頂部和標記的「禮」與「ID =畫廊」,但這並沒有幫助。
我在這裏錯過了什麼?
你怎麼在開發工具看? – SLaks 2013-03-05 19:09:22
您不需要在單引號字符串中使用雙引號。這可能是你的問題。 – Bojangles 2013-03-05 19:11:14
也許是一個愚蠢的評論,但你確定要''custom.css'而不是'custom.css'嗎? – ChrisW 2013-03-05 19:11:36