Jump to content

Creating a text box with a "close" button

Recommended Posts

Posted

Hey there, 

Im trying to create a very simple box with text to go over a shop page that can be closed if the user doesn't want to see it. Everything seems to work fine except the "x" button doesnt seem to work on squarespace, though it works in the codepen (I converted the less to css). Any help would be greatly appreciated. 

Here's the code: 

<style>#popup-holder {
     position: absolute;
     top: 100px;
     height: 200px;
     width: 100%;
}
 #popup-holder.hide {
     display: none;
}
 #popup-box {
     width: 200px;
     height: 200px;
     position: relative;
     margin: 0px auto;
     background: white;
     border-style: solid;
     border-color: #1d1e21;
     border-width: 4px;
}
 #popup-box p {
     font-size: 1.5em;
     color: black;
     font-family: sans-serif;
     text-align: center;
     padding-top: 3em;
     padding-bottom: 3.5;
}
 #popup-box button {
     border-radius: 0px;
     border: none;
     background: transparent;
     font-size: 2em;
     color: black;
     position: absolute;
     right: 0;
     top: 0;
     cursor: pointer;
     padding: 2px 15px 8px 15px;
}
 #popup-box button:hover, #popup-box button:focus {
     background: rgba(255,255,255,0.4);
}
 .page-article {
     background-color: #eee;
     width: 70%;
     margin: 30px auto;
     padding: 20px;
     font-family: sans-serif;
     min-height: 100px;
}
 .page-article a {
     color: #000;
     text-decoration: none;
}
 .page-article a:hover, .page-article a:focus {
     text-decoration: underline;
}
 </style>

 

<Script>

$('#exit-popup').click( function() {
  $('#popup-holder').addClass('hide');
  $('#pa-2 a').focus();
});

setTimeout( function() {
  $('#popup-holder').removeClass('hide');
  $('#exit-popup').focus();
}, 3000);

</script>

<html>

<div id="popup-holder" class="hide">
  <div id="popup-box">
    <p>Hi!</p>
    <button aria-label="Hide popup" id="exit-popup">x</button>
  </div>
</div>
</html>

  • Replies 2
  • Views 2.1k
  • Created
  • Last Reply
  • 1 year later...
Posted

I love your code! I tried it and had the same problem. My husband figured it out: The problem is the code you use to make the X on the button. If we used a <button...></button> the X only refreshes the page. Try making it an <input type=button ...> and see if that helps things along:

<input type=button label='Hide popup' id='exit_popup' value='X'>

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.