phone interaction

In this example below you will see how to do a phone interaction with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by knyttneve, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright knyttneve ©
  • HTML
  • CSS
  • JavaScript
    .phone
  .blank.top
    .camera
  .screen
  .blank.bottom
  .buttons
    .button
    .button
    .button
    .button

/*Downloaded from https://www.codeseek.co/knyttneve/phone-interaction-LrZrOj */
    @function em($pxval, $base: 16px) {
  @if (unitless($pxval)) {
    $pxval: $pxval * 1px;
  }

  @if (unitless($base)) {
    $base: $base * 1px;
  }

  @return $pxval / $base * 1em;
}

html {
  width: 100%;
  height: 100%;
}

body {
  background: #16b587;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.phone {
  position: relative;
  width: em(200);
  height: em(400px);
  background: #fff;
  border-radius: em(26px);
  border: 3px solid #d2c1a9;
  padding: 0 em(10px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.screen {
  height: em(310px);
  background: #383938;
  box-sizing: border-box;
  border: 2px solid #000;
}
.blank {
  height: em(40px);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.camera {
  width: em(25px);
  position: relative;
  height: 3px;
  background: #383938;
  margin-top: em(6px);
  border-radius: 20%;
  &:before {
    position: absolute;
    left: em(-12px);
    width: em(6px);
    height: em(6px);
    content: "";
    border-radius: 50%;
    top: -50%;
    background: #383938;
  }
  &:after {
    position: absolute;
    width: em(4px);
    height: em(4px);
    content: "";
    left: calc(50% - #{em(2px)});
    border-radius: 50%;
    top: em(-8px);
    background: #383938;
  }
}

.buttons {
  position: absolute;
  left: em(-6px);
  top: em(43px);
  width: calc(100% + #{em(12px)});
}

.button {
  width: em(3px);
  height: em(22px);
  position: absolute;
  left: 0;
  top: 0;
  background: red;
  background: #dccebb;
  border-left: 1px solid darken(#dccebb, 10%);
  border-radius: em(2px) 0 0 em(2px);
  &:first-child {
    height: em(14px);
  }
  &:nth-child(2) {
    top: em(28px);
  }
  &:nth-child(3) {
    top: em(60px);
  }
  &:nth-child(4) {
    border-left: 0;
    border-right: 1px solid darken(#dccebb, 10%);
    left: auto;
    right: 0;
    top: em(20px);
    border-radius: 0 em(2px) em(2px) 0;
  }
}

.top:after {
  content: "";
  position: absolute;
  bottom: em(10px);
  width: calc(100% + 6px);
  left: em(-3px);
  height: em(3px);
  background: #fff;
}
.bottom:after {
  width: em(24px);
  height: em(24px);
  border-radius: 50%;
  border: 1px solid #dccebb;
  position: absolute;
  left: 50%;
  content: "";
  top: 50%;
  transform: translate(-50%, -50%);
}


/*Downloaded from https://www.codeseek.co/knyttneve/phone-interaction-LrZrOj */
    

Comments