Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop float:left div from being covered up by following div?

I have the following code:

<div>
    <div onmouseover="this.style.color='red'" 
         onmouseout="this.style.color='blue'" 
         style="float:left">
        a
        <br/>
        b
        <br/>
        c
    </div>
    <div onmouseover="this.style.color='red'" 
         onmouseout="this.style.color='blue'" 
         style="position:relative;">
        Testing, one two three...
    </div>
</div>

The first div pushes the text in the second div to the right, but not the second div itself, so the a in the first inner div will be covered up by the T in the second inner div, and hovering over the a will not trigger the onmouseover.

This is a pretty simplified example, but how do I get this sort of layout, preserving the position:relative of the second div and not adding any margins to it, since the first div may or may not be displayed? It seems strange that the second div will cover up the first.

like image 532
yuttadhammo Avatar asked Nov 22 '25 13:11

yuttadhammo


1 Answers

If i understood you correctly.. Put float: left; to the second div as well.

like image 184
Joonas Avatar answered Nov 25 '25 02:11

Joonas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!