title: CSS Lightbox jumps to top of page when closed
body: <p>I am working on my single page portfolio site. Being terrified of JavaScript, I have found a way to create a lightbox using CSS on my work page. Site can be viewed here: <a href="http://codepen.io/lauramortier/full/ChlcD/" rel="nofollow">http://codepen.io/lauramortier/full/ChlcD/</a></p>
  
  <p>If you click on "Work", it'll take you down to my portfolio page, and if you click on a thumbnail, it'll open up a lightbox with the full-size image. It works just the way I want it too, until you close it by clicking X and it jumps all the way to the top of the site...
  Any idea how I can make it stay on the current div? (i.e: #page3?)</p>
  
  <p>Here is the HTML:</p>
  
  <pre><code>&lt;head&gt;
    &lt;title&gt;Laura Mortier|Graphic Designer&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
  &lt;/head&gt;
  
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="javascript/smoothscroll.js"&gt;&lt;/script&gt;
  
  &lt;body&gt;
    &lt;header&gt;
      &lt;nav&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href="#home" class="smoothScroll"&gt;Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#about" class="smoothScroll"&gt;About&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#work" class="smoothScroll"&gt;Work&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#contact" class="smoothScroll"&gt;Contact&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/nav&gt;
    &lt;/header&gt;
  
    &lt;!-----------------PAGES------------------&gt;
  
  
    &lt;!------Home------&gt;
  
    &lt;div id="page1"&gt;
      &lt;a id="home"&gt;&lt;/a&gt;
      &lt;h1 id="home-text"&gt;Salut! My name is Laura Mortier. 
        &lt;br&gt;I am a designer who loves making&lt;br&gt;
            things look pretty.&lt;/h1&gt;
    &lt;/div&gt;
  
  
    &lt;!------About------&gt;
  
    &lt;div id="page2"&gt;
      &lt;a id="about"&gt;&lt;/a&gt;
      &lt;h1 id="about-title"&gt;About Me&lt;/h1&gt;
  
        &lt;img src="http://i870.photobucket.com/albums/ab270/frenchspy007/6de8148c-6f03-497e-ba24-60c37b45978e_zps13deddb4.jpg"/&gt;  
  
      &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
        &lt;br&gt;sed do eiusmod tempor incididunt ut labore et dolore&lt;br&gt; magna aliqua. Ut enim ad minim veniam, quis nostrud &lt;br&gt;exercitation ullamco laboris nisi ut aliquip ex ea commodo &lt;br&gt; consequat.&lt;br&gt; Duis aute irure dolor in reprehenderit in voluptate velit esse &lt;br&gt; cillum dolore eu fugiat nulla
        pariatur. &lt;br&gt; Excepteur sint occaecat cupidatat non proident, sunt 
        &lt;br&gt;in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
  
    &lt;/div&gt;
  
  
    &lt;!------Work------&gt;
  
     &lt;div id="page3"&gt;
       &lt;a id="work"&gt;&lt;/a&gt;
       &lt;h1 id="work-title"&gt;Work&lt;/h1&gt;
       &lt;h2&gt;Here are some of my recent works:&lt;/h2&gt;
    &lt;div class="portfolio"&gt;
  
  &lt;ul id="gallery"&gt;
      &lt;li&gt;
  
          &lt;a class="lightbox" href="#image1"&gt;
          &lt;img src="../Thumbnails/four element thumb.png"/&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image1"&gt;
          &lt;img src="../Full-Size Images/four elements cans.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
      &lt;/li&gt;   
  
      &lt;li&gt;
  
          &lt;a class="lightbox" href="#image2"&gt;
          &lt;img src="../Thumbnails/watchdogs-thumb.png"/&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image2"&gt;
          &lt;img src="../Full-Size Images/watchdogs.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
  
      &lt;li&gt;
  
          &lt;a class="lightbox" href="#image3"&gt;
          &lt;img src="../Thumbnails/happy mouth logo final.png"&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image3"&gt;
          &lt;img src="../Full-Size Images/happy mouth logo final.png"
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
  
  
      &lt;li&gt;
  
          &lt;a class="lightbox" href="#image4"&gt;
          &lt;img src='../Thumbnails/designer desk thumb.png'/&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image4"&gt;
          &lt;img src="http://i870.photobucket.com/albums/ab270/frenchspy007/designerdesk_zps1eb2bab6.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
      &lt;li&gt;
  
          &lt;a class="lightbox" href="#image5"&gt;
          &lt;img src="http://i870.photobucket.com/albums/ab270/frenchspy007/newMlogo_zpse9e2cd8f.png"/&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image5"&gt;
          &lt;img src="http://i870.photobucket.com/albums/ab270/frenchspy007/d8340feb-cc71-420a-a58a-c9b454bb8732_zps28886966.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
  
          &lt;li&gt;
  
          &lt;a class="lightbox" href="#image6"&gt;
          &lt;img src="../Thumbnails/paris my sweet-thumb"/&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image6"&gt;
          &lt;img src="../Full-Size Images/paris my sweet.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
          &lt;li&gt;
  
          &lt;a class="lightbox" href="#image7"&gt;
          &lt;img src="../Thumbnails/dark souls thumb.png"/&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image7"&gt;
          &lt;img src="../Full-Size Images/dark souls.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
          &lt;li&gt;
  
          &lt;a class="lightbox" href="#image8"&gt;
          &lt;img src="../Thumbnails/bioshock poster thumb copy.png"&gt;
          &lt;/a&gt; 
          &lt;div class="lightbox-target" id="image8"&gt;
          &lt;img src="../Full-Size Images/bioshock poster.png"/&gt;
      &lt;a class="lightbox-close" href="#"&gt;&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/li&gt;
  
  &lt;/ul&gt;
  
    &lt;!------BEHANCE BUTTON------&gt;
  
  
          &lt;a href="http://www.behance.net/laura-mortier" target="_blank"&gt;
          &lt;button id="behance"&gt;&lt;h3 id="behance-text"&gt;See More on Behance&lt;/h3&gt;&lt;/button&gt;
          &lt;/a&gt;
  
  
    &lt;!------Contact------&gt;
  
    &lt;div id="page4"&gt;
      &lt;a id="contact"&gt;&lt;/a&gt;
      &lt;h1 id="contact-title"&gt;Get in touch!&lt;/h1&gt; 
      &lt;p id="contact-text"&gt;Wanna work with me or just wanna say hi?&lt;br&gt;
      Drop me a line, and I'll get back to you as&lt;br&gt;
  soon as I can!&lt;/p&gt;
  
      &lt;form action="FormtoEmail.php" method="post"&gt;
  
      &lt;label&gt;Name&lt;/label&gt;
      &lt;input name="name" placeholder="Who are you?"&gt;&lt;br&gt;
  
      &lt;label&gt;Email&lt;/label&gt;
      &lt;input name="email" type="email" placeholder="What's your e-mail?"&gt;&lt;br&gt;
  
      &lt;label&gt;Message&lt;/label&gt;
      &lt;textarea name="message" placeholder="What's on your mind?"&gt;&lt;/textarea&gt;
  
     &lt;br&gt; &lt;input id="submit" name="submit" type="submit" value="Submit"&gt;
  
  &lt;/form&gt;
  
  &lt;!-------------CONTACT INFO--------------
    &lt;div id="contact-info"&gt;
      &lt;ul&gt;
        &lt;li&gt;mortierlaura@rocketmail.com&lt;/li&gt;&lt;br&gt;
        &lt;li&gt;262-359-0213&lt;/li&gt;
      &lt;/ul&gt;
  
    &lt;/div&gt;
  ----------------------------------------&gt;  
  
  &lt;a href="#home" class="smoothScroll"&gt;&lt;button id="back-to-top" type="button"&gt;&lt;h3 id="fshoo"&gt;FSHOO!&lt;/h3&gt;&lt;/button&gt;&lt;/a&gt;
  
    &lt;/div&gt;
  
  
  &lt;/body&gt;
  
  &lt;footer&gt;
    &lt;h3 id="footer-text"&gt;Laura Mortier &amp;copy; All Rights Reserved&lt;/h3&gt;
  &lt;/footer&gt;
  </code></pre>
  
  <p>and the CSS</p>
  
  <pre><code> body{
    width:960px;
    margin:0 auto;
    display:block;
    background-color:#34495e;
  }
  
  /*********Navigation***********/
  header{
    display:block;
    background-color:#34495E;
    height:60px;
    position:fixed;
    width:960px;
    top:0px; 
  }
  
  header ul{
    margin:0;
    padding:0;
    float:right;
    margin-top:15px;
  }
  
  
  li{
    list-style:none;
    display:inline;
    color:white;
    font-family:helvetica;
    font-weight:bold;
    font-size: 24px;
    padding: 20px;
  
  }
  
  
  
  a:hover{
    color: #3498db;
  }
  
  a{
    color:white;
    text-decoration:none;
  }
  
  /*********HOME PAGE***********/
  
  #page1{
    margin:0;
    height:900px;
    background-color:#2ecc71;
    border-radius:10px;
  }
  
  #home-text{
    font-family:helvetica;
    font-size:50px;
    color:white;
    padding-left:75px;
    padding-top:100px;
  }
  
  /*********ABOUT PAGE***********/
  
  #page2{
    height:700px;
    background-color:#65C6BB;
    border-radius:10px;
    margin-top:20px;
  }
  
  #about-title{
    font-family:helvetica;
    color:white;
    padding-left:40px;
    padding-top:20px;
    padding-bottom:40px;
  }
  
  p{
    font-family:helvetica;
    text-align:left;
    color:white;
    padding-left:100px;
    padding-top:20px;
  }
  
  img{
    float:top;
    display:block;
    margin-left:175px;
    padding:0;
    border-radius:100%;
    border: 5px solid white;
  
  }
  
  
  /*********WORK PAGE***********/
  
  /**************GALLERY LIGHTBOX******************/
  
  /*Eliminates padding, centers the thumbnail */
  
  #page3{
    height:675px;
    background-color:lightcoral;
    border-radius:10px;
    margin-bottom:20px;
  }
  
  #work-title{
    font-family:helvetica;
    color:white;
    padding-left:40px;
    padding-top:20px;
  }
  
  h2{
    color:white;
    font-family:helvetica;
    padding-left:40px;
    font-weight:normal;
    font-size:24px;
  }
  
  .portfolio{
     height:400px;
     margin:0 auto;
      }
  
  #gallery li{
     display:inline-block;
     margin:5px;
     clear:both;
     }
  
  #behance{
      background-color:lightcoral;
      border-radius:10px;
      color:white;
      border: 2px white solid;
      height:60px;
      width:200px;
      font-family:Arial, Helvetica, sans-serif;
      font-size:18px;
      float:bottom;
      margin-left:350px;
      margin-bottom:20px;
      }
  
  #behance:hover{
      color:white;
      border: dashed 2px white;
      }
  
  #behance-text{
      font-weight:normal;
      padding:0;
      margin:0;
      }
  /*******************LIGHTBOX*******************/   
  
  
  
  
  
  /*******************LIGHTBOX*******************/
  
  
  /* Styles the thumbnail */
  
  a.lightbox img {
  height: 150px;
  width:150px;
  border: 3px solid white;
  border-radius:0px;
  box-shadow: 0px 0px 8px rgba(0,0,0,.3);
  margin: 5px;
  }
  
  /* Styles the lightbox, removes it from sight and adds the fade-in transition */
  
  .lightbox-target {
  position: fixed;
  top: 0;
  left:0;
  width: 100%;
  background: rgba(0,0,0,.7);
  width: 100%;
  opacity: 0;
  -webkit-transition: opacity .5s ease-in-out;
  -moz-transition: opacity .5s ease-in-out;
  -o-transition: opacity .5s ease-in-out;
  transition: opacity .5s ease-in-out;
  overflow: hidden;
  }
  
  /* Styles the lightbox image, centers it vertically and horizontally, adds the zoom-in transition and makes it responsive using a combination of margin and absolute positioning */
  
  .lightbox-target img {
  margin: auto;
  position: fixed;
  top: 0;
  left:0;
  right:0;
  bottom: 0;
  max-height: 0%;
  max-width: 0%;
  border: 3px solid white;
  box-shadow: 0px 0px 8px rgba(0,0,0,.3);
  box-sizing: border-box;
  -webkit-transition: .5s ease-in-out;
  -moz-transition: .5s ease-in-out;
  -o-transition: .5s ease-in-out;
  transition: .5s ease-in-out;
  border-radius:0px;
  }
  
  /* Styles the close link, adds the slide down transition */
  
  a.lightbox-close {
  display: block;
  width:50px;
  height:50px;
  box-sizing: border-box;
  background: white;
  color: black;
  text-decoration: none;
  position: fixed;
  top: -80px;
  right: 0;
  -webkit-transition: .5s ease-in-out;
  -moz-transition: .5s ease-in-out;
  -o-transition: .5s ease-in-out;
  transition: .5s ease-in-out;
  }
  
  /* Provides part of the "X" to eliminate an image from the close link */
  
  a.lightbox-close:before {
  content: "";
  display: block;
  height: 30px;
  width: 1px;
  background: black;
  position: absolute;
  left: 26px;
  top:10px;
  -webkit-transform:rotate(45deg);
  -moz-transform:rotate(45deg);
  -o-transform:rotate(45deg);
  transform:rotate(45deg);
  }
  
  /* Provides part of the "X" to eliminate an image from the close link */
  
  a.lightbox-close:after {
  content: "";
  display: block;
  height: 30px;
  width: 1px;
  background: black;
  position: absolute;
  left: 26px;
  top:10px;
  -webkit-transform:rotate(-45deg);
  -moz-transform:rotate(-45deg);
  -o-transform:rotate(-45deg);
  transform:rotate(-45deg);
  }
  
  /* Uses the :target pseudo-class to perform the animations upon clicking the .lightbox-target anchor */
  
  .lightbox-target:target {
  opacity: 1;
  top: 0;
  bottom: 0;
  }
  
  .lightbox-target:target img {
  max-height: 100%;
  max-width: 100%;
  }
  
  .lightbox-target:target a.lightbox-close {
  top: 0px;
  }
  
  
  
  
  
  
  /*********CONTACT PAGE***********/
  
  #page4{
    background-color:steelblue;
    height:700px;
    border-radius:10px;
    margin-bottom:10px;
    margin-top:30px;
  }
  
  #contact-title{
    font-family:helvetica;
    color:white;
    padding-left:40px;
    padding-top:20px;
  }
  
  #contact-text{
    color:white;
    font-size:18px;
    font-family:helvetica;
    padding-left:40px;
    font-weight:normal;
  }
  
  #submit{
      margin-top:20px;
      }
  
  /*********CONTACT FORM***********/
  
  form{
    padding-left:40px;
  }
  
  label{
    display:block;
    margin-top:20px;
    letter-spacing:2px;
    font-family:helvetica;
    color:white;
    font-size:18px;
  }
  
  input, textarea {
      width:400px;
      height:27px;
      background:#efefef;
      border:1px solid #dedede;
      padding:10px;
      margin-top:3px;
    font-family:helvetica;
    font-size:0.9em;
    color:#3a3a3a;
  }
  
  input, textarea {
      width:400px;
      height:27px;
      background:#efefef;
      border:1px solid #dedede;
      padding:10px;
      margin-top:3px;
      font-size:0.9em;
      color:#3a3a3a;
      -moz-border-radius:5px;
      -webkit-border-radius:5px;
      border-radius:5px;
  }
  
  textarea {
      height:213px;
      background:url(images/textarea-bg.jpg) right no-repeat #efefef;
  }
  
  input:focus, textarea:focus {
      border:1px solid #97d6eb;
  }
  
  #submit{
    background-color:steelblue;
    font-family:helvetica;
    font-size:18px;
    color:white;
    border: 2px solid white;
    height:30px;
    width:130px;
    padding:0;
  }
  
  #submit:hover{
    background-color:lightcoral;
  }
  
  #contact-info{
    float:right;
    color:white;
    display:block;
    font-family:helvetica;
    font-size:16px;
  }
  
  /*********BACK TO TOP BUTTON***********/
  
  #back-to-top{
    float:right;
    padding-bottom:20px;
    padding-right:30px;
  }
  
  #back-to-top{
    font-family:helvetica;
    color:white;
    font-size:16px;
    font-weight:bold;
    background-color:steelblue;
    border: 2px solid white;
    border-radius:10px;
    height:30px;
    width:150px;
    margin-right:50px;
    text-align:center;
  
  }
  
  #fshoo{
      margin-left:25px;
      margin-top:20px;    
  
      }
  
  #back-to-top:hover{
    border:dashed 2px white;
  }
  
  
  
  
  
  /*********FOOTER***********/
  
  footer{
    background-color:#34495E;
    height:60px;
    border-radius:10px;
    margin-top:0px;
  
  }
  
  
  #footer-text{
    font-family:helvetica;
    color:white;
    font-size:18px;
    font-weight: normal;
    padding-top:10px;
    padding-left:25px;
  }
  </code></pre>
  
  <p>Thank you in advance!</p>