1

I have a html structure like this:

<div class="content">
    <div class="icon"></div>
    <div class="text">Some long message text which is wrapped in two lines.</div>
    <div style="clear:both"></div>
</div>

and corresponding css:

.content {width:300px; margin:30px auto; border:1px solid #000}
.icon {width:40px; height:40px; background-color:maroon}
.icon, .text {float:left}

I want to align icon and text componenent in one line without using any relative and absolute width value.

Here is a fiddle - http://jsfiddle.net/7kNSs/

0

4 Answers 4

2

Remove CSS float property form .text

Try Fiddle

HTML :

 <div class="content">
    <div class="icon"></div>
    <div class="text">Some long message text which is wrapped in two lines.</div>
    <div style="clear:both"></div>
</div>

CSS :

   .content 
        {
      width:300px; margin:30px auto; border:1px solid #000;
        }
   .icon 
        {
        width:40px; height:40px; background-color:maroon; float:left;
        }
Sign up to request clarification or add additional context in comments.

Comments

0

All you gotta do is take out the .text div:

<div class="content">
    <div class="icon"></div>
    Some long message text which is wrapped in two lines.
    Some long message text which is wrapped in two lines.
    Some long message text which is wrapped in two lines.
    Some long message text which is wrapped in two lines.
    <div style="clear:both"></div>
</div>

.content {width:300px; margin:30px auto; border:1px solid #000}
.icon {width:40px; height:40px; background-color:maroon}
.icon, .text {float:left}

Check the forked fiddle: http://jsfiddle.net/Milanzor/tfrH6/

Comments

0

remove float form text class

html

<div class="content">
    <div class="icon"></div>
    <div class="text">Some long message text which is wrapped in two lines.</div>
    <div style="clear:both"></div>
</div>

css

  .content {width:300px; margin:30px auto; border:1px solid #000}
.icon {width:40px; height:40px; background-color:maroon;float:left;}

Comments

-1

Try to change this line .content {width:300px; margin:30px auto; border:1px solid #000} by this

#content { overflow: hidden;width:300px; margin:30px auto; border:1px solid #000}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.