简体   繁体   English

Safari 5.1打破了CSS表格单元格间距

[英]Safari 5.1 breaks CSS table cell spacing

My site was working fine across all major browsers right up until the update to Safari 5.1. 我的网站在所有主流浏览器上运行良好,直到更新到Safari 5.1。 Now, the primary navigation is busted up. 现在,主导航被破坏了。 I was using display:table-cell on the anchor element within the list element and was also using the font-size:0 hack to remove the spacing in between menu elements. 我在list元素中的anchor元素上使用display:table-cell ,并且还使用了font-size:0 hack来删除菜单元素之间的间距。 Has anyone else encountered this issue and have a solution they could offer up? 有没有其他人遇到过这个问题,并有一个他们可以提供的解决方案?

Before: 之前: 在图像之前

After: 后: 图像之后

CSS: CSS:

#navigation {
  padding-top: 7px;
}

#navigation ul.links, /* Main menu and secondary menu links */
#navigation .content ul /* Menu block links */ {
  margin: 0;
  padding: 0;
  display: block;
  font-size: 0; /* this is a hack so that the spacing between the menu buttons disappear
                   since they are inline-block elements, this should be unneccessary when
                   CSS3 is approved */
}

#navigation ul.links li, /* A simple method to get navigation links to appear in one line. */
#navigation .content li {
  display: inline-block;
  padding-right: 0;
  padding-left: 0;
  margin: 0;

  /* below is a fix for IE7 to get the main navigation items lined up correctly
   * in one row
   */
  zoom: 1;
  *display: inline;
}
#main-menu ul {
  width: 100%;
}
#main-menu li {
  width: 108px;
  text-align: center;
  padding-bottom: 7px;
  font-size: 11pt;
}
#main-menu a {
  display: table-cell;
  width: inherit;
  text-decoration: none;
  font-size: 0.9em;
  color: #035B9A;
  background-color: white;
  height: 30px;
  vertical-align: middle;
}

HTML: HTML:

<div id="navigation">
    <div class="section">
        <h2 class="element-invisible">Main menu</h2>
        <ul id="main-menu" class="links inline clearfix">
            <li class="menu-379 first"><a href="/about-scrubbed">About Us</a></li>
            <li class="menu-401"><a href="/" title="">Research</a></li>
            <li class="menu-385"><a href="/education">Education</a></li>
            <li class="menu-402"><a href="/" title="">Outreach</a></li>
            <li class="menu-403 active-trail active"><a href="/news" title="" class="active-trail active">News &amp; Events</a></li>
            <li class="menu-439"><a href="/people">People</a></li>
            <li class="menu-405"><a href="/" title="">Resources</a></li>
            <li class="menu-406"><a href="/" title="">Publications</a></li>
            <li class="menu-415 last"><a href="/partners">Partners</a></li>
        </ul>
    </div>
</div>

Thanks. 谢谢。

Just a note, this is a Drupal 7 site. 请注意,这是一个Drupal 7站点。

Also I freely and humbly admit I am not the very best at CSS markup. 我也自由而谦卑地承认我不是最好的CSS标记。 I'm learning a lot right now and am just trying to scrape through. 我现在正在学习很多东西,而且我只是想凑进去。

For those having trouble with Safari and dimensions for elements set to display:table; 对于那些遇到Safari问题的人和要显示的元素的尺寸:table; I was able to fix my problems by removing the padding and adding padding to a child element set to display:table-cell; 我能够通过删除填充并将padding添加到要显示的子元素集来解决我的问题:table-cell;

Apparently Safari does not like it when you try to add padding to an element set to display:table; 显然,当您尝试将padding添加到要显示的元素集时,Safari不喜欢它:table; In retrospect, this makes sense. 回想起来,这是有道理的。

Solved by making the list elements display as block and float them to the left. 通过使列表元素显示为块并将它们浮动到左侧来解决。

#navigation ul.links li, /* A simple method to get navigation links to appear in one line. */
#navigation .content li {
  display: block;
  float: left;
  padding-right: 0;
  padding-left: 0;
  margin: 0;

  /* below is a fix for IE7 to get the main navigation items lined up correctly
   * in one row
   */
  zoom: 1;
  *display: inline;
}

您想要border-collapse:collapsedisplay:table元素上border-collapse:collapse以删除单元格间距。

I took your css and html, and added to the css 我拿了你的css和html,然后加入了css

body {
    background-color: gray;
}

and I got the following , which looks correct. 我得到了以下 ,看起来是正确的。

This was run under lion, which has Safari 5.1 这是在拥有Safari 5.1的lion下运行的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM