Embedded padding/margin in fonts

后端 未结 16 968
执念已碎
执念已碎 2021-01-08 00:56

It seems that all fonts have some sort of embedded padding or margin. By setting:

margin: 0px;
padding: 0px;

You never get what you want. D

相关标签:
16条回答
  • 2021-01-08 01:35

    you can use line-height and letter-spacing padding/margin in fonts... otherwise use custom css for each heading........

    /*use line-height*/
    .font{
    line-height: 1px; 
    letter-spacing: 1px;
    }
    

    or use custom css......

      h1{margin:1px 0;}
        h2{margin:1px 0;}
        h3{margin:1px 0;}
        h4{margin:1px 0;}
    

    using these css before use reset css .......

    0 讨论(0)
  • 2021-01-08 01:38

    x ov gjqpy bdfhklt CAPS ÂÊÁËÈ

    A glyph is designed on a two dimensional canvas. For the latin writing system the height of this canvas is consistent and width may vary. Glyphs are placed on a baseline. x is on the baseline and the top of x defines x-height. Round and pointy shapes appear smaller so are optically corrected. Descenders extend below the baseline. Ascenders, capitals go above x-height. Browsers align text with different fonts (in the same paragraph) by baseline.

    So why is the build in margin? Glyphs need whitespace around to be aligned to each other.

    What can we do to influence these margins?

    1. Choose your fonts wisely.
    2. Specify line-height p { line-height:0.5EM;}.
    3. Baseline shift .shift { top:-.5em; position:relative; }
    4. And wait for CSS3 module: line.

    General advice: do not adjust a font yourself unless you are absolutely sure what you are doing. One of the many things you'll encounter is hinting. Windows needs hinted fonts and hinting is hard to get right. Also the way fonts are loaded (@font-face) will load a local copy if it exists. You can disable local fonts by a hack. Your mileage may vary.

    0 讨论(0)
  • 2021-01-08 01:38

    What's about resetting the margin and padding value to zero in all

    *{
      margin: 0;
      padding: 0;
    }
    
    0 讨论(0)
  • 2021-01-08 01:40

    It sounds like the issue you are having is not with the CSS but the font itself. Most fonts define a baseline, x-height and line-height out-of-the-box. Your specific issue is likely with the font's leading, the space between lines. Sometimes these values can be wildly inconsistent. If you are really trying to get a specific font to line up correctly, I would recommend taking a look at FontLab and editing the glyphs/baseline/line-height for the specific font you are working with.

    You can also look at a web-safe version of the font. These types of fonts usually have been specifically spaced to render best on the web. This isn't always the case, but it might get you the results you are looking for. Check out Google's library of web fonts here.

    Update

    This answer has received enough attention that I decided to add the first comment below to the answer and expound on it.

    Browser Reset: Every browser will set default states for many of the reserved HTML tags like a and strong. There are other things defined by default including fonts, line-heights, weights and sizes. This could have an affect on the rendering of a font. Generally this is localized to specific browsers. So, by using a CSS reset, you can eliminate default rendering issues in browsers. Eric Meyers Reset is a good reset, but there are definitely others. Try using different ones to see which works best for you.

    However, CSS resets work by targeting all browsers and setting them to all be the same. Some people prefer to use something that, instead, targets only the issues with each browser. That is were Normalize will be better.

    There are also issues that a CSS reset will not fix. Such as font aliasing (making the fonts seem smooth rather than jagged). Since some browsers and operating systems do not add anti-aliasing to fonts, you will also see glyph width differences. This, unfortunately, is unavoidable in most cases. Some people go the route of using a flash font replacement tool like Cufon or Sifr. This too has it's own list of issues (such as the FOUC).

    Another Update

    One other issue that is still out there is the problem with kerning, or the space between glyphs. There is a CSS property letter-spacing that will allow you to do a global kern on a block of text, but it lacks the ability to target individual glyphs like Photoshop or InDesign. The kerning is also based on whole-pixels, so you are limited by what you can achieve. It also has issues with IE and is not as reliable as one would hope. There is a javascript called kerningjs that is pretty decent but it, too, is whole-pixel based and therefore not as accurate as rasterized text.

    On the whole, fonts on the web have gotten better over the past few years. Sadly, we are still dealing with issues from the past, when fonts were only intended to be printed or rasterized. There is hope on the horizon for us font enthusiasts, though. As @allcaps said, the CSS3 specification for linebox is out there, so it's only a matter of time until it is widely accepted!

    0 讨论(0)
提交回复
热议问题