Home > Web Front-end > CSS Tutorial > How to implement image translation in css3

How to implement image translation in css3

青灯夜游
Release: 2023-01-07 11:43:24
Original
3602 people have browsed it

In css3, you can use the transform attribute to realize image translation. When the value is set to "translate(x,y)", the image can be translated in the x-axis and y-axis directions at the same time. The value is "translate X(x) " can translate in the x-axis direction, and the value "translateY(y)" can translate in the y-axis direction.

How to implement image translation in css3

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

TheTransform property applies a 2D or 3D transformation to the element. This property allows you to rotate, scale, move, tilt, etc. the element.

The definition of translation: the element moves in a straight line from its original position.

The Transform attribute has three attribute values ​​​​for setting translation:

  • translate (x, y) moves simultaneously in the x-axis and y-axis directions

  • translate

    Code example:
  • HTML code:
  • <!-- translate-->
    <div class="card">
      <div class="box translate">
        <div class="fill"></div>
      </div>
      <p>translate(45px)  </p>
    </div>
    <div class="card">
      <div class="box translateX">
        <div class="fill"></div>
      </div>
      <p>translateX(45px)</p>
    </div>
    <div class="card">
      <div class="box translateY">
        <div class="fill"></div>
      </div>
      <p>translateY(45px)</p>
    </div>
    Copy after login
css code:

*, *:after, *:before {
  box-sizing: border-box;
}

body {
  background: #F5F3F4;
  margin: 0;
  padding: 10px;
  font-family: &#39;Open Sans&#39;, sans-serif;
  text-align: center;
}

.card {
  display: inline-block;
  margin: 10px;
  background: #fff;
  padding: 15px;
  min-width: 200px;
  box-shadow: 0 3px 5px #ddd;
  color: #555;
}
.card .box {
  width: 100px;
  height: 100px;
  margin: auto;
  background: #ddd;
  cursor: pointer;
  box-shadow: 0 0 5px #ccc inset;
}
.card .box .fill {
  width: 100px;
  height: 100px;
  position: relative;
  background: pink;
  opacity: .5;
  box-shadow: 0 0 5px #ccc;
  -webkit-transition: 0.3s;
  transition: 0.3s;
}
.card p {
  margin: 25px 0 0;
}

.translate:hover .fill {
  -webkit-transform: translate(45px, 1em);
  transform: translate(45px, 1em);
}

.translateX:hover .fill {
  -webkit-transform: translateX(45px);
  transform: translateX(45px);
}

.translateY:hover .fill {
  -webkit-transform: translateY(45px);
  transform: translateY(45px);
}
Copy after login

Rendering:


(Learning video sharing:

css video tutorial

)

The above is the detailed content of How to implement image translation in css3. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template