文本未对齐

发布于 2024-12-09 03:53:05 字数 727 浏览 0 评论 0原文

我创建了以下 HTML CSS 代码

<div class="Pager">
  <span class="Resume">Posts 1 to 40 of 220X</span>
  <ul class="Buttons">
    <li><span>123</span></li>
  </ul>
  <div class="Clear"></div>
</div>

.Class {clear: both;}

div.Pager {}

div.Pager span.Resume {
  font-family: Arial;
  font-size: 0.9em;
  line-height: 1;
  float: left;
}

div.Pager ul.Buttons {
  float: left;    
}

div.Pager ul.Buttons li {
  float: left;   
}

div.Pager ul.Buttons li span {
  font-family: Arial;
  font-size: 0.9em;
  line-height: 1;
}

有谁知道为什么“123”文本显示得比之前的要低文本?

谢谢你, 米格尔

I created the following HTML CSS Code:

<div class="Pager">
  <span class="Resume">Posts 1 to 40 of 220X</span>
  <ul class="Buttons">
    <li><span>123</span></li>
  </ul>
  <div class="Clear"></div>
</div>

.Class {clear: both;}

div.Pager {}

div.Pager span.Resume {
  font-family: Arial;
  font-size: 0.9em;
  line-height: 1;
  float: left;
}

div.Pager ul.Buttons {
  float: left;    
}

div.Pager ul.Buttons li {
  float: left;   
}

div.Pager ul.Buttons li span {
  font-family: Arial;
  font-size: 0.9em;
  line-height: 1;
}

Does anyone knows why the "123" text appears lower then the previous text?

Thank You,
Miguel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尝蛊 2024-12-16 03:53:05

将“字体样式设置 CSS”移动到最外层元素 (div.Pager),并仅将其放在该元素上,这样您就不必不必要地重新定义相同的内容:

http://jsfiddle.net/thirtydot/85AKq/9/

这是有效的,因为font-familyfont-sizeline-height都是可继承的——后代可以从父元素继承这些属性。


我很确定这是无关紧要的,但要使其在 jsFiddle 中关闭“标准化 CSS”时工作,请添加 margin: 0;填充:0;列表样式:无到您的ul

http:// jsfiddle.net/thirtydot/85AKq/10/

Move your "font style setting CSS" to the outermost element (div.Pager), and have it only on that element so you're not needlessly redefining the same thing:

http://jsfiddle.net/thirtydot/85AKq/9/

This works because font-family, font-size, line-height are all inheritable - the descendants can inherit those properties from the parent element.


I'm pretty sure this is irrelevant, but to make it work when "Normalized CSS" is turned off in jsFiddle, add margin: 0; padding: 0; list-style: none to your ul:

http://jsfiddle.net/thirtydot/85AKq/10/

纸短情长 2024-12-16 03:53:05

将两个跨度上的 line-height 更改为正常对我有用

div.Pager span.Resume {
    float: left;
    font-family: Arial;
    font-size: 0.9em;
    line-height: normal;
}

div.Pager ul.Buttons li span {
    font-family: Arial;
    font-size: 0.9em;
    line-height: normal;
}

以及更改 liul 以删除点和间距完全修复了它。

div.Pager ul.Buttons li {
    float: left;
    list-style:none;
    padding:0;
    margin:0;
}

div.Pager ul.Buttons {
    float: left;
    list-style:none;
    padding:0;
    margin:0;
}

Changing the line-height to normal on both the spans worked for me

div.Pager span.Resume {
    float: left;
    font-family: Arial;
    font-size: 0.9em;
    line-height: normal;
}

div.Pager ul.Buttons li span {
    font-family: Arial;
    font-size: 0.9em;
    line-height: normal;
}

As well as changing the li and ul to remove the dot and the spacing fixed it completely.

div.Pager ul.Buttons li {
    float: left;
    list-style:none;
    padding:0;
    margin:0;
}

div.Pager ul.Buttons {
    float: left;
    list-style:none;
    padding:0;
    margin:0;
}
假情假意假温柔 2024-12-16 03:53:05

这是因为文本位于无序列表内。列表具有由浏览器确定的自动边距属性。为了让它达到相同的水平,您必须通过为列表提供 margin-top: -3px 样式来将其位置偏移到顶部,如下所示:

http://jsfiddle.net/hnYUR/

It's because the text is inside an unordered list. Lists have automatic margin properties that are determined by the browser. In order to get it to go up to the same level you're going to have to offset it's position to the top by giving the list a margin-top: -3px style like so:

http://jsfiddle.net/hnYUR/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文