Ata
Ata

Reputation: 12564

How to align floated div

I have a problem with div floating ,

I have used two DIVs that float left , but if div 2 has large text , it loads under div one , how can I prevent this , I want two divs load inline . I have used inline-block but not worked .

http://jsfiddle.net/pS6Gg/

<div style="width: 100%;overflow:hidden;">
 <div style="float: left;width:">Left Stuff</div>
 <div style="float: left;margin-left:10px;">    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
 <br style="clear: left;" />
</div>

thanks

Upvotes: 0

Views: 89

Answers (5)

Venkat
Venkat

Reputation: 314

    <div style="width:800px;">
    <div style="float: left;">Left Stuff</div>
    <div style="padding-left:80px;">....</div>

Try by padding-left by 80px... Its work in.your Fiddle.. Try it

Upvotes: 0

lostphilosopher
lostphilosopher

Reputation: 4521

Will http://jsfiddle.net/pS6Gg/4/ or http://jsfiddle.net/pS6Gg/5/ do it?

The first possibility lets the second div flow around the first,

<div style="float: left; width: 50px;">Left Stuff</div>
<div style="margin-left:10px;">... text ...</div>

and the second creates a column effect by defining the first div's width and and giving the parent div a defined height for the children to fill.

<div style="width: 100%;overflow:hidden; height:200px;">              <-- parent height 
<div style="float: left; width: 50px; height:100%;">Left Stuff</div>
<div style="margin-left:10px; height:100%;"> 

Upvotes: 0

Jon
Jon

Reputation: 437854

Well, what do you want to happen if the content is too long for both DIVs to display on the same row? You will either have to use a second line or else truncate the displayed content.

Since going on the second line is what happens already, consider using an inline element such as <span> to achieve the second effect if that is preferable. Example.

Upvotes: 1

semir.babajic
semir.babajic

Reputation: 751

Somehow like this:

<div style="width: 100%; overflow:hidden;">
 <div style="float: left;width:20%">Left Stuff</div>
 <div style="float: left;width:80%">Right Stuff</div>
</div>

However, I wouldn't suggest using such layout techniques since it can cause you some troubles later, when you might consider porting your page to mobile or some tiny-dispaly device.

Regards.

Upvotes: 1

Richard A.
Richard A.

Reputation: 1157

You need to set a width parameter for both <div> elements.

Upvotes: 1

Related Questions