css - 如何对齐 2 个并排 Div 的基线?

标签 css

这是来自 my blog 的页面.
我创建了一个名为 Journal entries 的灰色框。

第 1 点读作用于记录...
如您所见,从单词 For 开始的文本略低于数字 1 的级别。
第 2 点也是如此。

请建议我应该对代码进行哪些更改。

我的代码:

<div style="background-color: #F0F0F0; display: table-cell; vertical-align: middle; border-radius: 15px;">
    <div style="margin-left: 10px; margin-right: 100px; margin-top: 15px; margin-bottom: 15px;">


        <div style="text-align: center;"><span style="font-family: georgia; font-size: 17px; font-weight: bold;">Journal entries</span></div>

        <br>


        <div style="font-family: serif; font-size: 17px; margin-left: 30px;">

            <div style="float: left;">1.&nbsp;</div>
            <div>For recording 1<sup>st</sup> aspect, asset value is reduced period-wise by crediting its account:</div>
            <div style="margin-left: 20px;">Depreciation A/c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...Dr.
                <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To Asset A/c</div>

            <br>

            <div style="float: left;">2.&nbsp;</div>
            <div>For recording 2<sup>nd</sup> aspect, the depreciation for the period is transferred to the Profit &amp; Loss Account:</div>
            <div style="margin-left: 20px;">Profit and Loss A/c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...Dr.
                <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To Depreciation A/c</div>

        </div>


    </div>
</div>

最佳答案

根据您的评论,您根本不希望文本低于数字。一种选择是将数字放在文本 div 中,然后将其绝对放在 Angular 落。然后向 div 添加一些填充以移动文本。:

<div class="text">
    <div class="num">
        1.
    </div>

    stuff
</div>
.text{
    position: relative;
    padding-left: 20px;
}

.num{
    position: absolute; 
    width: 20px;
    top: 0;
    left: 0;
}

http://jsfiddle.net/THYga/1/

关于css - 如何对齐 2 个并排 Div 的基线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19638092/

相关文章:

javascript - 下拉菜单没有反应

html - 如何将两个 DOM 层与彼此顶部的文本对齐?

css - 用于 css 的 yuicompressor 为某些文件抛出错误

javascript - 使用 "background-image"时,DIV "background-size : 100% 100%"未延伸到整个 DIV

javascript - 关闭javascript确认框后如何从按钮上移除焦点

css - 注册表单文本显示为白色,背景为白色

css - Firefox 奇怪的百分比高度绝对定位的 div

javascript - 通过 Ajax 上传照片后替换 css 背景图像

css - 如何制作没有图像的虚线

javascript - Jquery悬停功能不起作用