简体   繁体   English

不同的定位铬和Firefox

[英]different positioning chrome and firefox

I have something like this: 我有这样的事情:

html: 的HTML:

<span class="st">sometext >
<ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
</ul>

</span>

css: CSS:

.st{
    position:relative;
}


.st:hover ul{
    transition: opacity 1s;
    opacity:1;  
}

.st ul{
    margin:0;
    padding-left:5%;
    opacity:0;
    position:absolute;
    width:8em;
    top:0;
    left:100%;
    list-style: none outside none;
}

.st ul li{
    display:inline-block;
    margin:0;
    padding:0;

}

fiddle 小提琴

--> the list (some images with links, but simplified to letters here) shows up when hovering over someText. ->将鼠标悬停在someText上时,将显示列表(一些带有链接的图像,但此处简化为字母)。 In firefox it shows up right next to someText > (which is the desired outcome), in Chrome however it appears much further right. 在firefox中,它显示在someText>旁边(这是所需的结果),而在Chrome中,它显示得更远。

My initial guess was that (since the ul is nested in the span) the width of the span is calculated differently, that firefox ignores the opacity 0 list for calculating the width of the span and chrome uses it. 我最初的猜测是(由于ul嵌套在跨度中),跨度的宽度以不同的方式计算,因此Firefox忽略了用于计算跨度宽度的不透明度0列表,而chrome使用了该列表。 But I have the same issue when removing the opacity rules and using display: none/block for hiding and showing of the ul. 但是,在删除不透明度规则并使用display时,我有相同的问题:none / block用于隐藏和显示ul。
(note: I say chrome, but I'm actually using Chromium 31.0.1650.63 on Ubuntu in case that makes a difference) --> Any idea what causes this? (注意:我说的是chrome,但实际上是在Ubuntu上使用Chromium 31.0.1650.63,以防万一。)->知道是什么原因造成的吗? And how can I solve this? 我该如何解决呢?

Hm, I think you have to reset browsers defaults. 嗯,我认为您必须重置浏览器的默认设置。
Try to use normalize.css or an simple css reset 尝试使用normalize.css或简单的CSS重置

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}

So.. why does the .st ul have padding-left:5%; 所以.. .st ul为什么有padding-left:5%; ? Because it seems that's what's causing it. 因为这似乎是造成它的原因。

Plus you're placing block stuff ( ul ) inside inline element ( span ), so another reason not to be surprised with different (that is, undefined ) behaviour. 另外,您还将填充( ul )放置在内元素( span )内,因此还有另一个理由不要因其不同的行为(即未定义的行为)而感到惊讶。

I never was a big fan of the list elements. 我从来都不是列表元素的忠实拥护者。 They seem to act slightly differently in all browsers, including their default margins and paddings. 它们在所有浏览器中的行为似乎略有不同,包括它们的默认边距和填充。

Why not use a simple div element instead? 为什么不使用简单的div元素呢? You can do whatever you want with it. 您可以用它做任何您想做的事。

Also you might want to use & gt; <您可能还想使用&gt; instead of > because it is a special html tag and might ruin the code (though browsers are smart enough these days). 而不是>,因为它是一个特殊的html标记,并且可能会破坏代码(尽管现在浏览器足够聪明)。

http://jsfiddle.net/qLuw2/9/ http://jsfiddle.net/qLuw2/9/

<span class="st">sometext &gt;
<div class="hoverable">
    a <br />
    b <br />
    c
</div>

</span>

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

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