html - CSS: Div的位置

标签 html css wordpress wordpress-theming

我正在使用 wordpress 主题,它会自动生成评论的 html 输出。 HTML 输出如下:

Author says:
August 30, 2011 at 6:43 pm  (Edit)
The comment text...
Reply.

我需要改变元素的位置。例如,我想在一行中显示作者、日期/编辑和回复。 喜欢:

Author says:    August 30, 2011 at 6:43 pm  (Edit)  Reply
The comment text...

正如我上面所说,我不能改变 HTML 结构,所以我只需要用 CSS 改变元素的位置。但是我可以这样做。 我会感谢任何帮助。

这是生成的 html:

<div class="comment-body" id="div-comment-33">

        <div class="comment-author vcard">
            <img width="48" height="48" class="avatar avatar-48 photo" src="http://i55.tinypic.com/21buau9.jpg" alt="">     

            <cite class="fn">
                <a class="url" rel="external nofollow" href="#">Author</a>
            </cite> 
            <span class="says">says:</span>     

        </div>

        <div class="comment-meta commentmetadata">
            <a href="#comment-33">August 30, 2011 at 6:43 pm</a>&nbsp;&nbsp;
            <a title="Edit comment" href="#" class="comment-edit-link">(Edit)</a>       
        </div>

        <p>The comment text...</p>

        <div class="reply">Reply</div>
</div>

jsFiddle 链接:

http://jsfiddle.net/GLwfW/1/

附言。我知道我们可以通过在 wordpress 中添加自定义函数来更改 HTML 输出,但这不是一种选择。

最佳答案

您可以在前几个元素上使用 display:inline-block; 开始:

.comment-body{
    border:1px solid green;
    position:relative;
}

.comment-author, .comment-meta{
    display:inline-block;
}

.reply{
    position:absolute;
    top:34px;
    left:360px;
}

然后给 .reply 一个 position:absolute;。您可能需要摆弄这些数字。

示例: http://jsfiddle.net/GLwfW/9/


编辑

基于@Diodeus 的评论回复

You can try absolute positioning -- until the author's name is long, which will then force "reply" to be on top of the text that was normally to the left of it.

要做的一件事是从 DOM 中分离回复并重新插入它。所以

新 CSS

.comment-body{
    border:1px solid green;
    position:relative;
}

.comment-author, .comment-meta, .reply{
    display:inline-block;
}

一些JS

var a = $('div.reply').detach();

a.appendTo('.comment-meta');

修订示例: http://jsfiddle.net/GLwfW/10/

关于html - CSS: Div的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7729637/

相关文章:

html - Chrome/Firefox 与 IE 的不同定位

html - CSS:为什么 "vertical-align: middle"不起作用?

php - 用 PHP 显示特定的 block 大小

php - 回显函数值不会传递给表单

php - 普通网站的 Wordpress 主题

html - 将 TD 元素并排放置

javascript - 使用按钮单击表单内部的 Ajax 调用不起作用

html - 我的 2 个 Div 不断重叠

javascript - 导航栏悬停鼠标

php - 在 Woocommerce 订单详细信息中显示父分组产品名称