Jump to content

How to put div elements centered in same line? (containing images and text)


Recommended Posts

This is the code:

 


<html>
<head>
	<style>
		#parent{
			border: 1px solid black;
			width: 90%;
			position: relative;
			left: 5%;
			padding: 1%;
		}

		#parent > div{
			width: 10%;
			border: 1px solid #ccc;
		}
		#parent > div > img{
			width: 100%;
		}
	</style>
</head>
<body>
	<div id="parent">
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div><div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
		<div>
			Planet Earth
			<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSmMWgMiKcAfjiYUAUz8dEM90_KrDnlXq4_6hnzKd83W03ykxal">
			user : Franko
		</div>
	</div>
</body>
</html>

 

Display: inline-block does not work in IE.

Floats are not a solution because it makes the parent div have a small height.

It needs to look like this:

https://www.box.com/s/2b73018fa44f89bea191

 

The content is dynamic, so fixed height won't work also.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.