473,508 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Center div

Hello,

I have two div's:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?
I tried the following CSS but it is not working:

..container
{
border: solid 1px red;
text-align: center;
}

..message
{
border: solid 1px blue;
clear: both;
margin: 20px auto;
text-align: left;
width: 100%;
}

Thanks,
Miguel

Jan 10 '07 #1
10 8363
In article
<11**********************@i56g2000hsf.googlegroups .com>,
"shapper" <md*****@gmail.comwrote:
Hello,

I have two div's:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?

Have you tried:

..container {

border: solid 1px red;
text-align: center;
}

..message {

border: solid 1px blue;
margin: 20px;
}

--
dorayme
Jan 11 '07 #2
Yes,

In Firefox and Opera the message div gets outside the container to the
right and in IE the container gets bigger then the defined width.

Any idea?

Thanks,
Miguel

dorayme wrote:
In article
<11**********************@i56g2000hsf.googlegroups .com>,
"shapper" <md*****@gmail.comwrote:
Hello,

I have two div's:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?


Have you tried:

.container {

border: solid 1px red;
text-align: center;
}

.message {

border: solid 1px blue;
margin: 20px;
}

--
dorayme
Jan 11 '07 #3
In article
<11*********************@k58g2000hse.googlegroups. com>,
"shapper" <md*****@gmail.comwrote:

>
dorayme wrote:
In article
<11**********************@i56g2000hsf.googlegroups .com>,
"shapper" <md*****@gmail.comwrote:
Hello,
>
I have two div's:
>
<div class="container">
<div class="message">message</div>
</div>
>
I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.
>
How can I do this?

Have you tried:

.container {

border: solid 1px red;
text-align: center;
}

.message {

border: solid 1px blue;
margin: 20px;
}
Yes,

In Firefox and Opera the message div gets outside the container to the
right and in IE the container gets bigger then the defined width.

Any idea?
Best not to top post, fixed here. You tried it exactly? you took
out your auto? and you used my code? And in FF it had the faults
you mention? Can you please post a URL showing this.

--
dorayme
Jan 11 '07 #4

shapper;671546 Wrote:
Hello,

I have two div's:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?
I tried the following CSS but it is not working:

..container
{
border: solid 1px red;
text-align: center;
}

..message
{
border: solid 1px blue;
clear: both;
margin: 20px auto;
text-align: left;
width: 100%;
}

Thanks,
Miguel
Without looking at the actual design and what you want to do, I'd say
this might work for you.

.message {border:solid 1px blue;margin:20px;margin-left:
auto;margin-right:auto;text-align:left;width:100%}

with this, I'd change the width to something, can't remember right at
this point of 100% width won't bring it from left to right full size.
Try giving it a width if the 100% doesn't seem to do anything.

Hope it helps. :) Lemme know.
--
CatBones

XHTMLIT.COM - PSD TO
XHTML/CSS CONVERSION SERVICE (\"HTTP://WWW.XHTMLIT.COM\")
Get your Design (.PSD or .PNG) converted into valid XHTML & CSS fast
and easy.
We cut, crop and professionally hand code it within 24 hours or your
money back guaranteed.
Visit http://www.hostingforum.ca today

Jan 11 '07 #5
CatBones wrote:
shapper;671546 Wrote:
Hello,

I have two div's:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?
I tried the following CSS but it is not working:

..container
{
border: solid 1px red;
text-align: center;
}

..message
{
border: solid 1px blue;
clear: both;
margin: 20px auto;
text-align: left;
width: 100%;
}

Thanks,
Miguel

Without looking at the actual design and what you want to do, I'd say
this might work for you.

.message {border:solid 1px blue;margin:20px;margin-left:
auto;margin-right:auto;text-align:left;width:100%}

with this, I'd change the width to something, can't remember right at
this point of 100% width won't bring it from left to right full size.
Try giving it a width if the 100% doesn't seem to do anything.

Hope it helps. :) Lemme know.
--
CatBones

XHTMLIT.COM - PSD TO
XHTML/CSS CONVERSION SERVICE (\"HTTP://WWW.XHTMLIT.COM\")
Get your Design (.PSD or .PNG) converted into valid XHTML & CSS fast
and easy.
We cut, crop and professionally hand code it within 24 hours or your
money back guaranteed.
Visit http://www.hostingforum.ca today
Sorry about top post but I am kind of new to this type of posting.

Anyway, I am working with ASP.NET and I am developing a control which
generates the HTML code. In this moment the generated code is as
follows:

<div id="container" class="container" style="width: 100%; text-align:
center;">
<div id="message" class="message" style="margin: 20px;">
<img id="icon" src="Warning.jpg" style="border-width: 0px;">
<span id="messageText" style="display: block; text-align:
left;">Text</span>
</div>
</div>

In both FF and Opera I don't get the top and bottom margin.
In IE I don't get the bottom margin.

Note that the class "container" and "message" are just this:
.container {background-color:red}
.message {background-color:blue}

I added display:block to messageText because I want it to appear after
the Icon.

Any idea what I am doing wrong?

Thanks,
Miguel

Jan 11 '07 #6

shapper wrote:
CatBones wrote:
shapper;671546 Wrote:
Hello,
>
I have two div's:
>
<div class="container">
<div class="message">message</div>
</div>
>
I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.
>
How can I do this?
I tried the following CSS but it is not working:
>
..container
{
border: solid 1px red;
text-align: center;
}
>
..message
{
border: solid 1px blue;
clear: both;
margin: 20px auto;
text-align: left;
width: 100%;
}
>
Thanks,
Miguel
Without looking at the actual design and what you want to do, I'd say
this might work for you.

.message {border:solid 1px blue;margin:20px;margin-left:
auto;margin-right:auto;text-align:left;width:100%}

with this, I'd change the width to something, can't remember right at
this point of 100% width won't bring it from left to right full size.
Try giving it a width if the 100% doesn't seem to do anything.

Hope it helps. :) Lemme know.
--
CatBones

XHTMLIT.COM - PSD TO
XHTML/CSS CONVERSION SERVICE (\"HTTP://WWW.XHTMLIT.COM\")
Get your Design (.PSD or .PNG) converted into valid XHTML & CSS fast
and easy.
We cut, crop and professionally hand code it within 24 hours or your
money back guaranteed.
Visit http://www.hostingforum.ca today

Sorry about top post but I am kind of new to this type of posting.

Anyway, I am working with ASP.NET and I am developing a control which
generates the HTML code. In this moment the generated code is as
follows:

<div id="container" class="container" style="width: 100%; text-align:
center;">
<div id="message" class="message" style="margin: 20px;">
<img id="icon" src="Warning.jpg" style="border-width: 0px;">
<span id="messageText" style="display: block; text-align:
left;">Text</span>
</div>
</div>

In both FF and Opera I don't get the top and bottom margin.
In IE I don't get the bottom margin.

Note that the class "container" and "message" are just this:
.container {background-color:red}
.message {background-color:blue}

I added display:block to messageText because I want it to appear after
the Icon.

Any idea what I am doing wrong?

Thanks,
Miguel
There is something else I realized:
I placed my container DIV inside a new CONTAINER div.
In IE, my container DIV don't full extend to the new CONTAINER div. Any
idea why?

Thanks,
Miguel

Jan 11 '07 #7
shapper wrote:
>>
Sorry about top post but I am kind of new to this type of posting.

Anyway, I am working with ASP.NET and I am developing a control which
generates the HTML code. In this moment the generated code is as
follows:

<div id="container" class="container" style="width: 100%; text-align:
center;">
<div id="message" class="message" style="margin: 20px;">
<img id="icon" src="Warning.jpg" style="border-width: 0px;">
<span id="messageText" style="display: block; text-align:
left;">Text</span>
</div>
</div>

In both FF and Opera I don't get the top and bottom margin.
In IE I don't get the bottom margin.

Note that the class "container" and "message" are just this:
.container {background-color:red}
.message {background-color:blue}

I added display:block to messageText because I want it to appear after
the Icon.

Any idea what I am doing wrong?
Yes. You are asking for help, getting it, and then ignoring it.
Do what dorayme suggested. Do just that. Do not do what CatBones
suggested; it doesn't work. Try dorayme's suggestion, which also worked
for me, despite your claim to the contrary.

>
There is something else I realized:
I placed my container DIV inside a new CONTAINER div.
So, you have changed the problem for us again? In that case, you will
have to restate the new conditions completely and clearly. Provide a URL
next time, too. I no longer understand what problem you want to solve.
It appears that all of the preceding discussion has been for a problem
you no longer care about. Or what?
In IE, my container DIV don't full extend to the new CONTAINER div. Any
idea why?
See above.

--
John
Jan 11 '07 #8
CatBones wrote :
.message {border:solid 1px blue;margin:20px;margin-left:
auto;margin-right:auto;text-align:left;width:100%}

with this, I'd change the width to something, can't remember right at
this point of 100% width won't bring it from left to right full size.
Try giving it a width if the 100% doesn't seem to do anything.
width: auto
will make the design scalable (fluid, flexible). Setting width: 100%
contributes to create a rigid, over-constrained design which will not
suit fluid/scalable webpage design.

width: auto
has to be understood as "take as much as you can" from left to right
from its containing block.

Gérard
--
remove blah to email me
Jan 11 '07 #9

Gérard Talbot wrote:
CatBones wrote :
.message {border:solid 1px blue;margin:20px;margin-left:
auto;margin-right:auto;text-align:left;width:100%}

with this, I'd change the width to something, can't remember right at
this point of 100% width won't bring it from left to right full size.
Try giving it a width if the 100% doesn't seem to do anything.

width: auto
will make the design scalable (fluid, flexible). Setting width: 100%
contributes to create a rigid, over-constrained design which will not
suit fluid/scalable webpage design.

width: auto
has to be understood as "take as much as you can" from left to right
from its containing block.

Gérard
--
remove blah to email me
Sorry,

Maybe I didn't explain myself the right way but it was because I
couldn't.
I am using ASP.NET server controls and sometimes they render as not
expected.

At the same time I had a few textboxes which where behaving in a
strange way and that were affecting my interpretation of my problem.

I was setting my textboxes to 100% and it seems that when they are
inside a div they have two behaviors, depending on the browser:
1. Get to the limit of the div as expected
2. Pass the right limit of the div
3. Pass the right limit of the div and pushes further altering the
width.

Because I had textboxes inside my div I didn't realized it was this
that caused the problem.

This textboxes thing is quite strange.

Anyway, in relation to my problem it is solved.

I never posted an URL because I have it in my computer and everything
is integrated in a ASP.NET project which in this moment it would be
hard to place it online.

Thanks,
Miguel

Jan 12 '07 #10
shapper schrieb:
I never posted an URL because I have it in my computer and everything
is integrated in a ASP.NET project which in this moment it would be
hard to place it online.
Then view your project in a browser, save the rendered code (produced by
your ASP.NET project), reduce it to the minimum and put in on some web
space for us to look at.

It's not that difficult.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jan 12 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3227
by: Alex | last post by:
Hi Everone, I need some advice on how to setup 4 columns where the outside two are absolute (120px) and the inner two (side by side) are relevent (Fluid) and change with the screen. Here's my...
2
7889
by: Claude Shea | last post by:
Is DB2 Development Center an addon product that I have to download or purchase separately? I can't seem to find it in any of my downloads or on any of my CDs. Is it available for all versions of...
1
1790
by: Henry Reardon | last post by:
I have been having problems with the Development Center for several days now. It seemed to be working fine when I initially installed DB2 (LUW) Version 8 (FP7) and upgraded to FP8, except that I...
4
6250
by: Joey | last post by:
Does anyone know how to center this sample webpage in Firefox? If so, will you provide the example as it applies to this sample webpage? I have read numerous posts and articles on how to center...
1
3467
by: judacris | last post by:
I've seen the threads here about molding 2 divs in a centered fashion. but I can't seem to solve this thing. my blogger blog is functioning well on my site for now, but the blog feed (left) and...
24
3575
by: GloStix | last post by:
I'm trying to center this banner, it's in a div that has the same width so it's not exactly "centering" but it's screwed up, It works in safari but in Firefox it's messed up. I uploaded a Video to...
2
16343
by: yangtono | last post by:
Hi, I am creating a table to list some data. The table is using a sorting and highlight function that I found from the net. I can't attach image here, basically html will wrap the heading,...
14
2384
by: gaijinco | last post by:
I was a hobbist web coder for years but I had to sidestep for a while. Now I'm trying to return to it and I'm trying to clarify how am I supposed to do somethings with CSS v.s. HTML and I'm...
13
3267
by: Stevo | last post by:
I've found that for IE6+, if you add the property text-align:center to a DIV, then *anything* inside it gets centered. That can be a table, an object/embed, another DIV, an image, or some text. ...
10
2580
by: dougancil | last post by:
I have a web page that I converted from a psd file to html with Photoshop and imported into Dreamweaver. The problem I'm having is that some viewers comment on the fact that the page is left...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.