CSS 文本列

标签 css

我目前正在学习 HTML/CSS,并且遇到了有关文本列的挑战。我正在尝试重新创建 www.campaignmonitor.com 作为练习。

这是挑战:

我有一个使用两列布局的文本区域,其中包含 4 个文本段落。我想让最上面的两个段落在顶部边缘对齐,下面的两个段落也在它们的顶部边缘对齐。换句话说,如果顶部段落中的任何一个增加高度,下面的两个段落将一起向下移动。

我明白这对你们这些 CSS 专业人士来说可能是一个基本问题,但我被这个问题难住了,在线资源、教程和其他网站都没有给我任何成功。

感谢所有帮助!

汤姆


这是我使用的代码:

<div class="content">
    <div class="row1">
    <div class="col1a">
        <h4>Create & send beautiful emails</h4>
        <p>Design great looking emails using your own tools, or create templates and let your clients send their own.</p>
    </div><!-- /end #col1a -->
    <div class="col2a">
        <h4>Manage lists & subscribers</h4>
        <p>We handle signups, unsubscribes and bounces automatically. Easily create targeted segments of subscribers.</p>
    </div><!-- /end #col2a -->
    </div><!-- /end #row1 -->
    <div class="row2">
    <div class="col1b">
        <h4>Powerful Analytics</h4>
        <p>Actionable reports that go beyond opens and clicks. Track your email related conversions and sales.</p>
    </div><!-- /end #col1b -->
    <div class="col2b">
        <h4>Mark-up, Resell and Profit</h4>
        <p>White-label and rebrandable, you set the price your clients pay and we’ll send through your profit each month.</p>
    </div><!-- /end #col2b -->
    </div><!-- /end #row2 -->
</div>

还有 CSS:

.content {
    width: 1024px;
    margin: auto;
    position: relative;
    margin-top: 20px;
    color: #333;
    background-color: #666;
}

.col1a {
    width: 225px;
    margin-right: 20px;
    display: block;
    float: left;
}

.col2a {
    width: 225px;
    margin-right: 20px;
    display: block;
    float: left;
}

.col1b {
    width: 225px;
    margin-right: 20px;
    display: block;
    float: left;
}

.col2b {
    width: 225px;
    margin-right: 20px;
    display: block;
    float: left;
}

.row1 {
    position: relative;
    width: 490px;
    background-color: orange;
}

.row2 {
    position: relative;
    width: 490px;
    background-color: green;
}

.content h4 {
    margin-top: 25px;
    margin-bottom: 7px;
    line-height: 22px;
    font-weight: normal;
    font-style: normal;
    font-size: 17px;
}

.content p {
    font-size: 13px;
    line-height: 18px;
}

最佳答案

clear: both 添加到行元素。

您的元素命名非常多余,col1acol1bcol2acol2b 做同样的事情所以它们都可以简单地命名为 col。行元素也是如此,它们也是无用的边界。

http://jsfiddle.net/yTJTp/1/

关于CSS 文本列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4553264/

相关文章:

javascript - 无法在我的 Mean-stack 应用程序中加载本地镜像

css - Bootstrap 4 中心和中间对齐表单元素

html - 如何强制自动设置导航栏宽度?

css - 内联 block 不在同一行

html - 如何在css中夹入一个盒子?

javascript - 如何延迟加载 css 文件(用于 google speed insights)

css - 将 Div 中的文本粘在窗口底部

html - 使用 HTML/CSS 创建带标签的水平线

css - SVG 无法在 Firefox 中呈现(最新版本)

css - 在 IE8 中,如何在没有任何重叠的情况下使用 Telerik 网格和 YUI3 网格?