使DIV可点击

时间:2013-02-05 19:32:58

标签: html css

我被指示在DIV周围包装一个锚标签,以使下面的PHP可点击。我的直觉是,这是一个坏主意,因为它对SEO无效和不好,所以我们可以一起解雇这个想法 - 不需要在这个建议上来回生成。那么,在“盒装”DIV中将所有内容都指向链接的正确方法是什么呢?

<div class="box-wrap">
    <div class="box">
        <header>            
            <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <?php echo get_the_term_list( $post->ID, 'categories', '<h3 class="entry-by">' . __('Posted In: ', 'okay'), ', ', '</h3>' ); ?>
        </header>
    </div><!-- box -->
</div><!-- box wrap -->

2 个答案:

答案 0 :(得分:3)

As of HTML5,您可以合法地将其包装在<a>中。在您的示例中,只需使用a标记替换外部div。

<a class="box-wrap" href="...">
    <div class="box">
        <!-- ... -->
    </div>
</a>

答案 1 :(得分:0)

如果你想让你的div“可点击”,你应该使用javascript:

$("#clickableDivId").click(function() {
    window.location = "your url";
});

您还可以将css样式cursor: pointer;添加到div中,看起来像锚。

相关问题