Solved

How to center content?

Posted on 2013-01-21
18
345 Views
Last Modified: 2013-01-21
How can I get all of the content below to center?  

In the div mc_embed_signup, why does text-align:center have no effect?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<title></title>
	</head>
	<body>

<!-- Begin MailChimp Signup Form -->
<link href="http://cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<div id="mc_embed_signup" style="background:#f8f8f8;text-align:center;width:500px;">
<form action="" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<label for="mce-EMAIL">Just sign up to our newsletter to receive your free copy of our latest ebook and content.</label>
<input type="text" value="" name="FNAME" class="email" id="mce-FNAME"placeholder="first name" required style="width:200px;">
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required style="width:200px;"><div><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" style="width:200px;"></div>
</form>
</div>
<!--End mc_embed_signup-->
	</body>
</html>

Open in new window

0
Comment
Question by:brettr
  • 6
  • 5
  • 4
  • +1
18 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 38802168
Try adding "margin: auto;" to your style:

<div id="mc_embed_signup" style="background:#f8f8f8;text-align:center;width:500px; margin: auto;">

Open in new window

0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 125 total points
ID: 38802172
If you are trying to center it in the page then do it this way:

<div id="mc_embed_signup" style="background:#f8f8f8;text-align:center;width:500px; margin:auto;">

If that does not solve it post a link to the page so we can see if the obsolete doctype or something else is part of the problem.

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38802179
Sorry kaufmed, I should have refreshed; or typed faster.

Cd&
0
 

Author Comment

by:brettr
ID: 38802182
Sorry - it's actually the content in the gray box I'd like to center, not center against the page.  Right now, the interior content is left aligned.
0
 
LVL 30

Assisted Solution

by:IanTh
IanTh earned 125 total points
ID: 38802188
you might need a div within mc_embed

and in css set the inner div as centered and put the form in the inner div

and mc-emded in css as 1024 pixels  

so

<!-- Begin MailChimp Signup Form -->
<link href="http://cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<div id="mc_embed_signup" style="background:#f8f8f8;text-align:center;width:500px;">
<div id="inner_mc" style="text-align:center;">
<form action="" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<label for="mce-EMAIL">Just sign up to our newsletter to receive your free copy of our latest ebook and content.</label>
<input type="text" value="" name="FNAME" class="email" id="mce-FNAME"placeholder="first name" required style="width:200px;">
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required style="width:200px;"><div><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" style="width:200px;"></div>
</form>
</div>
</div>
<!--End mc_embed_signup-->
      </body>
</html>
0
 

Author Comment

by:brettr
ID: 38802205
@IanTh

I tried the code you pasted but don't see that anything is being centered.
0
 
LVL 30

Expert Comment

by:IanTh
ID: 38802217
do you have a separate css file ?
0
 

Author Comment

by:brettr
ID: 38802228
No.  I'm trying the code stand alone as I pasted it for the simplest scenario.
0
 
LVL 30

Expert Comment

by:IanTh
ID: 38802321
what browser are you testing it on I think there used to be a align:center for a div but that's deprecated
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 38802332
What "gray box"? I see a gray button. Are you referring to the text, "Just sign up..."? If so, have you tried adding a text-align to the label instead?

<label for="mce-EMAIL" style="text-align: center;">Just sign up to our newsletter to receive your free copy of our latest ebook and content.</label>

Open in new window

0
 

Author Comment

by:brettr
ID: 38802354
A gray box surrounds the content.  Not sure why you can't see it.   background:#f8f8f8 creates it.  I've attached a screenshot with preview in Taco HTML Edit.

Adding that style to the label does center the text.  But how do I also center the two input boxes and button?

preview
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 38802472
Ah. Opera is not showing it for some reason--I assume the style isn't quite proper--but I can see it in IE. Have you tried the <label> suggestion?

Screenshot
[edit]

It is there in Opera. It's just so light that it's easy to miss!

[/edit]
0
 

Author Comment

by:brettr
ID: 38802495
You can see in your screenshot that the input boxes and button still aren't centered.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38802591
preview in Taco HTML Edit

Preview mode in a tool is not the place to assess presentation.  

It needs to be in a page and rendered by a browser.  Just looking at a code fragment in a  tool will not tell you how it renders in the real world. You also have all kinds of ids and classes. Is the tool applying those or just what is in the fragment?

Cd&
0
 

Author Comment

by:brettr
ID: 38802641
What do you mean by "those"?

It looks the same in the tool or in a browser.
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 38802660
Use the 2nd <div> approach suggested by IanTh, but put a "margin: auto;" and a width on that <div>:

...
<div id="mc_embed_signup" style="background:#f8f8f8;text-align:center;width:500px;">
<div style="margin: auto; width: 50%;">
...
</div>
</div>
...

Open in new window

0
 
LVL 30

Expert Comment

by:IanTh
ID: 38802674
I think on mc-emdeb you will need to setup padding to push it to the middle
0
 
LVL 30

Expert Comment

by:IanTh
ID: 38804147
padding will work as well if you have a div that is say 100 pixels wide and you add padding of 100 pixels the elements are 200 from the left assuming float left
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now