jimmyNames
jimmyNames

Reputation: 162

How to center Mailchimp sign-up form div?

I've found this q&a on stack but both solutions did not work..

How do I center a mailchimp embed form in a twitter bootstrap page?

centering input in form mailchimp

What I think these questions lack is both the code for the form and style code included (see below). How can I center both the content (text) and the div itself as a whole so it's responsively centered on the page?

    <link href="//cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
    #mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
    /* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
       We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>

    <center>
        <div class="display:block margin:auto "id="mc_embed_signup">
    <form action="//twitter.us11.list-manage.com/subscribe/post?u=b59cd34816a376a0c58945aee&amp;id=2e74fec4e5" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
        <div id="mc_embed_signup_scroll">
        <label for="mce-EMAIL">Subscribe to our mailing list</label>
        <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
        <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;"><input type="text" name="b_b59cd34816a376a0c58945aee_2e74fec4e5" tabindex="-1" value="">
            </div>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
            </div>
            </div>
            </div>   
</form>
    </div>
</center>

You can see I've attempted the tags as well as altering the class within the form..

Any help is greatly appreciated :3

Upvotes: 1

Views: 12960

Answers (4)

I had the same problem, using Mobirise, the Mailchimp form always aligned left.

Then I found that changing the % width below from 100% to 50% solved the problem:

<div class="container">
    <div class="inner-container" style="width: 50%;">
        <hr class="line" style="width: 10%;">

This was within the Mobirise Block where I pasted the text.

I also found that in the settings when creating the Signup form from Mailchimp, removing the width of pixels there helped:

"Leave blank to let the form take on the width of the area where it's placed."

Upvotes: 0

Keito Aino
Keito Aino

Reputation: 86

First - remove center tags and this "class":

class="display:block margin:auto"

Second - you can set input width to 100% and block width to 58%:

#mc_embed_signup input.email {
  ...
  width: 100%;
  ...
}

#mc_embed_signup form {
  ...
  width: 58%;
  margin: auto;
}

Example:

<link href="https://cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">

<style type="text/css">
    #mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
    /* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
       We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
  #mc_embed_signup label {
    text-align: center;
  }
  #mc_embed_signup input.email {
    width: 100%;
  }
  
  #mc_embed_signup input.button {
    margin: auto;
  }
  
  #mc_embed_signup form {
    width: 58%;
    margin: auto;
  }
</style>

<div class="display:block margin:auto" id="mc_embed_signup">
    <form action="//twitter.us11.list-manage.com/subscribe/post?u=b59cd34816a376a0c58945aee&amp;id=2e74fec4e5" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
        <div id="mc_embed_signup_scroll">
            <label for="mce-EMAIL">Subscribe to our mailing list</label>
            <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
            <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
            <div style="position: absolute; left: -5000px;">
                <input type="text" name="b_b59cd34816a376a0c58945aee_2e74fec4e5" tabindex="-1" value="">
            </div>
            <div class="clear">
                <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
            </div>
        </div>
    </form>
</div>

Also, this looks like ugly hack:

style="position: absolute; left: -5000px;"

Why u don't use hidden input or "display: none"? :)

Upvotes: 2

vanburen
vanburen

Reputation: 21653

This article may help: Customize Your Own MailChimp E-Mail Newsletter Signup Form.

/** MailChimp Styles **/

#mc_embed_signup {
  background: #fff;
  clear: left;
  font: 14px Helvetica, Arial, sans-serif;
  text-align: center;
  width: 350px;
  margin: 0 auto;
}
/* MailChimp Form Embed Code - Slim - 08/17/2011 */

#mc_embed_signup form {
  display: block;
  position: relative;
  text-align: center;
  padding: 10px 0 10px 3%;
}
#mc_embed_signup h2 {
  font-weight: bold;
  padding: 0;
  margin: 15px 0;
  font-size: 1.4em;
}
#mc_embed_signup input {
  border: 1px solid #ababab;
  -webkit-appearance: none;
}
#mc_embed_signup input[type=checkbox] {
  -webkit-appearance: checkbox;
}
#mc_embed_signup input[type=radio] {
  -webkit-appearance: radio;
}
#mc_embed_signup input:focus {
  border-color: #799877;
}
#mc_embed_signup .button {
  display: block;
  position: relative;
  background-color: #266080;
  padding: 0;
  margin: 0 auto;
  border: 0 none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  width: 140px;
  height: 36px;
  line-height: 36px;
  font-weight: bold;
  text-align: center;
  text-decoration: none;
  vertical-align: top;
}
#mc_embed_signup .button:hover {
  background-color: #f00;
}
#mc_embed_signup .button:active {
  top: 2px;
  border-bottom-width: 1px;
}
#mc_embed_signup .small-meta {
  font-size: 11px;
}
#mc_embed_signup .nowrap {
  white-space: nowrap;
}
#mc_embed_signup .clear {
  clear: none;
  display: inline;
}
#mc_embed_signup label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  padding-bottom: 7px;
  color: #616161;
  font-weight: bold;
}
#mc_embed_signup input.email {
  display: block;
  padding: 8px 4px;
  margin: 0 4% 10px 0;
  text-indent: 5px;
  color: #818181;
  font-size: 1.0em;
  background: #fff;
  font-weight: bold;
  width: 100%;
  -webkit-transition: all 0.2s linear;
  -moz-transition: all 0.2s linear;
  transition: all 0.2s linear;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
}
#mc_embed_signup input.email:focus {
  color: #666;
}
#mc_embed_signup div#mce-responses {
  float: left;
  top: -1.4em;
  padding: 0em .5em 0em .5em;
  overflow: hidden;
  width: 90%;
  margin: 0 5%;
  clear: both;
}
#mc_embed_signup div.response {
  margin: 1em 0;
  padding: 1em .5em .5em 0;
  font-weight: bold;
  float: left;
  top: -1.5em;
  z-index: 1;
  width: 80%;
}
#mc_embed_signup #mce-error-response {
  display: none;
}
#mc_embed_signup #mce-success-response {
  color: #529214;
  display: none;
}
#mc_embed_signup label.error {
  display: block;
  float: none;
  width: auto;
  margin-left: 1.05em;
  text-align: left;
  padding: .5em 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div id="mc_embed_signup">
    <form action="//twitter.us11.list-manage.com/subscribe/post?u=b59cd34816a376a0c58945aee&amp;id=2e74fec4e5" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
      <div id="mc_embed_signup_scroll">
        <label for="mce-EMAIL">Subscribe to our mailing list</label>
        <input type="email" value="" name="EMAIL" class="email form-control" id="mce-EMAIL" placeholder="email address" required>
        <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;">
          <input type="text" name="b_b59cd34816a376a0c58945aee_2e74fec4e5" tabindex="-1" value="">
        </div>
        <div class="clear">
          <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
        </div>
      </div>
    </form>
  </div>
</div>

Upvotes: 0

Tushar Khatiwada
Tushar Khatiwada

Reputation: 2027

You are using bootstrap. So how about wrapping that code inside the bootstrap's grid system.

#mc_embed_signup {
  background: #fff;
  clear: left;
  font: 14px Helvetica, Arial, sans-serif;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
  <div class="row">
    <div class="col-md-3"></div>
    <div class="col-md-6">
      <center>
        <div class="display:block margin:auto " id="mc_embed_signup">
          <form action="//twitter.us11.list-manage.com/subscribe/post?u=b59cd34816a376a0c58945aee&amp;id=2e74fec4e5" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
            <div id="mc_embed_signup_scroll">
              <label for="mce-EMAIL">Subscribe to our mailing list</label><br />
              <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
              <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
              <div style="position: absolute; left: -5000px;">
                <input type="text" name="b_b59cd34816a376a0c58945aee_2e74fec4e5" tabindex="-1" value="">
              </div>
              <div class="clear">
                <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
              </div>
            </div>
          </form>
        </div>
      </center>
    </div>
    <div class="col-md-3"></div>
  </div>
</div>

Upvotes: 0

Related Questions