473,420 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

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 8362
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
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.