html – 将标题对齐到相同的基线,无论后续文字是什么?

html – 将标题对齐到相同的基线,无论后续文字是什么?,第1张

概述有没有办法将不同大小的多个标题的第一行与同一基线对齐?也不管后面的文本,也应该对齐. 请在http://snapplr.com/snap/z1mw见图片 编辑:重新上传: alt text http://img144.imageshack.us/img144/7615/screenshot2010021722h53.png 在我看来,唯一的解决方案是将每个标题和每个正文文本放入单独的DIV,然后使 有没有办法将不同大小的多个标题的第一行与同一基线对齐?也不管后面的文本,也应该对齐.

请在http://snapplr.com/snap/z1mw见图片

编辑:重新上传:

alt text http://img144.imageshack.us/img144/7615/screenshot2010021722h53.png

在我看来,唯一的解决方案是将每个标题和每个正文文本放入单独的div,然后使用标题来填充顶部或边缘顶部以对齐它们(例如H1将是36px,0px边距,而H3将是24px,12px上边距).像这样的东西:

<HTML><head>    <style type="text/CSS" media="all">        div {            wIDth: 240px;            float: left;        }        h1 {            Font-size: 36px;            margin: 0;            padding: 0;        }        h3 {            Font-size: 24px;            margin: 0;            padding: 10px 0 0 0; /*for some reason I must use 10px instead of 12px to align. Why??*/        }    </style></head><body>    <div>        <h1>H1 heading</h1>    </div>    <div>        <h3>H3 heading</h3>    </div>    <div>        <h3>H3 heading that is somewhat longer and spans multiple lines</h3>    </div>    <div ></div>    <div>        <p>There are many variations of passages of Lorem Ipsum available,but the majority have suffered alteration in some form,by injected humour,or randomised words which don't look even slightly belIEvable. If you are going to use a passage of Lorem Ipsum,you need to be sure there isn't anything embarrassing hIDden in the mIDdle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary,making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words,combined with a handful of model sentence structures,to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition,injected humour,or non-characteristic words etc.</p>    </div>    <div>        <p>There are many variations of passages of Lorem Ipsum available,or non-characteristic words etc.</p>    </div></body>

但这不是一个很好的解决方案.请问有什么更好的吗?

非常感谢你!

解决方法 Web处理基线的方式与您以前的打印方式不同.浏览器会将文本与行高的中心对齐,而不是与底部对齐.这意味着与网格对齐的文本相对于彼此垂直居中,而不是坐在相同的基线上.

如果你对此感到满意,你仍然可以从中获得强大的网格.您必须精确地结合使用行高,填充,边框和边距.这需要一些数学,但完全有可能.更多信息:

http://24ways.org/2006/compose-to-a-vertical-rhythm/

如果您需要实际与基线对齐的东西,就像您在印刷中所知,那么游戏就更难了.问题是你需要根据确切的字体推送不同数量的东西 – 当每个浏览器使用不同的字体时几乎不可能.以下是尝试实现这一目标的一种尝试:

http://baselinecss.com/

无论哪种解决方案都存在跨浏览器问题.网络还没有为此提供适当的工具.但在任何情况下你都不需要div.您可以对标题本身进行所有调整.在你的例子中你甚至不需要它们.那里的div为什么?

总结

以上是内存溢出为你收集整理的html – 将标题对齐到相同的基线,无论后续文字是什么?全部内容,希望文章能够帮你解决html – 将标题对齐到相同的基线,无论后续文字是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1135647.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存