Jump to content

Style checkboxes in embedded MailChimp subscribe form

Recommended Posts

  • Replies 8
  • Views 1.3k
  • Created
  • Last Reply
On 3/20/2021 at 1:25 AM, dvgdvgdvg said:

Site URL: https://cyan-teal-3zmw.squarespace.com/subscribe

I'm looking to style the checkboxes in an embedded MailChimp subscribe form – specifically, I'm trying to change the background color when they're checked. I've tried using "input[type=checkbox]:checked" to target them in my CSS but I'm not having any luck. Any help would be hugely appreciated.

Password = governance

Checkbox can not be style like this, try this

#mc_embed_signup .mc-field-group.input-group input[type=checkbox] {
  position: absolute;
  opacity: 0;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:before {
  content: '';
  position: absolute;
  top: -2.5px;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #eee;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:before {
  background-color: #41a0ce;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:after {
  display: block;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:after {
  content: "";
    position: absolute;
      left: 7.5px;
    top: 0px;
    width: 7px;
    height: 12px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(
45deg
);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
  display: none;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label {
  sbackground-color: #ccc;
  position: relative;
  display: inline-block;
  text-indent: 25px
}

image.png.41b4789da7f3db0e5ddf5e76175a888a.png

learn more about technique here

How To Create a Custom Checkbox and Radio Buttons (w3schools.com)

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
On 3/22/2021 at 8:27 AM, bangank36 said:

Checkbox can not be style like this, try this



#mc_embed_signup .mc-field-group.input-group input[type=checkbox] {
  display: none;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:before {
  content: '';
  position: absolute;
  top: -2.5px;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #eee;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:before {
  background-color: #41a0ce;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:after {
  display: block;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:after {
  content: "";
    position: absolute;
      left: 7.5px;
    top: 0px;
    width: 7px;
    height: 12px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(
45deg
);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
  display: none;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label {
  sbackground-color: #ccc;
  position: relative;
  display: inline-block;
  text-indent: 25px
}

image.png.41b4789da7f3db0e5ddf5e76175a888a.png

learn more about technique here

How To Create a Custom Checkbox and Radio Buttons (w3schools.com)

Thanks! This looks great in theory, but unfortunately I believe using "display:none" to hide the default input makes the form inaccessible for screen reader users; if that's the case, then this approach should be avoided.

Link to comment
14 minutes ago, dvgdvgdvg said:

Thanks! This looks great in theory, but unfortunately using "display:none" to hide the default input makes the form inaccessible for screen reader users (as far as I know), so that should be avoided.

I just updated the code to hide it using absolute positioning, you can take reference of how to hide checkbox in this article, within the scope of these questions I can not go in detail. Hope that helps

Inclusively Hiding & Styling Checkboxes and Radio Buttons (sarasoueidan.com)

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
On 3/22/2021 at 8:27 AM, bangank36 said:

Checkbox can not be style like this, try this


#mc_embed_signup .mc-field-group.input-group input[type=checkbox] {
  position: absolute;
  opacity: 0;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:before {
  content: '';
  position: absolute;
  top: -2.5px;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #eee;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:before {
  background-color: #41a0ce;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:after {
  display: block;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:after {
  content: "";
    position: absolute;
      left: 7.5px;
    top: 0px;
    width: 7px;
    height: 12px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(
45deg
);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
  display: none;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label {
  sbackground-color: #ccc;
  position: relative;
  display: inline-block;
  text-indent: 25px
}

learn more about technique here

How To Create a Custom Checkbox and Radio Buttons (w3schools.com)

You're my hero @bangank36 – with some tweaks, this worked exactly as I hoped! I made some modifications and added focus states for accessibility. In case it's helpful for anyone else, here's the revised CSS:

/* hide existing checkbox */
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] {
  position: absolute;
  opacity: 0;
}
/* new checkbox styling */
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 20px;
  width: 20px;
  background-color: #fff;
  border: 1px solid #ABB0B2;
  border-radius: 3px;
  box-sizing: border-box;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:focus ~ label:before {
  border-color: #333;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:before {
  background-color: #299fce;
  border: 1px solid #299fce;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:focus:checked ~ label:before {
  border-color: #20305f!important;
}
#mc_embed_signup .mc-field-group.input-group input[type=checkbox]:checked ~ label:after {
  content: "";
  position: absolute;
  left: 6px;
  top: 3px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 3px 3px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
  display: block;
}
/* checkbox label */
#mc_embed_signup .mc-field-group.input-group input[type=checkbox] ~ label {
  background-color: #fff;
  position: relative;
  display: inline-block;
  text-indent: 18px;
}

 

Link to comment

@dvgdvgdvg I see your site, tablet, has white bar on right of screen.

You can add this to Subscribe Page Header

<style>
  @media screen and (max-width:991px) and (min-width:768px) {
  html, body {
    overflow-x: hidden;
}
  }
</style>

image.thumb.png.4ffe7ccf211471f564557b8bca1b2f42.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
4 hours ago, tuanphan said:

@dvgdvgdvg I see your site, tablet, has white bar on right of screen.

You can add this to Subscribe Page Header


<style>
  @media screen and (max-width:991px) and (min-width:768px) {
  html, body {
    overflow-x: hidden;
}
  }
</style>

 

Ah thank you for the heads up! It looks like the footer form was causing this; I removed the "width:auto" setting I'd applied to .newsletter-form-fields-wrapper and that appears to have resolved it. Let me know if the overflow/white edge is still showing up for you though. Appreciate it!

Link to comment
On 3/26/2021 at 9:13 PM, dvgdvgdvg said:

Ah thank you for the heads up! It looks like the footer form was causing this; I removed the "width:auto" setting I'd applied to .newsletter-form-fields-wrapper and that appears to have resolved it. Let me know if the overflow/white edge is still showing up for you though. Appreciate it!

Now I see fine (y)

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.