Text wraps around floating div but borders and
s do not

后端 未结 5 2027
南笙
南笙 2021-01-04 05:09

I have a div that is float: right and it is inside a parent div. There are p elements inside that same parent div also, and the text wraps around t

相关标签:
5条回答
  • 2021-01-04 05:51

    I know this problem was posted some time ago, but I had the same problem today and found another solution:

    http://jsfiddle.net/MvX62/

    I use border-bottom instead of the <hr /> tag and had to add an overflow: hidden;. Look at the fiddle, i think this is more useful then the accepted solution, because you can also add a margin to the horizontal line and there is the same gap, as the text has.

    Also you don't need to define z values and don't need any hacks or workarounds.

    0 讨论(0)
  • 2021-01-04 05:56

    Div cannot wrap around another div. Wrapping is text-only property. You can simulate wrapping by setting the margin-right for the master div to the width of the div you want it to wrap, but text wil not flow under the inset div.

    0 讨论(0)
  • 2021-01-04 06:01

    I've had this problem before, and I wasn't sure if it was solvable.

    In your case, however, you could wrap the green box with another element and swap margin with padding and set its background to #fff to cover the offending line.

    0 讨论(0)
  • 2021-01-04 06:09

    You would have to set the width of the paragraphs to the width of the container minus the width of the floating element, or you could give them a margin on the same side of the float equal to the float's width.

    0 讨论(0)
  • 2021-01-04 06:15

    Check out the fiddle...

    http://jsfiddle.net/UnsungHero97/8BwGB/3/

    What I did here was give the floated element a z-index CSS property, which will put it "above" the non floated element (which has a smaller valued z-index) and the <hr /> will not go above the floated element.

    In regards to getting it as wide as the text, in my example it is as wide as the text, but I'm not sure if that holds across browsers (I'm on Chrome). Let me know if it doesn't.

    I hope this helps.
    Hristo

    p.s. excellent mspaint skillz :)

    0 讨论(0)
提交回复
热议问题