douyongwan5946
douyongwan5946
2013-11-03 23:45
浏览 19
已采纳

使用PHP时CSS代码会发生变化

I have this HTML/CSS here:

<div class="liste">
    <div class="content">
        <h4>Cyekl something</h4>
        <p>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maiores, ullam, consectetur, totam vel consequuntur
            quas sunt nulla rerum maxime saepe repudiandae voluptate porro laudantium repellat rem non doloremque? Ea,
            delectus, quis quod nemo deleniti velit 
        </p>
    </div>
    <div class="listeimage">
        <img src="http://lorempixel.com/116/80/" alt="">
    </div>
    <p class="pris">Pris 9.995 kr.</p>
    <a href="#">
        <h4 class="mereinfo">Mere info</h4>
    </a>
</div>

and when I'm using it with PHP, the sidebar I have on my page moves into the content class and just kinda ruins everything.

    $cykel_id = $row['cykel_id'];
    $cykel_tekst = $row['cykel_tekst'];
    $cykel_pris = $row['cykel_pris'];
    $img = 'http://lorempixel.com/116/80/';
    echo '<div class="liste"><div class="content"><h4>'.$cykel_id.'</h4>'.'<p>'.$cykel_tekst.'</p>'.'</div><div class="listeimage"><img src="'.$img.'"</div><p class="pris">'.$cyke_pris.'</p>'.'<a href="#"><h4 class="mereinfo">Mere info</h4></a></div>';
}

And thats my php code I have no idea what's going wrong hope someone can help me.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongmeng0317
    dongmeng0317 2013-11-03 23:55
    已采纳

    Indent your code properly and you will see the mistakes much faster.

    After formatting, your PHP echo looks like this:

    echo '
        <div class="liste">
            <div class="content">
                <h4>'.$cykel_id.'</h4>
                '.'<p>'.$cykel_tekst.'</p>'.'
            </div>
            <div class="listeimage">
                <img src="'.$img.'"
            </div>
            <p class="pris">'.$cyke_pris.'</p>
            '.'
            <a href="#">
                <h4 class="mereinfo">Mere info</h4>
            </a>
        </div>
    ';
    

    The <img /> tag is not closed properly. Also, there are some unnecessary '.' fragments here and there, but they are not affecting the correctness.

    The line with img tag should look like:

    <img src="'.$img.'" />
    

    (and to be fully valid, it should have alt attribute, too)

    点赞 评论
  • douyong1908
    douyong1908 2013-11-04 00:03

    You didn't close your img tag. Also, you had a typo at $cyke_pris. It should be $cykel_pris. The following format may help you avoid this error in the future:

    <?php
    $cykel_tekst = $row['cykel_tekst'];
    $cykel_pris = $row['cykel_pris'];
    $img = 'http://lorempixel.com/116/80/';
    echo "<div class='liste'>
            <div class='content'>
              <h4>$cykel_id</h4>
              <p>$cykel_tekst</p>
            </div>
            <div class='listeimage'>
              <img src='$img' />
            </div>
            <p class='pris'>$cykel_pris</p>
            <a href='#'><h4 class='mereinfo'>Mere info</h4></a>
          </div>";
    ?>
    

    You can use output buffering to get rid of tho white spaces, or just take them out yourself.

    点赞 评论

相关推荐