www.webdeveloper.com
Results 1 to 4 of 4

Thread: Floating 2 images and some text

  1. #1
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    86

    Floating 2 images and some text

    Hi,

    I'm trying to float 2 images, one left and the other right, then add some text in-between them. Here is my attempt, but as you can see, the addition of the text wraps the right image...

    http://jsbin.com/ofurig/1/

    Code if the link doesn't work...
    Code:
    <div style="float: left; margin-left: 15px; margin-right: 15px;">
    	 <img src="http://elisabethrobson.com/wp-content/uploads/2012/08/200px-HTML5-logo.png" alt="2012 calendar"> 
    
    </div>
    
      <div style="margin: 0 auto; display: block; float:none;">
    	<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    	<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    	<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
    </div>
    
    
    <div style="float: right; margin-right: 15px;">
    	 <img src="http://elisabethrobson.com/wp-content/uploads/2012/08/200px-HTML5-logo.png" alt="2012 calendar"> 
    </div>
    What do you suggest?

    Thanks

  2. #2
    Join Date
    Feb 2010
    Posts
    16
    Have you tried, maybe, defining widths for each div? Possibly percentage widths...

    Also, is there a float container for the divs?

  3. #3
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    86
    Quote Originally Posted by Hunter1611 View Post
    Have you tried, maybe, defining widths for each div? Possibly percentage widths...

    Also, is there a float container for the divs?
    Thanks for the idea. I managed to find a solution...
    Code:
      <div>
    
    <div align="center" style="float:left;
    width:24%;">
      
    	 <img src="http://elisabethrobson.com/wp-content/uploads/2012/08/200px-HTML5-logo.png" alt="2012 calendar"> 
    
    </div>
    
    <div align="center" style="float:left;
    width:50%; text-align:left">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    </div>
    
    
    <div align="center" style="float:left;
    width:24%;">
      
    	 <img src="http://elisabethrobson.com/wp-content/uploads/2012/08/200px-HTML5-logo.png" alt="2012 calendar"> 
    </div>
          
    </div>

  4. #4
    Join Date
    Sep 2006
    Location
    new york
    Posts
    266

    middle <div> centered

    How about this?
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>3 elements</title>
    <style type="text/css">
    
    html { color: black; background: #ffffff; margin: 0; padding: 0; }
    
    body	{ color: black;	background: transparent; 	margin: 0;	padding: 0; text-align:center; 	}
    #wrap { color: black; margin: 0 auto; width: 95%; max-width:1000px; min-width: 200px;  width: 95%;   background-color: rgba(255, 255,255, 0.25);  z-index:300; }
    
    .container { width: 95%; padding:10px; margin: 5px auto; z-index:400; clear:both; overflow: auto; border: #C00 medium ridge; }
    
    .floatLeft { float: left; width: 20%; height: auto; display: inline-block; }
    
    .floatRight { float: right; width: 20%; height: auto; display: inline-block; }
    
    .textbox { text-align:left; display: block; width: 40%; padding: 5px; margin: 0 auto; }
    </style>
    
    </head>
    
    <body>
    <div id="wrap">
    <div class="container">
    <h1> Could be header</h1>
    </div><!--closeCONTAINER-->
    	 
         <div class="container">
    
         <img class="floatLeft" src="http://elisabethrobson.com/wp-content/uploads/2012/08/200px-HTML5-logo.png" alt="2012 calendar">
      	 <img class="floatRight" src="http://elisabethrobson.com/wp-content/uploads/2012/08/200px-HTML5-logo.png" alt="2012 calendar"> 
      <div class="textbox">
        <h2>In HTML Markup</h2>
        <p>The middle section, centered with margin: 0 auto, comes after the floated left/right elements.</p>
      </div><!--closeTEXTBOX-->
    </div><!--closeCONTAINER-->
    
    <div class="container">
    <h4> Could be footer</h4>
    </div><!--closeCONTAINER-->
    
    
    
    
    </div><!--closeWrAP-->
    </body>
    </html>
    Last edited by auntnini; 01-07-2013 at 05:29 PM. Reason: clean up code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles