Firefox 浮动定位和 Firefox div:hover 不工作应该如何处理?

发布于 2024-08-09 06:23:17 字数 1497 浏览 1 评论 0原文

我正在研究一些棘手的样式,该样式适用于 Safari/Webkit,但不适用于 Firefox/Gecko。我不明白到底出了什么问题。

这是我正在使用的 HTML:

<div class="showcase"><a href=><div class="showtit"><span class="showname">Stripes!</span> <span class="showtype">a theme</span> <span class="showdate">October 2009</span></div></a></div>

因此,它创建 Showcase div,然后在其中创建一个包含 Showtit div(用于定位)的链接,然后是 Showname、Showtype 和 Showdate 跨度。这就是所有的样式:

.showcase {
 border-bottom-color: #eeeeee;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 font-size: 20pt;

}

.showtit {
 text-align: left;

 width: 800px;
 margin: 0 auto;
 padding: 20;
}

.showtit:hover{background-color: #3f3f3f;}

a .showcase {
  color: black;
}

.showcase:hover {
 background-color: #3f3f3f;
 color: white;

}
.showcase a{color:black;}
.showcase a:hover {background-color: #3f3f3f;
 color: white;}


.showtype {
 text-transform: lowercase;
 font-size: 0.7em;
 color: #cecece;
}
.showdate {
 z-index: 0;
 top: 0.35em;
 float: right;
 position: relative;
 font-size: 0.7em;
 color: #cecece;
}

凌乱的代码,我知道,但这是在我尝试堵塞我能想到的每个泄漏之后。现在,在 Safari 上,此代码会产生如下布局:

imgur.com/54VFo.png

悬停在中间的位置超过。但在 Firefox 上,我得到的是:

imgur.com/MCNYV.png

将鼠标悬停在同一中间。因此,div 背景悬停不起作用,而且,我在右侧对齐的跨度没有自行对齐。

这是为什么呢?我该如何解决这个问题?我如何确保这种情况不再发生?

I'm working on a tricky bit of styling that's working on Safari/Webkit but not on Firefox/Gecko. I can't figure out just what's going wrong.

Here's the HTML that I'm using:

<div class="showcase"><a href=><div class="showtit"><span class="showname">Stripes!</span> <span class="showtype">a theme</span> <span class="showdate">October 2009</span></div></a></div>

So, it creates the Showcase div, then inside that makes a link that encompasses the Showtit div (used for positioning), and then the Showname, Showtype, and Showdate spans. Here's how that's all being styled:

.showcase {
 border-bottom-color: #eeeeee;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 font-size: 20pt;

}

.showtit {
 text-align: left;

 width: 800px;
 margin: 0 auto;
 padding: 20;
}

.showtit:hover{background-color: #3f3f3f;}

a .showcase {
  color: black;
}

.showcase:hover {
 background-color: #3f3f3f;
 color: white;

}
.showcase a{color:black;}
.showcase a:hover {background-color: #3f3f3f;
 color: white;}


.showtype {
 text-transform: lowercase;
 font-size: 0.7em;
 color: #cecece;
}
.showdate {
 z-index: 0;
 top: 0.35em;
 float: right;
 position: relative;
 font-size: 0.7em;
 color: #cecece;
}

Messy code, I know, but this is after I've tried plugging every leak I could think of. Now, on Safari this code results in a layout like this:

imgur.com/54VFo.png

Where the middle is being hovered over. But on Firefox, I instead get this:

imgur.com/MCNYV.png

With that same middle being hovered over. So the div background hover isn't working, and, what's more, the spans I aligned on the right aren't aligning themselves.

Why is this? How do I fix this? How do I make certain this never happens again?

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

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

发布评论

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

评论(1

一身骄傲 2024-08-16 06:23:17

您的代码有一些问题:

  • 在 HTML 4.01 或 XHTML 1.0 中,您不能在内联元素中使用块元素(div)(a)
  • 如果您使用“严格”Doctype,则只能应用伪类“hover”要链接元素,

我建议使用下面的代码:

<style>
div.showcase {
 border: 1px solid #EEE;
  font-size: 20pt;
 }
 div.showcase a{
  display: block;
  width: 100%;
  color:black;
  /*center the "a" tag in IE6 */
  text-align: center;
 }
 div.showcase a:hover{
  background-color: #3f3f3f;
  color: white;
 }
 div.showcase #content{
  display: block;
  width: 800px;
  margin: 0 auto;
  padding: 20px;
  text-align: left;
 }


span.showtype {
  text-transform: lowercase;
  font-size: 0.7em;
  color: #cecece;
}

span.showdate {
  z-index: 0;
  top: 0.35em;
  float: right;
  position: relative;
  font-size: 0.7em;
  color: #cecece;
}
</style>

<div class="showcase">
 <a href="#">
     <span id="content">
            <span class="showname">Stripes!</span>
            <span class="showtype">a theme</span>
            <span class="showdate">October 2009</span>
     </span>
  </a>
</div>

请注意,在 FF 中,两个包含“Stripes!”的跨度和“主题”没有对齐,而且在 IE6 中存在很大的对齐问题(我没有用其他版本测试过代码)。


编辑:要向右浮动“showdate”跨度,只需向右应用浮动并将html代码放置在其他两个跨度之前...边距顶部修复了对齐问题:

<style>
span.showdate {
    margin-top: 7px;
    float: right;
    font-size: 0.7em;
    color: #cecece;
}
</style>


<div class="showcase">
 <a href="#">
     <span id="content">
            <span class="showdate">October 2009</span>
            <span class="showname">Stripes!</span>
            <span class="showtype">a theme</span>
     </span>
  </a>
</div> 

您有稍微使用 CSS 来对齐跨度“showname”和“showtype”;我不知道你想要完成什么,但我建议用下面的 html 替换这两个 span:

<span class="showname">Stripes! <small>a theme</small></span>

Your code has some issues:

  • in HTML 4.01 or XHTML 1.0 , you can't use block elements (div) inside inline elements (a)
  • if you are using a "strict" Doctype, you can apply the pseudo-class "hover" only to link elements

I suggest the code below:

<style>
div.showcase {
 border: 1px solid #EEE;
  font-size: 20pt;
 }
 div.showcase a{
  display: block;
  width: 100%;
  color:black;
  /*center the "a" tag in IE6 */
  text-align: center;
 }
 div.showcase a:hover{
  background-color: #3f3f3f;
  color: white;
 }
 div.showcase #content{
  display: block;
  width: 800px;
  margin: 0 auto;
  padding: 20px;
  text-align: left;
 }


span.showtype {
  text-transform: lowercase;
  font-size: 0.7em;
  color: #cecece;
}

span.showdate {
  z-index: 0;
  top: 0.35em;
  float: right;
  position: relative;
  font-size: 0.7em;
  color: #cecece;
}
</style>

<div class="showcase">
 <a href="#">
     <span id="content">
            <span class="showname">Stripes!</span>
            <span class="showtype">a theme</span>
            <span class="showdate">October 2009</span>
     </span>
  </a>
</div>

Notice that in FF the two span that contain "Stripes!" and "a theme" are not aligned, moreover you have a big alignment issue in IE6 (I've not tested the code with other versions).


EDIT: To float right the "showdate" span, just apply a float right and place the html code before the other two span(s) ... the margin-top fixes the alignment issue:

<style>
span.showdate {
    margin-top: 7px;
    float: right;
    font-size: 0.7em;
    color: #cecece;
}
</style>


<div class="showcase">
 <a href="#">
     <span id="content">
            <span class="showdate">October 2009</span>
            <span class="showname">Stripes!</span>
            <span class="showtype">a theme</span>
     </span>
  </a>
</div> 

You have to play a bit with the CSS to align the span(s) "showname" and "showtype"; I don't know what you are trying to accomplish, but I suggest to replace the two span(s) with the html below:

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