CSS - Is it Possible to “Shrink Wrap” a Bounding Block to a Font's Cap and Baseline?

我只是一个虾纸丫 提交于 2019-12-08 05:43:57

问题


I have some <h1> and <p> tags with text content. I'd like the top of the text (cap height) and the bottom of the text (baseline) to be flush with the tag's bounding block. By default there seems to be a certain amount of spacing and I don't know why. Is there a calculation to determine this spacing?

I can achieve what I'm after if I modify the line-height and the height properties of the element, but then the original and desirable line-height for multi-line text overlaps and isn't what we want.

Ex. Right-click a <p> tag on this page and hover the element in the dev console to notice that the top/bottom of the text isn't flush with the bounds of the actual <p> element.

  1. Is it possible to make the cap height and baseline flush with and element's bounds?
  2. Is this spacing possible to edit in CSS?
  3. Is there a rule/calculation that determines what this spacing is?

回答1:


you want to use something called css reset block

http://html5doctor.com/html-5-reset-stylesheet/

and also if your container is a div

use display:inline; to wrap exactly onto the element inside.



来源:https://stackoverflow.com/questions/25671545/css-is-it-possible-to-shrink-wrap-a-bounding-block-to-a-fonts-cap-and-basel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!