简体   繁体   English

使用Chrome,IE7和IE8在ul中浮动文本

[英]Floating text inside ul with Chrome, IE7 and IE8

I am having some problems with floating text inside unordered list (ul). 我在无序列表(ul)中浮动文本时遇到一些问题。 The problem appears, because I want to float div element to the left, I need to do this, because after this div there is another div, that needs to be on the same line, so I use float left. 出现问题是因为我想将div元素向左浮动,这是因为在此div之后还有另一个div,它需要在同一行上,因此我使用float向左。 Here is an example on jsFiddle . 这是jsFiddle的示例。 Now the problem is, that in FF 6.02, Opera 11.50 and IE9 it works OK, but in Chrome 14.0.835.202, IE7 and IE8 the circle that should appear in the front of the text appears almost at the end of the text in the background. 现在的问题是,在FF 6.02,Opera 11.50和IE9中它可以正常工作,但是在Chrome 14.0.835.202,IE7和IE8中,应该出现在文本前面的圆圈几乎在背景中的文本末尾出现。

I have posted the example on jsFiddle, but will also post the code here: 我已将示例发布在jsFiddle上,但还将在此处发布代码:

HTML: HTML:

<ul>
<li>
    <div class="textLeft">Glavna knjiga</div>
</li>
</ul>

CSS: CSS:

.textLeft {
float: left;
position: relative;
left: 4px;
}

Now how do I fix this, so that I will appear the same in IE7 and Chrome? 现在如何解决此问题,以便在IE7和Chrome中显示相同的内容?

If you don't have to use position relative, you can make both divs inline-block, and instead of left, use padding-left. 如果不必使用相对位置,则可以使两个div都内联块,并且可以使用padding-left代替left。

Here's an example: http://jsfiddle.net/bQthE/3/ 这是一个示例: http : //jsfiddle.net/bQthE/3/

The problem is that the div is floated, but the li itself is not. 问题是div是浮动的,而li本身不是。 That makes it so that the list item's indicator, the circle, is positioned as if the div were not there. 这样就可以确定列表项的指示器(圆圈)的位置,就像div不在那儿一样。 Is it possible to float the li , or possibly the entire ul ? 是否可以浮动li或整个ul

Why do you need to float the divs at all? 为什么您需要完全浮动div? Set your divs to display:inline-block and that will take care of it. 将div设置为display:inline-block,它将解决这个问题。 One thing you have to keep in mind is that inline-block display creates a 4px margin to the right of divs, so if you have a fixed width list item (li) you have to take that into account. 您要记住的一件事是,内联块显示在div的右侧创建了4px的边距,因此,如果您有固定宽度的列表项(li),则必须考虑到这一点。

i usually don't like floating elements if i can help it. 如果我能帮助的话,我通常不喜欢浮动元素。

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

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