你会如何设计这个 html 以便所有内容都落入表格中?

发布于 2024-10-31 02:06:02 字数 1506 浏览 2 评论 0原文

如何使以下 html 变成一个类似表格的结构,其中每个 div.comment_column 水平相邻?我更喜欢使用 CSS 而不是表格:

<div class="comments_div">

    <div class="comment_column">
        <div id="comment_title_23" class="comment_title">
            What do you think of the lyrics?
            <a href="/comment_titles/23" class="comment_title_delete" data-method="delete" data-remote="true" rel="nofollow">x</a>
        </div>
        <div class="comment" id="comment_4">
             Great lyrics!
        </div>
    </div>

    <div class="comment_column">
        <div id="comment_title_25" class="comment_title">
            What should my next song be?
            <a href="/comment_titles/25" class="comment_title_delete" data-method="delete" data-remote="true" rel="nofollow">x</a>
        </div>
        <div class="comment" id="comment_4">
             Nice job! Do a another song next.
        </div>
    </div>

    <div class="comment_column">
        <div id="comment_title_26" class="comment_title">
            Feedback
            <a href="/comment_titles/26" class="comment_title_delete" data-method="delete" data-remote="true" rel="nofollow">x</a>
        </div>
        <div class="comment" id="comment_4">
             Awesome stuff... next time rap a little more than sing but still great job.
        </div>   
    </div>

</div>

How would you make the following html fall into a table-like structure where each div.comment_column falls horizontally next to one another? I prefer to use CSS and not tables:

<div class="comments_div">

    <div class="comment_column">
        <div id="comment_title_23" class="comment_title">
            What do you think of the lyrics?
            <a href="/comment_titles/23" class="comment_title_delete" data-method="delete" data-remote="true" rel="nofollow">x</a>
        </div>
        <div class="comment" id="comment_4">
             Great lyrics!
        </div>
    </div>

    <div class="comment_column">
        <div id="comment_title_25" class="comment_title">
            What should my next song be?
            <a href="/comment_titles/25" class="comment_title_delete" data-method="delete" data-remote="true" rel="nofollow">x</a>
        </div>
        <div class="comment" id="comment_4">
             Nice job! Do a another song next.
        </div>
    </div>

    <div class="comment_column">
        <div id="comment_title_26" class="comment_title">
            Feedback
            <a href="/comment_titles/26" class="comment_title_delete" data-method="delete" data-remote="true" rel="nofollow">x</a>
        </div>
        <div class="comment" id="comment_4">
             Awesome stuff... next time rap a little more than sing but still great job.
        </div>   
    </div>

</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把梦留给海 2024-11-07 02:06:02

将这些添加到您的 css 中:

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.clearfix {
    display: inline-block;
}

html[xmlns] .clearfix {
    display: block;
}

* html .clearfix {
    height: 1%;
}

.comment_colum {
    float: left;
    /* width: 200px; <-- can set a width here */
}

并将 : 更改

<div class="comments_div">

为:

<div class="comments_div clearfix">

Add these to your css :

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.clearfix {
    display: inline-block;
}

html[xmlns] .clearfix {
    display: block;
}

* html .clearfix {
    height: 1%;
}

.comment_colum {
    float: left;
    /* width: 200px; <-- can set a width here */
}

And change :

<div class="comments_div">

to :

<div class="comments_div clearfix">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文