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-18-2012, 03:27 AM   PM User | #1
Windbrand
New Coder

 
Join Date: Sep 2011
Posts: 44
Thanks: 4
Thanked 0 Times in 0 Posts
Windbrand is an unknown quantity at this point
Row of centered images and text

I'm trying to create a row of banner-like images, centered and gap between each auto-adjusted, each with an aligned text below it. I tried to use the CSS property columns, but I'm unable to change the amount of space between each element.

Picture:


This is what I have so far:

HTML:
Code:
<div class="container">

	<div id="pic1">
		<img src="pictures/characters/1.png">
		<br>
		<br>
		<span id="pic1text">text1</span>
	</div>
				
	<div id="pic2">
		<img src="pictures/characters/2.png">
		<br>
		<br>
		<span id="pic2text">text2</span>
	</div>
				
	<div id="pic3">
		<img src="pictures/characters/3.png">
		<br>
		<br>
		<span id="pic3text">text3</span>
	</div>
				
	<div id="pic4">
		<img src="pictures/characters/4.png">
		<br>
		<br>
		<span id="pic4text">text4</span>
	</div>
				
	<div id="pic5">
		<img src="pictures/characters/5.png">
		<br>
		<br>
		<span id="pic5text">text5</span>
	</div>
				
</div>
CSS:
Code:
.container{
	width:950px;
	height:350px;
	-moz-column-count:8; /* Firefox */
	-webkit-column-count:8; /* Safari and Chrome */
	column-count:8;
}

/*div of each image*/
.container > div {
	display:inline;
	height:350px;
	width:125px;
}
But the moment I add "column-gap:5px;" the pictures won't be in a single row anymore and the formatting is completely messed up. I also need an identifier for each text, as I'm gonna need to fade in/out these text when the mouse hovers over each image, which I'll do once the formatting is done.

Last edited by Windbrand; 11-18-2012 at 03:33 AM..
Windbrand is offline   Reply With Quote
Old 11-18-2012, 03:45 AM   PM User | #2
comport9
New Coder

 
Join Date: Oct 2012
Posts: 25
Thanks: 2
Thanked 0 Times in 0 Posts
comport9 is an unknown quantity at this point
I don't know about columns, but you could just use "float: left" instead. Then your "columns" will be side-by-side without any additional fuss.
comport9 is offline   Reply With Quote
Old 11-18-2012, 04:23 AM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,375
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
@Windbrand the CSS3 column-count property is used to divide text in the div element into columns, like a news paper. It has no place here. Use the float as comport9 said and set a margin-right for the space between them. You also should use a padding-left on the container to move the divs to the right.

You don't need .container > div A .container div will work.
sunfighter is offline   Reply With Quote
Old 11-18-2012, 06:19 AM   PM User | #4
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Using <br /> to space things out is a bad idea. A better option is to use margin and padding and to make your layout elastic (auto-adjusted as you put it) you can use % for dimensions.

Here is a basic example of an elastic layout with 4 images. If you have a different number of images, just adjust the %'s for .picContainer in the css to suit.

The images and their container will automatically shrink or enlarge as you change the browser size.

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></title>
        <style type="text/css">
            #container {
                width: 70%;
                margin: 30px auto 0px auto;
                border: 3px solid blue;
                overflow: hidden;
            }
            .picContainer{
                float: left;
                width: 20%;
                margin: 0px 2.5% 0% 2.5%;
            }
            .picContainer img {
                display: block;
                width: 100%;
            }
            .picContainer p{
                margin: 10px 0px 0px 0px;
                text-align: center;
            }
            #gutter{
                margin: 10px 10px 10px 10px;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="gutter">
                <div class="picContainer" >
                    <img src="image1.jpg" alt="" />
                    <p>caption 1</p>
                </div>
                <div class="picContainer">
                    <img src="image2.jpg" alt="" />
                    <p>caption 2</p>
                </div>
                <div class="picContainer">
                    <img src="image3.jpg" alt="" />
                    <p>caption 3</p>
                </div>
                <div class="picContainer" >
                    <img src="image4.jpg" alt="" />
                    <p>caption 4</p>
                </div>
            </div>
        </div>
    </body>
</html>

Last edited by minder; 11-18-2012 at 06:28 AM..
minder is offline   Reply With Quote
Old 11-18-2012, 09:23 AM   PM User | #5
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 Windbrand,
Floats are great for putting elements side by side but you'll have to do the math to center them.
Look at this approach (the margin is what controls the space between them)
Code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
html, body {
	margin: 0;
	background: #fc6;
}
.container{
	width: 950px;
	padding: 10px 10px 50px;
	text-align: center;
	background: #333;
}
.container > div {
	height: 350px;
	width: 125px;
	margin: 0 5px;
	display: inline-block;
	background: #f00;
}
</style>
</head>
<body>
	<div class="container">
        <div id="pic1">
            <img src="pictures/characters/1.png">
            <br>
            <br>
            <span id="pic1text">text1</span>
        </div>				
        <div id="pic2">
            <img src="pictures/characters/2.png">
            <br>
            <br>
            <span id="pic2text">text2</span>
        </div>				
        <div id="pic3">
            <img src="pictures/characters/3.png">
            <br>
            <br>
            <span id="pic3text">text3</span>
        </div>				
        <div id="pic4">
            <img src="pictures/characters/4.png">
            <br>
            <br>
            <span id="pic4text">text4</span>
        </div>				
        <div id="pic5">
            <img src="pictures/characters/5.png">
            <br>
            <br>
            <span id="pic5text">text5</span>
        </div>
    <!--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
Excavator 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 07:53 PM.


Advertisement
Log in to turn off these ads.