dqf60304 2016-02-27 22:07
浏览 90

HTML <a>无效

Apologies for the short title.

When I echo a <a>-tag via PHP, the link behaves like normal text; it doesn't change the mousepointer, it doesn't go to any given links, but it does follow the CSS rules for a. Here's my code:

<?php $string = "<content-box id='about'>
        <content-box-title>Welcome,</content-box-title><br/>
        <p>
            text
        </p>
        <p>
            text
        </p>
        <p>" //this string is all on one line in my code, 
             //but for question purposes I aligned them, so it's better readable

    echo substr($string, 0, 952) . '... </p><a href="about.php">More</a></content-box>';
 ?>

And my CSS

a {
    color: #d60000;
    border-bottom: 1px dotted #000000;
    text-decoration: none;
}
a:active {
    color: #d60000;
}
container > content > content-box {
    width: 920px;
    padding: 40px;
    margin-bottom: 10px;
    background-color: #ffffff;
    box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
}

It did work before, but suddenly it doesn't anymore. Can anyone figure out what's going on?

Thanks.

EDIT: This example is supposed to be a 'preview' of what's on another page (that's why I need a 'more' button). I retrieve the raw HTML from another source and then shorten it. By that reason </p> and </content-box> fall off.

Also <content-box> is a custom element, but it acts just lake a normal <div> (see comments)

EDIT:

<content>
    <?php
        error_reporting(E_ALL & ~E_WARNING);
        $page = new DOMDocument();
        $page->loadHTMLFile('about.php');
        $elm = $page->getElementById('about');

        $faulty_string = $elm->ownerDocument->saveHTML($elm);
        $string = str_replace('ï', 'ï', $faulty_string);

        echo substr($string, 0, 206) . '... </p><a href="about.php">More</a></content-box>';
    ?>
</content>

And #about on about.php

<content-box id='about'>
        <content-box-title>Welcome,</content-box-title><br/>
        <p>
            text
        </p>
        <p>
            text
        </p>
        <p>
            text
        </p>
    </content-box>

CSS: Same as before.

EDIT:

<content-box id="about">
    <content-box-title>Welcome,</content-box-title>
    <br>
    <p> text </p>
    <p> text </p>
    <p> tex... </p>
    <a href="about.php">Lees verder</a>
</content-box>

This is from the DOM Explorer from Firefox.

  • 写回答

1条回答 默认 最新

  • dongtanlin0765 2016-02-27 22:17
    关注

    A better approach to this would be to store the text of the content-box tag in it's own string, then use substr to shorten it.

    <?php
    $text = '<p>Text</p><p>Text</p>';
    $text = substr($text, 0, 952) . '... </p><a href="about.php">More</a>';
    $content_box = "<content-box id='about'>
            <content-box-title>Welcome,</content-box-title><br/>
                 ".$text.";
            </content-box>";
    
    echo $content_box;
     ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!