当标题位置固定时,锚点不起作用

时间:2018-04-19 08:19:15

标签: javascript html css

当我滚动时,我已经制作了一个固定位置的标题。但是当发生这种情况时,锚标记会停止工作以及所有效果



.buttons {
    margin-left: 460px;
}

.buttons .button a i {
    color: #fff;
    transition: .2s;
}

.buttons .button {
    float: left;
    margin-left: 10px;
    margin-top: 0px;
    transition: .8s;
    background-image: url(img/hexagon0.png);
    width: 50px;
    height: 50px;
    cursor: pointer;
}

.buttons .button a i:hover {
    color: #ff8000;
}

.buttons .button a i {
    margin-top: 15px;
}

.top-container {
    background-color: #f1f1f1;
    padding: 30px;
    text-align: center;
}

.header {
    padding: 10px 16px;
    background: #555;
    color: #f1f1f1;
    z-index: -1;
}

.content {
    padding: 16px;
    z-index: 1;
}

.sticky {
    position: fixed;
    top: 0;
    width: 100%;
}

.sticky + .content {
    padding-top: 102px;
}
div.hexagons {
    padding-left: 100px;
    margin-top: 100px;
}

.hex i {
    color: #fff;
    margin-top: 45px;
    transition: .5s ease;
}

.hex {
    cursor: pointer;
    width: 200px;
}

#hex1 {
    margin-left: -300px;
}

#hex2 {
    margin-left: 108px;
    margin-top: -172px;
}

#hex3 {
    margin-top: 60px;
    margin-left: -99px;
}

#hex4 {
    margin-left: 310px;
    margin-top: -172px;
}

#hex5 {
    margin-left: -510px;
    margin-top: -175px;
}

.hex:hover i {
    transform: translateY(-70px);
}

.hex .text p {
    margin-top: -50px;
    opacity: 0;
    transition: .5s;
    transform: translateY(50px);
    color: #fff;
}

.hex .text p#title {
    font-size: 15px;
}

.hex:hover .text p#title {
    font-size: 18px;
}

.hex .text p#content {
    margin-top: 0;
    font-size: 15px;
}

.hex:hover .text p#content {
    font-size: 15px;
}

.hex:hover .text p {
    transform: translateY(0);
    opacity: 1;
}

.hexagon {
    position: relative;
    width: 200px;
    height: 115.47px;
    background-color: #2e2e2e;
    margin: 57.74px 0;
    box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.hexagon:before,
.hexagon:after {
    content: "";
    position: absolute;
    z-index: 1;
    width: 141.42px;
    height: 141.42px;
    -webkit-transform: scaleY(0.5774) rotate(-45deg);
    -ms-transform: scaleY(0.5774) rotate(-45deg);
    transform: scaleY(0.5774) rotate(-45deg);
    background-color: inherit;
    left: 29.2893px;
    box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.hexagon:before {
    top: -70.7107px;
}

.hexagon:after {
    bottom: -70.7107px;
}

/*cover up extra shadows*/
.hexagon span {
    display: block;
    position: absolute;
    top:0px;
    left: 0;
    width:200px;
    height:115.4701px;
    z-index: 2;
    background: inherit;
}

.hex-img1 {
    margin-left: -300px;
    margin-top: -50px;
    z-index: -1;
}

.hexagon-img {
    position: relative;
    width: 800px;
    height: 461.88px;
    margin: 230.94px 0;
    background-image: url(img/2.jpg);
    background-size: auto 912.2134px;
    background-position: center;
    border-left: solid 5px #ff8000;
    border-right: solid 5px #ff8000;
}

.hexTop,
.hexBottom {
    position: absolute;
    z-index: 1;
    width: 565.69px;
    height: 565.69px;
    overflow: hidden;
    -webkit-transform: scaleY(0.5774) rotate(-45deg);
    -ms-transform: scaleY(0.5774) rotate(-45deg);
    transform: scaleY(0.5774) rotate(-45deg);
    background: inherit;
    left: 112.16px;
}

/*counter transform the bg image on the caps*/
.hexTop:after,
.hexBottom:after {
    content: "";
    position: absolute;
    width: 790.0000px;
    height: 456.1067126598044px;
    -webkit-transform:  rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
    -ms-transform:      rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
    transform:          rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
    -webkit-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    transform-origin: 0 0;
    background: inherit;
}

.hexTop {
    top: -282.8427px;
    border-top: solid 7.0711px #ff8000;
    border-right: solid 7.0711px #ff8000;
}

.hexTop:after {
    background-position: center top;
}

.hexBottom {
    bottom: -282.8427px;
    border-bottom: solid 7.0711px #ff8000;
    border-left: solid 7.0711px #ff8000;
}

.hexBottom:after {
    background-position: center bottom;
}

.hexagon-img:after {
    content: "";
    position: absolute;
    top: 2.8868px;
    left: 0;
    width: 790.0000px;
    height: 456.1067px;
    z-index: 2;
    background: inherit;
}

.content {
    margin-top: 1000px;
}

.section-title {
    background-color: #ff8000;
    width: 300px;
    text-align: center;
    transform: rotateZ(30deg) translateY(-21px) translateX(200px);
}

.section-title p {
    font-size: 50px;
    color: #fff;
    z-index: 1;
    font-weight: bold;
}

<!DOCTYPE html>
<html lang="en" dir="ltr">
      <head>
            <meta charset="utf-8">
            <title></title>
            <link rel="stylesheet" href="style.css">
            <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
            <script src="https://code.jquery.com/jquery-3.3.1.js"></script>

      </head>
      <body>
          <center>
              <div class="hexagons">
                  <a href="#one"><div class="hex" id="hex1">
                      <div class="hexagon">
                          <span>
                              <i style="font-size: 30px;" class="fa fa-paint-brush" aria-hidden="true"></i>
                              <div class="text">
                                  <p id="title">Grafisk Design</p>
                                  <p id="content">Jag har jobbat i många år med Grafisk Design</p>
                              </div>
                          </span>
                      </div>
               </div>
               </a>

               <a href="#two"><div class="hex" id="hex2">
                   <div class="hexagon">
                       <span>
                           <i style="font-size: 30px;" class="fa fa-gamepad" aria-hidden="true"></i>
                           <div class="text">
                               <p id="title">Spel Skapande</p>
                               <p id="content">Jag älskar att jobba med speldesign och skapande</p>
                           </div>
                        </span>
                   </div>
                </div>
                </a>

                <a href="#three"><div class="hex" id="hex3">
                    <div class="hexagon">
                        <span>
                            <i style="font-size: 30px;" class="fa fa-music" aria-hidden="true"></i>
                            <div class="text">
                                <p id="title">Musik Skapande</p>
                                <p id="content">Jag brukar på min fritid <br> skapa musik</p>
                            </div>
                        </span>
                    </div>
                </div></a>

                <a href="#four"><div class="hex" id="hex4">
                    <div class="hexagon">
                        <span>
                            <i style="font-size: 30px;" class="fa fa-file-text-o" aria-hidden="true"></i>
                            <div class="text">
                                <p id="title">CV</p>
                                <p id="content">Här kan du se mitt CV</p>
                            </div>
                        </span>
                   </div>
              </div></a>

              <a href="#four">
                  <div class="hex" id="hex5">
                      <div class="hexagon">
                          <span>
                              <i style="font-size: 30px;" class="fa fa-video-camera" aria-hidden="true"></i>
                              <div class="text">
                                  <p id="title">Videos</p>
                                  <p id="content">Här postar jag min videos</p>
                              </div>
                          </span>
                        </div>
                  </div></a>
             </div>
       </center>
       <br><br><br><br><br><br><br><br><br><br>
            <div class="header" id="myHeader">
                  <div class="buttons">
                        <div class="button-hover">
                              <div class="button">
                                    <a href="youtube.com"><i style="font-size: 17px;" class="fa fa-paint-brush" aria-hidden="true"></i></a>
                              </div>
                        </div>
                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-gamepad" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-music" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-file-text-o" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-video-camera" aria-hidden="true"></i></a>
                        </div>
                  </div>
            </div>

      </div>
</div>

<div class="content">
      <div id="one">
            <div class="section-title">
                  <p>section 1</p>
            </div>
            <div class="hex-img1">
                  <div class="hexagon-img">
                        <div class="hexTop"></div>
                        <div class="hexBottom"></div>
                  </div>
            </div>
      </div>

      <div id="two">
            <p>section 2</p>
      </div>

      <div id="three">
            <p>section 3</p>
      </div>

      <div id="four">
            <p>section 4</p>
      </div>

      <div id="five">
            <p>section 5</p>
      </div>
</div>

<script>
window.onscroll = function() {myFunction()};

var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function myFunction() {
 if (window.pageYOffset >= sticky) {
    header.classList.add("sticky");
 } else {
    header.classList.remove("sticky");
 }
}
</script>

<script type="text/javascript">
$("a[href^='#']").click(function(e) {
      e.preventDefault();

      var position = $($(this).attr("href")).offset().top;

      $("body, html").animate({
            scrollTop: position
      } /* speed */ );
      });
</script>

</body>
</html>
&#13;
&#13;
&#13;

所以我需要帮助才能在我的网站上运行。

当我滚动作为第二个菜单而不是顶部菜单时,我希望标题出现。因此,无论您身在何处,都可以轻松访问。

2 个答案:

答案 0 :(得分:0)

 <!-- Add z-index: 9 to element '.sticky' in your css -->

.buttons {
      margin-left: 460px;
}

.buttons .button a i {
      color: #fff;
      transition: .2s;
}

.buttons .button {
      float: left;
      margin-left: 10px;
      margin-top: 0px;
      transition: .8s;
      background-image: url(img/hexagon0.png);
      width: 50px;
      height: 50px;
      cursor: pointer;
}

.buttons .button a i:hover {
      color: #ff8000;
}

.buttons .button a i {
      margin-top: 15px;
}

.top-container {
  background-color: #f1f1f1;
  padding: 30px;
  text-align: center;
}

.header {
  padding: 10px 16px;
  background: #555;
  color: #f1f1f1;
  z-index: -1;
}

.content {
  padding: 16px;
  z-index: 1;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
  z-index:9;
}

.sticky + .content {
  padding-top: 102px;
}
div.hexagons {
      padding-left: 100px;
      margin-top: 100px;
}

.hex i {
      color: #fff;
      margin-top: 45px;
      transition: .5s ease;
}

.hex {
      cursor: pointer;
      width: 200px;
}

#hex1 {
      margin-left: -300px;
}

#hex2 {
      margin-left: 108px;
      margin-top: -172px;
}

#hex3 {
      margin-top: 60px;
      margin-left: -99px;
}

#hex4 {
      margin-left: 310px;
      margin-top: -172px;
}

#hex5 {
      margin-left: -510px;
      margin-top: -175px;
}

.hex:hover i {
      transform: translateY(-70px);
}

.hex .text p {
      margin-top: -50px;
      opacity: 0;
      transition: .5s;
      transform: translateY(50px);
      color: #fff;
}

.hex .text p#title {
      font-size: 15px;
}

.hex:hover .text p#title {
      font-size: 18px;
}

.hex .text p#content {
      margin-top: 0;
      font-size: 15px;
}

.hex:hover .text p#content {
      font-size: 15px;
}

.hex:hover .text p {
      transform: translateY(0);
      opacity: 1;
}

.hexagon {
  position: relative;
  width: 200px;
  height: 115.47px;
  background-color: #2e2e2e;
  margin: 57.74px 0;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.hexagon:before,
.hexagon:after {
  content: "";
  position: absolute;
  z-index: 1;
  width: 141.42px;
  height: 141.42px;
  -webkit-transform: scaleY(0.5774) rotate(-45deg);
  -ms-transform: scaleY(0.5774) rotate(-45deg);
  transform: scaleY(0.5774) rotate(-45deg);
  background-color: inherit;
  left: 29.2893px;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.hexagon:before {
  top: -70.7107px;
}

.hexagon:after {
  bottom: -70.7107px;
}

/*cover up extra shadows*/
.hexagon span {
  display: block;
  position: absolute;
  top:0px;
  left: 0;
  width:200px;
  height:115.4701px;
  z-index: 2;
  background: inherit;
}

.hex-img1 {
      margin-left: -300px;
      margin-top: -50px;
      z-index: -1;
}

.hexagon-img {
  position: relative;
  width: 800px;
  height: 461.88px;
  margin: 230.94px 0;
  background-image: url(img/2.jpg);
  background-size: auto 912.2134px;
  background-position: center;
  border-left: solid 5px #ff8000;
  border-right: solid 5px #ff8000;
}

.hexTop,
.hexBottom {
  position: absolute;
  z-index: 1;
  width: 565.69px;
  height: 565.69px;
  overflow: hidden;
  -webkit-transform: scaleY(0.5774) rotate(-45deg);
  -ms-transform: scaleY(0.5774) rotate(-45deg);
  transform: scaleY(0.5774) rotate(-45deg);
  background: inherit;
  left: 112.16px;
}

/*counter transform the bg image on the caps*/
.hexTop:after,
.hexBottom:after {
  content: "";
  position: absolute;
  width: 790.0000px;
  height: 456.1067126598044px;
  -webkit-transform:  rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
  -ms-transform:      rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
  transform:          rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
  background: inherit;
}

.hexTop {
  top: -282.8427px;
  border-top: solid 7.0711px #ff8000;
  border-right: solid 7.0711px #ff8000;
}

.hexTop:after {
  background-position: center top;
}

.hexBottom {
  bottom: -282.8427px;
  border-bottom: solid 7.0711px #ff8000;
  border-left: solid 7.0711px #ff8000;
}

.hexBottom:after {
  background-position: center bottom;
}

.hexagon-img:after {
  content: "";
  position: absolute;
  top: 2.8868px;
  left: 0;
  width: 790.0000px;
  height: 456.1067px;
  z-index: 2;
  background: inherit;
}

.content {
      margin-top: 1000px;
}

.section-title {
      background-color: #ff8000;
      width: 300px;
      text-align: center;
      transform: rotateZ(30deg) translateY(-21px) translateX(200px);
}

.section-title p {
      font-size: 50px;
      color: #fff;
      z-index: 1;
      font-weight: bold;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
      <head>
            <meta charset="utf-8">
            <title></title>
            <link rel="stylesheet" href="style.css">
            <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
            <script src="https://code.jquery.com/jquery-3.3.1.js"></script>

      </head>
      <body>

            <center>

                  <div class="hexagons">
                        <a href="#one"><div class="hex" id="hex1">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-paint-brush" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Grafisk Design</p>
                                                <p id="content">Jag har jobbat i många år med Grafisk Design</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#two"><div class="hex" id="hex2">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-gamepad" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Spel Skapande</p>
                                                <p id="content">Jag älskar att jobba med speldesign och skapande</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#three"><div class="hex" id="hex3">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-music" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Musik Skapande</p>
                                                <p id="content">Jag brukar på min fritid <br> skapa musik</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#four"><div class="hex" id="hex4">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-file-text-o" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">CV</p>
                                                <p id="content">Här kan du se mitt CV</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#four"><div class="hex" id="hex5">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-video-camera" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Videos</p>
                                                <p id="content">Här postar jag min videos</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>
                  </div>

            </center>
      <br><br><br><br><br><br><br><br><br><br>
            <div class="header" id="myHeader">
                  <div class="buttons">

                        <div class="button-hover">
                              <div class="button">
                                    <a href="youtube.com"><i style="font-size: 17px;" class="fa fa-paint-brush" aria-hidden="true"></i></a>
                              </div>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-gamepad" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-music" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-file-text-o" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#"><i style="font-size: 17px;" class="fa fa-video-camera" aria-hidden="true"></i></a>
                        </div>
                  </div>
            </div>

      </div>
</div>

<div class="content">
      <div id="one">
            <div class="section-title">
                  <p>section 1</p>
            </div>
            <div class="hex-img1">
                  <div class="hexagon-img">
                        <div class="hexTop"></div>
                        <div class="hexBottom"></div>
                  </div>
            </div>
      </div>

      <div id="two">
            <p>section 2</p>
      </div>

      <div id="three">
            <p>section 3</p>
      </div>

      <div id="four">
            <p>section 4</p>
      </div>

      <div id="five">
            <p>section 5</p>
      </div>
</div>

<script>
window.onscroll = function() {myFunction()};

var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function myFunction() {
 if (window.pageYOffset >= sticky) {
    header.classList.add("sticky");
 } else {
    header.classList.remove("sticky");
 }
}
</script>

<script type="text/javascript">
$("a[href^='#']").click(function(e) {
      e.preventDefault();

      var position = $($(this).attr("href")).offset().top;

      $("body, html").animate({
            scrollTop: position
      } /* speed */ );
      });
</script>

      </body>
</html>

答案 1 :(得分:0)

您的z-index元素需要更高的.sticky。 目前,未在固定标题上触发点击事件。

您需要在粘贴标头中添加锚点,否则JS代码不知道您要滚动到哪个部分。 (youtube.com在这里不起作用;))

你在六边形中使用了两次相同的锚#four,所以我也修复了它。

.buttons {
      margin-left: 460px;
}

.buttons .button a i {
      color: #fff;
      transition: .2s;
}

.buttons .button {
      float: left;
      margin-left: 10px;
      margin-top: 0px;
      transition: .8s;
      background-image: url(img/hexagon0.png);
      width: 50px;
      height: 50px;
      cursor: pointer;
}

.buttons .button a i:hover {
      color: #ff8000;
}

.buttons .button a i {
      margin-top: 15px;
}

.top-container {
  background-color: #f1f1f1;
  padding: 30px;
  text-align: center;
}

.header {
  padding: 10px 16px;
  background: #555;
  color: #f1f1f1;
  z-index: -1;
}

.content {
  padding: 16px;
  z-index: 1;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 10;
}

.sticky + .content {
  padding-top: 102px;
}
div.hexagons {
      padding-left: 100px;
      margin-top: 100px;
}

.hex i {
      color: #fff;
      margin-top: 45px;
      transition: .5s ease;
}

.hex {
      cursor: pointer;
      width: 200px;
}

#hex1 {
      margin-left: -300px;
}

#hex2 {
      margin-left: 108px;
      margin-top: -172px;
}

#hex3 {
      margin-top: 60px;
      margin-left: -99px;
}

#hex4 {
      margin-left: 310px;
      margin-top: -172px;
}

#hex5 {
      margin-left: -510px;
      margin-top: -175px;
}

.hex:hover i {
      transform: translateY(-70px);
}

.hex .text p {
      margin-top: -50px;
      opacity: 0;
      transition: .5s;
      transform: translateY(50px);
      color: #fff;
}

.hex .text p#title {
      font-size: 15px;
}

.hex:hover .text p#title {
      font-size: 18px;
}

.hex .text p#content {
      margin-top: 0;
      font-size: 15px;
}

.hex:hover .text p#content {
      font-size: 15px;
}

.hex:hover .text p {
      transform: translateY(0);
      opacity: 1;
}

.hexagon {
  position: relative;
  width: 200px;
  height: 115.47px;
  background-color: #2e2e2e;
  margin: 57.74px 0;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.hexagon:before,
.hexagon:after {
  content: "";
  position: absolute;
  z-index: 1;
  width: 141.42px;
  height: 141.42px;
  -webkit-transform: scaleY(0.5774) rotate(-45deg);
  -ms-transform: scaleY(0.5774) rotate(-45deg);
  transform: scaleY(0.5774) rotate(-45deg);
  background-color: inherit;
  left: 29.2893px;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}

.hexagon:before {
  top: -70.7107px;
}

.hexagon:after {
  bottom: -70.7107px;
}

/*cover up extra shadows*/
.hexagon span {
  display: block;
  position: absolute;
  top:0px;
  left: 0;
  width:200px;
  height:115.4701px;
  z-index: 2;
  background: inherit;
}

.hex-img1 {
      margin-left: -300px;
      margin-top: -50px;
      z-index: -1;
}

.hexagon-img {
  position: relative;
  width: 800px;
  height: 461.88px;
  margin: 230.94px 0;
  background-image: url(img/2.jpg);
  background-size: auto 912.2134px;
  background-position: center;
  border-left: solid 5px #ff8000;
  border-right: solid 5px #ff8000;
}

.hexTop,
.hexBottom {
  position: absolute;
  z-index: 1;
  width: 565.69px;
  height: 565.69px;
  overflow: hidden;
  -webkit-transform: scaleY(0.5774) rotate(-45deg);
  -ms-transform: scaleY(0.5774) rotate(-45deg);
  transform: scaleY(0.5774) rotate(-45deg);
  background: inherit;
  left: 112.16px;
}

/*counter transform the bg image on the caps*/
.hexTop:after,
.hexBottom:after {
  content: "";
  position: absolute;
  width: 790.0000px;
  height: 456.1067126598044px;
  -webkit-transform:  rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
  -ms-transform:      rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
  transform:          rotate(45deg) scaleY(1.7321) translateY(-228.0534px);
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
  background: inherit;
}

.hexTop {
  top: -282.8427px;
  border-top: solid 7.0711px #ff8000;
  border-right: solid 7.0711px #ff8000;
}

.hexTop:after {
  background-position: center top;
}

.hexBottom {
  bottom: -282.8427px;
  border-bottom: solid 7.0711px #ff8000;
  border-left: solid 7.0711px #ff8000;
}

.hexBottom:after {
  background-position: center bottom;
}

.hexagon-img:after {
  content: "";
  position: absolute;
  top: 2.8868px;
  left: 0;
  width: 790.0000px;
  height: 456.1067px;
  z-index: 2;
  background: inherit;
}

.content {
      margin-top: 1000px;
}

.section-title {
      background-color: #ff8000;
      width: 300px;
      text-align: center;
      transform: rotateZ(30deg) translateY(-21px) translateX(200px);
}

.section-title p {
      font-size: 50px;
      color: #fff;
      z-index: 1;
      font-weight: bold;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
      <head>
            <meta charset="utf-8">
            <title></title>
            <link rel="stylesheet" href="style.css">
            <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
            <script src="https://code.jquery.com/jquery-3.3.1.js"></script>

      </head>
      <body>

            <center>

                  <div class="hexagons">
                        <a href="#one"><div class="hex" id="hex1">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-paint-brush" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Grafisk Design</p>
                                                <p id="content">Jag har jobbat i många år med Grafisk Design</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#two"><div class="hex" id="hex2">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-gamepad" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Spel Skapande</p>
                                                <p id="content">Jag älskar att jobba med speldesign och skapande</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#three"><div class="hex" id="hex3">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-music" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Musik Skapande</p>
                                                <p id="content">Jag brukar på min fritid <br> skapa musik</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#four"><div class="hex" id="hex4">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-file-text-o" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">CV</p>
                                                <p id="content">Här kan du se mitt CV</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>

                        <a href="#five"><div class="hex" id="hex5">
                              <div class="hexagon">
                                    <span>
                                          <i style="font-size: 30px;" class="fa fa-video-camera" aria-hidden="true"></i>
                                          <div class="text">
                                                <p id="title">Videos</p>
                                                <p id="content">Här postar jag min videos</p>
                                          </div>
                                    </span>
                              </div>
                        </div></a>
                  </div>

            </center>
      <br><br><br><br><br><br><br><br><br><br>
            <div class="header" id="myHeader">
                  <div class="buttons">

                        <div class="button-hover">
                              <div class="button">
                                    <a href="#one"><i style="font-size: 17px;" class="fa fa-paint-brush" aria-hidden="true"></i></a>
                              </div>
                        </div>

                        <div class="button">
                              <a href="#two"><i style="font-size: 17px;" class="fa fa-gamepad" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#three"><i style="font-size: 17px;" class="fa fa-music" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#four"><i style="font-size: 17px;" class="fa fa-file-text-o" aria-hidden="true"></i></a>
                        </div>

                        <div class="button">
                              <a href="#five"><i style="font-size: 17px;" class="fa fa-video-camera" aria-hidden="true"></i></a>
                        </div>
                  </div>
            </div>

      </div>
</div>

<div class="content">
      <div id="one">
            <div class="section-title">
                  <p>section 1</p>
            </div>
            <div class="hex-img1">
                  <div class="hexagon-img">
                        <div class="hexTop"></div>
                        <div class="hexBottom"></div>
                  </div>
            </div>
      </div>

      <div id="two">
            <p>section 2</p>
      </div>

      <div id="three">
            <p>section 3</p>
      </div>

      <div id="four">
            <p>section 4</p>
      </div>

      <div id="five">
            <p>section 5</p>
      </div>
</div>

<script>
window.onscroll = function() {myFunction()};

var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function myFunction() {
 if (window.pageYOffset >= sticky) {
    header.classList.add("sticky");
 } else {
    header.classList.remove("sticky");
 }
}
</script>

<script type="text/javascript">
$("a[href^='#']").click(function(e) {
      e.preventDefault();

      var position = $($(this).attr("href")).offset().top;

      $("body, html").animate({
            scrollTop: position
      } /* speed */ );
      });
</script>

      </body>
</html>