Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fit images in div grid (exciting problem to think about)

    hi guys,

    i have a div with a width of 500px and an undefined height.
    i'm using images of 20px x 15px as a base. i want to fill
    this div with this images. if i give them a border, a grid will
    be visible.

    however, i'm also using images of 40px x 15px, or images
    of 40px x 30px.

    so i want the div to be full with images. so all spaces must
    be filled. one of the problems is that the images will be aligned
    by the 30px height of some of the images, so there will be
    spaces on top of the smaller images..

    can anyone help me? it's a pretty exciting problem to figure out i think

    eventually i will have to display the images randomly and it
    still has to fit every time...

    grtz,
    jimmy

  • #2
    Regular Coder optimus203's Avatar
    Join Date
    Sep 2008
    Location
    CT
    Posts
    317
    Thanks
    22
    Thanked 16 Times in 15 Posts
    For something like this, if I'm understanding correctly, your best bet might be absolute positioning. Here an idea (not saying its the way to go, but its an idea).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Four images All in a Row!</title>
    <style type="text/css" media="screen">
    div {width: 200px;}
    img {
    border:1px solid red;
    }
    </style>
    </head>
    
    <body>
    <div>
    <!-- row 1 -->
    <img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:0;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:22px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:44px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:66px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:88px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:110px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:132px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:154px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:176px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:198px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:0; left:220px;" />
    
    <!-- row 2 -->
    <img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:0;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:22px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:44px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:66px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:88px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:110px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:132px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:154px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:176px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:198px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:17px; left:220px;" />
    
    <!-- row 3 -->
    <img 
    src="pic.jpg" width="40" height="30" style="position:absolute; top:34px; left:0;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:34px; left:42px;" /><img 
    src="pic.jpg" width="20" height="15" style="position:absolute; top:50px; left:42px;" />
    <!-- etc -->
    
    </div>
    </body>
    </html>
    Always thank those CF Users who help you solve issues...
    Connecticut Web Design

  • #3
    New Coder
    Join Date
    Jun 2010
    Location
    usa
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jimmyfortune View Post
    hi guys,

    i have a div with a width of 500px and an undefined height.
    i'm using images of 20px x 15px as a base. i want to fill
    this div with this images. if i give them a border, a grid will
    be visible.

    however, i'm also using images of 40px x 15px, or images
    of 40px x 30px.

    so i want the div to be full with images. so all spaces must
    be filled. one of the problems is that the images will be aligned
    by the 30px height of some of the images, so there will be
    spaces on top of the smaller images..

    can anyone help me? it's a pretty exciting problem to figure out i think

    eventually i will have to display the images randomly and it
    still has to fit every time...

    grtz,
    jimmy
    Hi,
    can you post the link you didn't reply this seems your problem is unsolved if you post the link i can tell you how to make it any query let me know

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,088
    Thanks
    15
    Thanked 245 Times in 245 Posts
    This will involve something besides HTML and CSS, it will need javascript or a server side language, and probably both, to handle all the size information and perform all the conditional operations that will be needed to do this automatically. I doubt you'll get someone to jump up and say 'that would be a fun project, I'll just do it for free'. So maybe first just do an intensive search, in case someone has already published a way. Or you may figure out a way using HTML/CSS by separating the images by size in different divs, that suits you.

  • #5
    New Coder
    Join Date
    Nov 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi guys,

    thanks a lot for your help already! thanks optimus for getting me started on this!

    i didn't have time to answer, but it's not resolved. i'm planning on using
    php to do this in an automatic way. i don't have a link yet. i will start on the script today.

    any thought are welcome ofcourse

    cheers

  • #6
    New Coder
    Join Date
    Nov 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi guys,

    i made a test, but something very strange happens:
    http://www.storylinedesign.be/sites/test.php

    when i compare my sourcecode to what firebug makes of it, it seems like the "left:xx" style parts just disappear...

    source code:
    Code:
      
    <div width="1000">
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:0;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:50;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:100;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:150;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:200;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:250;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:300;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:350;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:400;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:450;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:500;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:550;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:600;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:650;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:700;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:750;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:800;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:850;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:900;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:950;" />
    </div>
    the source code looks good, but the images are all stacked on top of eachother...

    anyone know why?

    thanks!

    jimmy
    Last edited by jimmyfortune; 11-11-2010 at 03:18 PM.

  • #7
    New Coder
    Join Date
    Nov 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi guys,

    i made a test, but something very strange happens:
    http://www.storylinedesign.be/sites/test.php

    when i compare my sourcecode to what firebug makes of it, it seems like the "left:xx" style parts just disappear...

    source code:
    Code:
      
    <div width="1000">
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:0;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:50;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:100;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:150;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:200;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:250;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:300;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:350;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:400;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:450;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:500;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:550;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:600;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:650;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:700;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:750;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:800;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:850;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:900;" />
                  <img src="/empty.jpg" width="50" height="30" style="position:absolute; top:0; left:950;" />
    </div>
    the source code looks good, but the images are all stacked on top of eachother...

    anyone know why?

    thanks!

    jimmy

  • #8
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,311
    Thanks
    11
    Thanked 284 Times in 283 Posts
    For one, you need some units on the left tags. Inches? Miles? Pixels? My guess is pixels, so left:100px, etc.

    Dave

  • #9
    New Coder
    Join Date
    Nov 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried that already and it's not helping

  • #10
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,311
    Thanks
    11
    Thanked 284 Times in 283 Posts
    Could you show the actual code that's failing? I can't get to the link you provided. You might also clean up the rest of your code so that it validates, but I don't see a reason it would fail as shown, if you updated it with the "px" I mentioned. You might correct the <div width="1000"> to validate as well, but I don't know that it would cause the issue you're seeing.

    Dave

  • #11
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello jimmyfortune,
    Run your code through the validator real quick. It'll show you a few more errors that are causing you trouble:

    http://validator.w3.org/check?verbos...tes%2Ftest.php


    Would resizing the images be easier? Have a look at this -
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {background: #FC6;}
    #container {
    	width: 500px;
    	margin: 30px auto;
    	background: #999;
    	overflow: auto;
    }
    img {
    	width: 50px;
    	height: 30px;
    	float: left;
    	border: 1px solid #ff0;;
    }
    </style>
    </head>
    <body>
        <div id="container">
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="20x15.jpg" width="20" height="15" alt="20x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x15.jpg" width="40" height="15" alt="40x15" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
        <img src="40x30.jpg" width="40" height="30" alt="40x30" />
    <!--end container--></div>
    </body>
    </html>
    Last edited by Excavator; 11-11-2010 at 04:40 PM.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #12
    New Coder
    Join Date
    Nov 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    damn you were right. i needed to place "px" for the top and left position.
    i thought i did it, but i only did it for the width and height.

    thanks guys!


  •  

    Posting Permissions

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