【问题标题】:css id in php echo not workingphp echo中的css id不起作用
【发布时间】:2013-11-28 09:38:02
【问题描述】:

我似乎无法获得我在 php 回显中分配的类 ID,以便被 CSS 识别。这是代码。似乎我错过了一些简单的东西,但我似乎无法弄清楚或看到它是什么。

echo "<table class='item'>
                    <tr>
                        <td id='name'><h3>" . $name . "</h3></td>
                        <td id='itemdescription'>" . $description . "</td>
                        <td id='imagelocaiton'><img src='" . $location . "'id='image'></td>
                        <td id='price'>" . $price . "</td>";

以及相关的 CSS:

#image {
width: 300px;
height: auto;
}

#itemdescription {
color: red;
}

谢谢!

编辑:这是检查元素的输出 HTML。我想我应该提到这个 id 正在使用 while 循环从 MySQL 数据库中绘制表信息进行修改。我刚刚注意到我的 CSS 似乎可以使用 google chrome 但不能在 Safari 中工作......

<html><head>
    <title>For Sale</title>
    <link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css"></style></head>
<body>
    <div class="item_list">

        <table class="item">
                    <tbody><tr>
                        <td id="name"><h3>had</h3></td>
                        <td id="itemdescription">adfafdsaf</td>
                        <td id="imagelocaiton"><img src="images/simple.gif" id="image"></td>
                        <td id="price">$0</td></tr></tbody></table><table class="item">
                    <tbody><tr>
                        <td id="name"><h3>Idkd</h3></td>
                        <td id="itemdescription">adfaf</td>
                        <td id="imagelocaiton"><img src="images/Airplane Logo.jpg" id="image"></td>
                        <td id="price">$0</td></tr></tbody></table><table class="item">
                    <tbody><tr>
                        <td id="name"><h3>adfag</h3></td>
                        <td id="itemdescription">adfaf</td>
                        <td id="imagelocaiton"><img src="images/Jason.jpeg" id="image"></td>
                        <td id="price">$1313</td></tr></tbody></table><table class="item">
                    <tbody><tr>
                        <td id="name"><h3>afaf</h3></td>
                        <td id="itemdescription">adfafaf</td>
                        <td id="imagelocaiton"><img src="images/HDR1.jpg" id="image"></td>
                        <td id="price">$331</td>        

【问题讨论】:

  • 我认为你错过了 css 中的项目类..
  • 你能贴出 echo 输出的 html 吗?或者提供一个我们可以查看的网址?
  • @LakshmiPrasanna 该类在这里不应该有所作为,因为 jason 正在使用 ids。
  • 您好,感谢您的回复。我无法发布该页面,因为这一切都在本地主机上。 HTML 输出看起来就像没有任何 CSS 样式。如果我在 或 标签上使用全局样式,它也不起作用。
  • @LakshmiPrasanna 这是输出应该是什么样子的小提琴:jsfiddle.net/jameslafferty/9QDBR

标签: php css styles echo


【解决方案1】:

你写错了代码。整个页面不能有多个 id。

区分类和id:http://css-tricks.com/the-difference-between-id-and-class/

然后使用单个 id 再试一次。

【讨论】:

    【解决方案2】:

    您的代码是正确的,您对图像标签做了一些小改动:

    <td id='imagelocaiton'><img src='" . $location . "'id='image'></td>
    try make minor correction
    <td id='imagelocaiton'><img src='" . $location . "' id='image'></td>
    

    它工作正常,但保证 $location 具有正确的路径和带扩展名的图像文件名。根据给定的 css,我得到了红色的描述和图像。

    【讨论】:

      猜你喜欢
      • 2013-02-01
      • 2013-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2019-01-10
      • 1970-01-01
      • 2020-12-07
      相关资源
      最近更新 更多