Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Center div within a div
Old 06-07-2007, 02:16 PM Center div within a div
Novice Talker

Posts: 9
Trades: 0
Hi all,

I have a wrapper div which is centered within which is a another div which has an <ul> containing images that I want to center, but I'm getting alittle lost.

HTML Code:
	<style>
		html, body{
			height:100%;
			margin:0;
			padding:0;
			background:#gray;
		}
		#wrapper{
			width:700px;
			min-height:100%;
			margin:0 auto;
			position:relative;
			background:white;
		}
		#gallery li{
			width:85px;
			height:64px;
			border:solid #ccc;
			border-width:0 1px 1px 0;
			background:#fff;
			text-align:center;
			position:relative;
			float:left;
			display:inline;
			margin:5px;
			padding:3px;
		}
		#gallery {
			border:1px solid red;
			text-align:center;
		}
	</style>
</head>
<body>
	<div id="wrapper">
		<div id="gallery">
			<ul>
				<li><a href="#"><img src="1_resize/01.jpg" alt="" title="" /></a></li>
				<li><a href="#"><img src="1_resize/02.jpg" alt="" title="" /></a></li>
			</ul>
		</div>
	</div>
</body>
</html>
cooper10 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-08-2007, 05:27 AM Re: Center div within a div
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
you can't centre an element that has float:left and display:inline applied to it

if it's the <ul> to centre and then float the <li>'s inside the <ul> it's just the same as centring a <div>.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-12-2007, 11:36 PM Re: Center div within a div
Experienced Talker

Posts: 30
Name: Ben Henick
Trades: 0
It'd be easier to grasp what you're trying for, if you could give some kind of sketch or other example.

Assuming that you simply want to center the list inside of some other container, you'd want to do something like the following:

Code:
* html #container {

  text-align: center;

}

#container ul#myUL {

  width: 50%;
  margin-left: auto;
  margin-right: auto;

}

* html #container * {

  text-align: left;

}
Assuming that you have an element called 'container' which itself contains an unordered list called 'myUL', the list will be half as wide (barring padding or borders, of course) as #container and rest equidistant from the left and right margins of #container.

The * html rules produce the same behavior *sigh* in IE6.
persist1 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Center div within a div
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15510 seconds with 12 queries