![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. I'm quite new to CSS and have tried to fix this now for a long time. Can anyone see where I'm going wrong? Thank you in advance. Raj #wrap{ background: #faf1d4 url(../images/bg.gif) repeat-x; } #text{ float: left; width: 1000px; padding-left: 20px; padding-right: 20px; background-color: #f5e9cc; margin-left: auto; margin-right: auto; } the relevant html code is: div id="wrap" <div id="text" <p>abcdef</p </div /div |
#3
| |||
| |||
|
|
In article <2008031409494775249-raj@nospamcom>, raj <raj (AT) nospam (DOT) com> wrote: Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. I'm quite new to CSS and have tried to fix this now for a long time. Can anyone see where I'm going wrong? Thank you in advance. Raj #wrap{ background: #faf1d4 url(../images/bg.gif) repeat-x; } #text{ float: left; width: 1000px; padding-left: 20px; padding-right: 20px; background-color: #f5e9cc; margin-left: auto; margin-right: auto; } the relevant html code is: div id="wrap" <div id="text" <p>abcdef</p </div /div Have you tried #text{ float: left; width: 1000px; background-color: #f5e9cc; text-align: center; ? (1000px is a lot to be expecting on a webpage, not usually advisable) |
#4
| |||
| |||
|
|
Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. |
|
I'm quite new to CSS and have tried to fix this now for a long time. Can anyone see where I'm going wrong? Thank you in advance. Raj #wrap{ background: #faf1d4 url(../images/bg.gif) repeat-x; } #text{ float: left; ^^^^^^^^^^^ |
|
width: 1000px; padding-left: 20px; padding-right: 20px; background-color: #f5e9cc; margin-left: auto; margin-right: auto; } the relevant html code is: div id="wrap" <div id="text" <p>abcdef</p </div /div |
#5
| |||
| |||
|
|
On 2008-03-14, raj <raj (AT) nospam (DOT) com> wrote: Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. You can't centre a float. It floats to one side or the other. I'm quite new to CSS and have tried to fix this now for a long time. Can anyone see where I'm going wrong? Thank you in advance. Raj #wrap{ background: #faf1d4 url(../images/bg.gif) repeat-x; } #text{ float: left; ^^^^^^^^^^^ Just get rid of this line and it should centre OK. width: 1000px; padding-left: 20px; padding-right: 20px; background-color: #f5e9cc; margin-left: auto; margin-right: auto; } the relevant html code is: div id="wrap" <div id="text" <p>abcdef</p </div /div |
#6
| |||
| |||
|
|
On 2008-03-14, raj <raj (AT) nospam (DOT) com> wrote: Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. You can't centre a float. It floats to one side or the other. |
#7
| |||
| |||
|
|
Ben C wrote: On 2008-03-14, raj <r... (AT) nospam (DOT) com> wrote: Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. You can't centre a float. It floats to one side or the other. Though I know that and I can understand it I was wondering of the following senario: I have a div with width 100% (so it goes it fills the whole viewport). I want a div inside it with some pictures: div id="wrap" * * * * <div * * * * <img src="blah.jpg"> <img src="blah1.jpg"> <img src="blah2.jpg"> <img src="blah3.jpg" * * * * </div /div By default #wrap div will also have width:100%. What if I want the div containing the imgs to be centered. The only way I know is to explicit set the width like: #wrap div img {margin-left:2em} #wrap div {width:50em;margin:0 auto} But I don't know the overall width of the images, so it's wrong to set a width. How can I accomplish that? thanks in advance |
#8
| |||
| |||
|
|
Ben C wrote: On 2008-03-14, raj <raj (AT) nospam (DOT) com> wrote: Hi everyone, I'm a newbie and can;t get this code to work. It is supposed to center the text block within the wrap, but the centering won't work. You can't centre a float. It floats to one side or the other. Though I know that and I can understand it I was wondering of the following senario: I have a div with width 100% (so it goes it fills the whole viewport). I want a div inside it with some pictures: div id="wrap" <div <img src="blah.jpg"> <img src="blah1.jpg"> <img src="blah2.jpg"> <img src="blah3.jpg" </div /div By default #wrap div will also have width:100%. What if I want the div containing the imgs to be centered. The only way I know is to explicit set the width like: #wrap div img {margin-left:2em} #wrap div {width:50em;margin:0 auto} But I don't know the overall width of the images, so it's wrong to set a width. How can I accomplish that? |
#9
| |||
| |||
|
|
What you want is "centred shrink-to-fit" for which you need inline-block (wait for Firefox 3), tables, or JavaScript. See also dorayme's page: http://netweaver.com.au/alt/shrinkTo...rinkToFit.html |
#10
| |||
| |||
|
|
display:table is just fine |
![]() |
| Thread Tools | |
| Display Modes | |
| |