This is a discussion on "Making centred div hug content" within the Web Page Design section. This forum, and the thread "Making centred div hug content are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
Making centred div hug content
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Making centred div hug content
Hi,
I have a page with images centred by putting them in a div with a class "center".
Any ideas? |
|
|
|
|||
|
Re: Making centred div hug content
Could you post a link or your full code (including CSS)?
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Dec 9th, 2007 at 18:11. |
|
||||
|
Re: Making centred div hug content
If you don't set a width on .center, it will stretch across the entire page. Check out the A List Apart article on CSS drop shadows. This should help with what you want to acheive
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
|
|||
|
Re: Making centred div hug content
Yes, thats true aso186. You must set the width of the div elements (that you want to center), otherwise it will stretching to occupy it's Parent DIV
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
|
|||
|
Re: Making centred div hug content
Oh. So it's impossible to make it hug without giving it a width.
So my code where the size of the image is not known is not possible. |
|
|||
|
Re: Making centred div hug content
Quote:
Yes, centred elements need an explicit width. But no, you do not have to set this width yourself. The image itself sets the width; all you need is for the box to "shrink-wrap" around it (but you should set the image's width explicitly in your <img> tag). Floating an element causes it to "shrink-wrap". So to start with, float your outermost <div> with {float: left}. Then add another <div> around the outside, and position this in the centre with {margin: 0 auto}. You'll probably run across some IE bugs, unfortunately. Test in Firefox first to see whether it works at all. |
|
|||
|
Re: Making centred div hug content
Um....
I'm afraid neither of these are working for me. the floating div with the center div round it does shrink wrap it but it just floats to the left anyway. Giving the div a width doesn't make it shrink at all.
|
|
|||
|
Re: Making centred div hug content
Post a link for lazy people like me.
|
|
|||
|
Re: Making centred div hug content
Tricky to post a link because it's a live website - here's a version of it though http://www.getoutofglasgow.com/test.htm
|
|
|||
|
Re: Making centred div hug content
I don't see the problem on your test page, but note that you have a massive 113 XHTML errors. If you don't fix the errors, it makes a mockery of the whole debugging process.
|
|
|||
|
Re: Making centred div hug content
OK,
It's taken all night (my pages are dynamically created - well not the test page) but they now adhere to the strict XHTML standard (my css is still a bit dodgy) but no change. http://www.getoutofglasgow.com/test.htm http://www.getoutofglasgow.com/test2.htm Any ideas? |
|
|||
|
Re: Making centred div hug content
And now I've fixed the css with the css validator.
Still no joy! |
|
|||
|
Re: Making centred div hug content
Is this what you want it to do?
CSS
|
|
|||
|
Re: Making centred div hug content
Hmm.
Perhaps the image needs to be set to {display: block}. At this stage, I would consider creating a minimal test case, just to prove the concept of using a wrapper to centre a float. Prove the idea right or wrong, and then move on from there. |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems making the content area have a dynamic height | blizeH | Web Page Design | 41 | Aug 13th, 2007 01:19 |
| div wrap height centred | jillcary | Web Page Design | 1 | Jul 24th, 2007 16:05 |
| printing style sheets to provide A5 size printouts without making content smaller | paulbarris | Web Page Design | 5 | May 9th, 2007 19:37 |
| centred table not touching the top of the screen? | acrobat | Web Page Design | 9 | Apr 14th, 2007 00:05 |
| place following divs in one page centred div | antonyx | Web Page Design | 12 | Dec 30th, 2005 21:00 |