![]() |
Auto margin?
Hi!
I want to center some divs, and I recently learned about margin-left: auto; margin-right: auto; which worked great when i wanted to center my website! However, it doesn't quite work here.. Possibly because I floated some things inside. http://img136.imageshack.us/img136/4829/origz.jpg http://img18.imageshack.us/img18/4469/orig2t.jpg As you see, on the first picture it displays 4 products(there will always be a maximum of 3 products per row) on 2 rows. It looks pretty centered, because I matched the margins for specifically 3 products per line. If you check the second picture, where only 2 products is displayed, it is not centered. And if there's only 1 product it's even less centered. I want to somehow be able to center these based on nr of products on the line. I've used a markup like this: HTML Code:
<div id="main">Code:
#products { padding: 10px; padding-bottom: 0; margin-bottom: 25px; margin-top: 15px; }Any help please? |
All content is natively floated left, this means that the 2 boxes will shift to the left. You could apply a special class that sets an absolute position when there are less than 3 items on a given line, or just let the content float left.
|
Yes but, the 2 boxes are inside the .product-line which is not floated.. so if I'm able to center that, shouldn't the floated boxes inside be centered then aswell?
I tried absolute, but then all lines starts from the same origin(the first line) so they get all clumped up. But I think I know how to solve this. I just set the margin-left on the .product-line based on how many products there is in the line. Requires some math, and code will be clunky, but whatever.. |
inline-block and some hacking for the browsers that doesn't support it maybe?
|
Mm, yea.. I'm a complete newbie when it comes to CSS so how does inline-block work in this case?
|
Quote:
"inline-block This value causes an element to generate a block box, which itself is flowed as a single inline box, similar to a replaced element. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an inline replaced element. " |
is margin:auto; what you are looking for? Do note that margin:auto; requires that you set a width to the element.
Code:
.product-line{Code:
.product_line{ |
Quote:
Quote:
|
Quote:
Still as i said earlier comes with some quirks that you need to take into account, always easier to help with live example aswell. |
Quote:
Regarding underscore, I have quite alot of element with a dash in the name. If I get a complaint I'll change it to an underscore :-) |
* Thread Cleaned *
Summary: claims were made that at least one older version of Opera does not like class names containing hyphens. No source was cited to back up that claim so take it with a pinch of salt and do your own research as always. Deleted posts were off-topic (ie. not dealing with Tanax's issue) and some broke our rules. Please kindly continue the discussion on-topic, or not at all. Thank you. |
| All times are GMT. The time now is 03:19 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0