Search code examples
htmlcsstexthref

Making the page smaller in CSS?


I am developing an intro site for myself, but I came across an error. I use a video background, I hope that I can keep and still resolve my issue with the link.

Here is a screenshot of the problem:https://gyazo.com/d3f9c4f933f5b54c70835451d62d258f

The "Riptide" link is technically centered on the page, but I do not want the page being as wide as it is. If I minimize the page width, the link moves. This is my current code:

@import url('https://fonts.googleapis.com/css?family=Raleway');
body {
    max-width: 100%;
}
.fullscreen-bg {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  z-index: -100;
}

.fullscreen-bg__video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

@media (min-aspect-ratio: 16/9) {
  .fullscreen-bg__video {
    height: 300%;
    top: -100%;
  }
}

@media (max-aspect-ratio: 16/9) {
  .fullscreen-bg__video {
    width: 300%;
    left: -100%;
  }
}

@media (max-width: 767px) {
  .fullscreen-bg {
    background: url('../img/videoframe.jpg') center center / cover no-repeat;
  }

  .fullscreen-bg__video {
    display: none;
  }
}

#riptide {
    font-size: 4.5em;
    text-decoration: none;
    font-family: "Raleway", sans-serif;
    font-weight: 900;
    color: white;
    position: relative;
    padding: 15px;
    top: 40%;
    margin-left: 50%;
    margin-right: 50%;
    border-radius: 10px;
    transition: color 0.6s, background-color 0.6s;
}

#riptide:hover {
    color: black;
    background-color: white;
}

Solution

  • Now knowing what the OP was needing the following is the solution.

    We wrapped his anchor with a <div> and positioned that absolutely in the middle of the page. That was done with the following:

    #test{
      position:absolute;
      top:50%;
      left:50%;
      transform:translate(-50%,-50%);
    }
    

    With the RIPTIDE section simplified to:

    #riptide {
      font-size: 4.5em;
      text-decoration: none;
      font-family: "Raleway", sans-serif;
      font-weight: 900;
      color: white;
      padding: 15px;
      text-align: center;
      border-radius: 10px;
      transition: color 0.6s, background-color 0.6s;
      height: 100%;
      display: block;
    }
    

    Jsfiddle: https://jsfiddle.net/yrscgvek/10/

    Let me know what is going on or give more info. I will do what I can to help.