Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2010, 07:21 PM   PM User | #1
jimmyfortune
New Coder

 
Join Date: Nov 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
jimmyfortune is an unknown quantity at this point
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
jimmyfortune is offline   Reply With Quote
Old 11-10-2010, 02:46 AM   PM User | #2
optimus203
Regular Coder

 
optimus203's Avatar
 
Join Date: Sep 2008
Location: CT
Posts: 316
Thanks: 22
Thanked 16 Times in 15 Posts
optimus203 is an unknown quantity at this point
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
optimus203 is offline   Reply With Quote
Old 11-10-2010, 12:13 PM   PM User | #3
mahesh2010
New Coder

 
Join Date: Jun 2010
Location: usa
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
mahesh2010 is an unknown quantity at this point
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
mahesh2010 is offline   Reply With Quote
Old 11-11-2010, 02:07 AM   PM User | #4
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,226
Thanks: 11
Thanked 156 Times in 156 Posts
DrDOS is infamous around these parts
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.
DrDOS is offline   Reply With Quote
Old 11-11-2010, 09:04 AM   PM User | #5
jimmyfortune
New Coder

 
Join Date: Nov 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
jimmyfortune is an unknown quantity at this point
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
jimmyfortune is offline   Reply With Quote
Old 11-11-2010, 10:43 AM   PM User | #6
jimmyfortune
New Coder

 
Join Date: Nov 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
jimmyfortune is an unknown quantity at this point
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..
jimmyfortune is offline   Reply With Quote
Old 11-11-2010, 03:19 PM   PM User | #7
jimmyfortune
New Coder

 
Join Date: Nov 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
jimmyfortune is an unknown quantity at this point
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
jimmyfortune is offline   Reply With Quote
Old 11-11-2010, 03:24 PM   PM User | #8
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 906
Thanks: 4
Thanked 212 Times in 211 Posts
tracknut is an unknown quantity at this point
For one, you need some units on the left tags. Inches? Miles? Pixels? My guess is pixels, so left:100px, etc.

Dave
tracknut is offline   Reply With Quote
Old 11-11-2010, 04:18 PM   PM User | #9
jimmyfortune
New Coder

 
Join Date: Nov 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
jimmyfortune is an unknown quantity at this point
i tried that already and it's not helping
jimmyfortune is offline   Reply With Quote
Old 11-11-2010, 04:35 PM   PM User | #10
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 906
Thanks: 4
Thanked 212 Times in 211 Posts
tracknut is an unknown quantity at this point
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
tracknut is offline   Reply With Quote
Old 11-11-2010, 04:38 PM   PM User | #11
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
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>
__________________
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

Last edited by Excavator; 11-11-2010 at 04:40 PM..
Excavator is offline   Reply With Quote
Old 11-11-2010, 05:36 PM   PM User | #12
jimmyfortune
New Coder

 
Join Date: Nov 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
jimmyfortune is an unknown quantity at this point
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!
jimmyfortune is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:47 AM.


Advertisement
Log in to turn off these ads.