【问题标题】:Center text in all supporting browsers with css使用 css 在所有支持的浏览器中居中文本
【发布时间】:2011-05-09 22:01:46
【问题描述】:

我有这个sn-p:查看here编辑here

如何让“x”在所有支持的浏览器(至少 firefox3+ 和 chrome)上保持在圆圈的中间

片段:

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>Backbone: Tody</title>

  <style>
    .delete {
      -moz-border-radius: .75em;
      -webkit-border-radius: .75em;
      width: 1.4em;
      height: 1.4em;
      text-align: center;
      display: inline-block;
      line-height: 1.4em;
      display:inline-block
      vertical-align:middle
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
      font-size: 14px;
      font-weight: bold;
      color: white;
      background-color: gray;
      cursor: pointer;
    }
    .delete:before {
      content: "\2715";
      /* content: "\00D7"; */
    }
    .delete:hover {
      background-color: red;
    }
  </style>

</head>
<body>

<div class="delete"></div>

</body>
</html>

【问题讨论】:

  • 不是已经在中间了吗?
  • 那个版本在 FF 上没问题,但在 chrome 上不行,一定有一些东西在这两个上都可以工作

标签: html css center centering


【解决方案1】:

如果您希望它在浏览器中保持像素完美,最好的办法可能是使用图像——x 的位置将取决于不同浏览器中的默认字体大小。

也就是说,我想说它在 FF4b 和 OS X 上的 Chrome 7 中已经足够接近了...

【讨论】:

    【解决方案2】:

    我通过设置这样的边距并使内部空间(框+填充)与字体大小相同来实现这一点。 http://jsbin.com/unera3/5/edit

    <!DOCTYPE HTML>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <title>Backbone: Tody</title>
    
      <style>
        .delete {
          -moz-border-radius: .75em;
          -webkit-border-radius: .75em;
          width: 1.4em;
          height: 1.4em;
          text-align: center;
          line-height: 1.4em;
          vertical-align:middle
          font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
          font-size: 14px;
          font-weight: bold;
          color: white;
          background-color: gray;
          cursor: pointer;
        }
        .delete:before {
          content: "\2715";
          /* content: "\00D7"; */
        }
        .delete:hover {
          background-color: red;
        }
      </style>
    
    </head>
    <body>
    
    <div class="delete"></div>
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2019-11-27
      • 2021-08-13
      • 2013-07-01
      • 2021-10-22
      • 2011-04-20
      • 2020-06-27
      • 2010-09-28
      相关资源
      最近更新 更多