skip to Main Content

I’m working on including a shortcode on the footer of my WordPress website so that users may sign up to my newsletter.

I managed to include the shortcode itself on the footer, although I can’t get it horizontally centered, it seems stuck on the left side. As you can see, I’ve created a class with two IDs inside of it, the first one with some written text and the second one with the form. The written text is centered, but I can’t find the right way to center the form.

I tried different potential solutions, such as this, this and this, but none of them got it properly centered, it always stays off. I’m sure the solution must be simple, I just can’t see it.

Non working code (solution is shown below):

.tnp-subscription-minimal input[type=submit] {
  background-color: #224b37!important;
  color: #ffffff;
  font: Poppins, sans-serif;
  font-weight: bold;
  margin: 0 auto;
  border: none;
  padding: 0 30px;
  border-radius: 5px;
  letter-spacing: 1px;
  font-size: 14px;
  box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  box-sizing: border-box;
  margin-left: 2px;
  transition: all 0.23s ease-in-out 0s;
}

.tnp-subscription-minimal input[type=email] {
  font-family: Poppins, sans-serif;
  border: none;
  padding: 15px;
  width: 50%;
  font-size: 14px;
  margin-right: 5px;
  -webkit-border-radius: 0px;
  -moz-border-radius: 0px;
  border-radius: 5px;
  color: #343434;
  background-color: #fff;
  box-sizing: border-box;
}

#inscripcion {
  font-size: 16px;
  font: Poppins, sans-serif;
  font-weight: 600;
  margin: 0 0 20px;
  color: #000000;
  text-align: center;
}
<div class=“newsletter-wrapper” style="position: sticky; background-color:#c2cdc8; padding:60px 30px 60px 30px; width: 100%;">
  <div id="inscripcion" style="absolute: sticky; left: 50%; top: 50%; z-index: 9999">¿Quieres recibir todos mis posts? ⦙ <br> Do you want to receive my posts?</div>
  <div id="formulario-newsletter"  style="absolute: sticky; left: 50%; top: 50%;">
    <form calss="tnp-subscription-minimal">
      <input type="email" /> <button type="submit">OK!</button>
    </form>
  </div>
</div>

I deliberately left the previous, non-working code in case it helps someone in a similar situation, this is how it ended up looking (and working properly):

.tnp-subscription-minimal input[type=submit] {
  background-color: #224b37!important;
  color: #ffffff;
  font: Poppins, sans-serif;
  font-weight: bold;
  margin: 0 auto;
    width: 16%;
  border: none;
  padding: 0 0px;
  border-radius: 5px;
  letter-spacing: 1px;
  font-size: 14px;
  box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  box-sizing: border-box;
  margin-left: 2px;
  transition: all 0.23s ease-in-out 0s;
}

.tnp-subscription-minimal input[type=email] {
  font-family: Poppins, sans-serif;
  border: none;
  padding: 15px;
  width: 68%;
  font-size: 14px;
  margin-right: 5px;
  -webkit-border-radius: 0px;
  -moz-border-radius: 0px;
  border-radius: 5px;
  color: #343434;
  background-color: #fff;
  box-sizing: border-box;
}

#inscripcion {
  font-size: 16px;
  font: Poppins, sans-serif;
  font-weight: 600;
  margin: 0 0 20px;
  color: #000000;
  text-align: center;
}

#formulario-newsletter {
  text-align: center;
}
<div class=“newsletter-wrapper” style="position: sticky; background-color:#c2cdc8; padding:45px 30px 60px 30px; width: 100%; display: flex; flex-direction: column; align-items: center;">
  <div id="inscripcion" style="z-index: 9999">¿Quieres recibir todos mis posts? ⦙ <br> Do you want to receive my posts?</div>
  <div id="formulario-newsletter">
<?php echo do_shortcode('[newsletter_form type="minimal"]'); ?> 
  </div>
</div>

Text is centered, but the form isn't

2

Answers


  1. First, as a comment said, absolute: sticky is not an actual tag, it’s position: absolute or position: sticky.

    Next, position: sticky only has to be used on the parent element, not the child elements as well.

    And to answer your question, simply remove "position" and "top", "left" attributes from the child elements and add the following attributes to the parent element:

    display: flex;
    flex-direction: column;
    align-items: center;
    

    I also made the modifications to your code, so you can see it working:

    .tnp-subscription-minimal input[type=submit] {
      background-color: #224b37!important;
      color: #ffffff;
      font: Poppins, sans-serif;
      font-weight: bold;
      margin: 0 auto;
      border: none;
      padding: 0 30px;
      border-radius: 5px;
      letter-spacing: 1px;
      font-size: 14px;
      box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
      cursor: pointer;
      box-sizing: border-box;
      margin-left: 2px;
      transition: all 0.23s ease-in-out 0s;
    }
    
    .tnp-subscription-minimal input[type=email] {
      font-family: Poppins, sans-serif;
      border: none;
      padding: 15px;
      width: 50%;
      font-size: 14px;
      margin-right: 5px;
      -webkit-border-radius: 0px;
      -moz-border-radius: 0px;
      border-radius: 5px;
      color: #343434;
      background-color: #fff;
      box-sizing: border-box;
    }
    
    #inscripcion {
      font-size: 16px;
      font: Poppins, sans-serif;
      font-weight: 600;
      margin: 0 0 20px;
      color: #000000;
      text-align: center;
    }
    <div class=“newsletter-wrapper” style="position: sticky; background-color:#c2cdc8; padding:60px 30px 60px 30px; width: 100%; display: flex; flex-direction: column; align-items: center;">
      <div id="inscripcion" style="z-index: 9999">¿Quieres recibir todos mis posts? ⦙ <br> Do you want to receive my posts?</div>
      <div id="formulario-newsletter">
        <form calss="tnp-subscription-minimal">
          <input type="email" /> <button type="submit">OK!</button>
        </form>
      </div>
    </div>
    Login or Signup to reply.
  2. Add this to css

    #formulario-newsletter {
      display: grid;
      place-items: center;
    }
    

    and change the html to this:

    <div class=“newsletter-wrapper” style="position: sticky; background-color:#c2cdc8; padding:60px 30px 60px 30px; width: 100%;">
        <div id="inscripcion">¿Quieres recibir todos mis posts? ⦙ <br> Do you want to receive my posts?</div>
        <div id="formulario-newsletter">
            <form class="tnp-subscription-minimal"> <!--btw u wrote calss instead of class-->
                <input type="email" /> <button type="submit">OK!</button>
            </form>
        </div>
    </div>
    

    That should work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search