In this article, we’ll learn how CSS transforms can be used in the real world to solve various tasks and achieve interesting results. Specifically, you’ll learn how to adjust elements vertically, create nice-looking arrows, build loading animations and create flip animations.
Transformations of HTML elements became a CSS3 standard in 2012 and were available in some browsers before then. Transformations allow you to transform elements on a web page — as explained in our 101 article on CSS transforms. You can rotate, scale, or skew your elements easily with just one line of code, which was difficult before. Both 2D and 3D transformations are available.
As for browser support, 2D transforms are supported by all major browsers — including Internet Explorer, which has had support since version 9. As for 3D transformations, IE has only partial support since version 10.
This article won’t focus on the basics of transformations. If you don’t feel very confident with transformations, I recommend reading about 2D and 3D transforms first.
本文将不专注于转换的基础。如果您对转换不太满意,建议您先阅读2D和3D转换 。
垂直对齐的孩子 (Vertically Aligning Children)
Any web designer knows how tedious it can be to vertically align elements. This task may sound very simple to a person who’s not familiar with CSS, but in reality there’s a jumble of techniques that are carefully preserved between generations of developers. Some suggest using display: inline with vertical-align: middle, some vote for display: table and accompanying styles, whereas true old school coders are still designing their sites with tables (just joking, don’t do that!). Also, it’s possible to solve this task with Flexbox or Grids, but for smaller components, transforms may be a simpler option.
任何网页设计师都知道垂直对齐元素是多么乏味。 对于不熟悉CSS的人来说,这项任务听起来很简单,但实际上,世世代代之间精心保留了许多技术。 有些人建议使用display: inline with vertical-align: middle ,有些人赞成display: table和伴随的样式,而真正的老派编码人员仍在用表设计站点(只是在开玩笑,不要那样做)。 同样,可以使用Flexbox或Grids解决此任务,但是对于较小的组件,变换可能是一个更简单的选择。
Vertical alignment can be more complex when element heights are variable. However, CSS transformations provide one way to solve the problem. Let’s see a very simple example with two nested divs:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam
Nothing complex: just two nested blocks with a Lorem Ipsum text of different length.
没什么复杂的:只有两个嵌套块,它们具有不同长度的Lorem Ipsum文本 。
Let’s set width, height, and border for the parent, as well as some spacing to make it look nicer:
And now your customer says: “Please align the text vertically so that it appears in the middle of these red boxes”. Nooo!. But fear not: we’re armed with transformations! The first step is to position our children relatively and move them 50% to the bottom:
So, what’s happening here? top: 50% moves the top of the child element to the center of the parent:
那么,这里发生了什么? top: 50%将子元素的顶部移动到父元素的中心:
But this is not enough, because we want the child’s center to be aligned with the parent’s center. Therefore, by applying the translateY we move the child up 50% of its height:
Some developers have reported that this approach can cause the children to become blurry due to the element being placed on a “half pixel”. A solution for this is to set the perspective of the element:
This is it! Your children are now aligned properly even with variable text, which is really nice. Of course, this solution is a little hacky, but it works in older browsers in contrast to CSS Grid. The final result can be seen on CodePen:
See the Pen CSS Transforms: Vertical-Align by SitePoint (@SitePoint) on CodePen.
见笔CSS变换:垂直对齐由SitePoint( @SitePoint上) CodePen 。
创建箭头 (Creating Arrows)
Another very interesting use case for transformations is creating speech bubble arrows that scale properly. I mean, you can definitely create arrows with a graphical editor, but that’s a bit tedious, and also they may not scale well if you use a bitmap image.
I’m using rem units here so that if the root’s font size is changed, the box is scaled accordingly.
我在这里使用rem单位,以便如果更改根的字体大小,则将相应地缩放框。
Next, I’d like to make this bubble become more “bubble-ish” by displaying an arrow to the right. We’ll achieve that by using a ::before pseudo-selector:
Unfortunately, things on the web don’t happen instantly. Users often have to wait for an action to complete, be it sending an email, posting their comment, or uploading photos. Therefore, it’s a good idea to display a “loading” indicator so that users understand they’ll have to wait for a few seconds.
Previously, when there were no CSS animations and transformations, we would probably use a graphical editor to create an animated GIF loader image. This is no longer necessary because CSS3 offers powerful options. So, let’s see how transformations can be utilized in conjunction with animations to create a nice-looking jumping ball.
Here’s our shiny purple ball that resembles pokeball:
这是我们类似波克球的闪亮紫色球:
How do we make it jump? Well, with a help of CSS animations! Specifically, I’m going to define an infinite animation called jump that takes 1.5 seconds to complete and performs the listed actions back and forth:
Next, let’s ask ourselves: what does it mean when we say “to jump”? In the simplest case, it means moving up and down on the Y axis (vertically). So, let’s use the translateY function again and define keyframes:
@keyframes jump {
from {
transform: translateY(0px)
}
to {
transform: translateY(-50px)
}
}
So, initially the ball is at coordinates (0,0), but then we move it up to (0,-50). However, currently we might not have enough space for the ball to actually jump, so let’s give it some margin:
Of course, we can do more. For instance, let’s rotate this ball while it jumps:
当然,我们可以做更多。 例如,让我们在跳球时旋转它:
@keyframes jump {
from {
transform: translateY(0px) rotate(0deg)
}
to {
transform: translateY(-50px) rotate(360deg)
}
}
Also, why don’t we make it smaller? For that, let’s utilize a scale function that changes the element’s width and height using the given multipliers:
另外,为什么不缩小尺寸呢? 为此,让我们利用scale函数,使用给定的乘数来更改元素的宽度和高度:
@keyframes jump {
from {
transform: translateY(0px) rotate(0deg) scale(1,1);
}
to {
transform: translateY(-50px) rotate(360deg) scale(0.8,0.8);
}
}
Note, by the way, that all functions should be listed for the transform property in both from and to sections, because otherwise the animation won’t work properly!
That’s it! Our loader element is ready, and here’s the final result:
而已! 我们的加载器元素已经准备就绪,这是最终结果:
See the Pen CSS Transformations: Loader Ball by SitePoint (@SitePoint) on CodePen.
见笔CSS转换:装载机球由SitePoint( @SitePoint上) CodePen 。
使用SVG创建“旋转器”加载器 (Creating a “Spinner” Loader with SVG)
We’ve already seen how to create a simple “jumping ball” loader with just a few lines of code. For a more complex effect, however, you can utilize SVGs which are defined with a set of special tags.
As an example, let’s create a spinner loader. Here’s the corresponding SVG:
例如,让我们创建一个微调加载器。 这是相应的SVG:
Main things to note here:
这里要注意的主要事情:
Our canvas has a viewport of 66×66. 我们的画布的视口为66×66。
This defines the actual circle that’s going to spin. Its center is located at (33,33) and the radius is 31px. We’ll also have a stroke of 2px, which means 31 * 2 + 2 * 2 = 66. stroke="url(#gradient) means that the color of the stroke is defined by an element with an ID of #gradient.
That’s our gradient for the spinner’s stroke. It has three breakpoints that set different opacity values, which is going to result in a pretty cool effect. 这就是旋转器行程的渐变。 它具有三个设置不同不透明度值的断点,这将产生非常酷的效果。
That’s a dot that’s going to be displayed on the spinner’s stroke. It will look like a small “head”. 那是一个点,将显示在微调器的笔划上。 它看起来像个小“头”。
Now let’s define some styling for the canvas and scale it up to 180×180:
Here’s how our spinner looks at this stage. For now it doesn’t spin, of course:
这是我们的微调器在此阶段的外观。 现在,它当然不会旋转:
Now let’s make it spin, which effectively means rotating it by 360 degrees:
现在让它旋转,这实际上意味着将其旋转360度:
.spinner {
// ...
animation: rotate 2s linear infinite;
}
@keyframes rotate {
to {
transform: rotate(360deg);
}
}
This is an infinite animation that takes 2 seconds to complete.
这是一个无限的动画,需要2秒钟才能完成。
Also, we can achieve an interesting effect of a “snake trying to bite its tail” with a skew function. Remember that I’ve called that small dot a “head”? Why don’t we pretend that it is a snake’s head then? In order to make it look more realistic, we’ll skew it on the X axis:
The last example is a photo with a flip animation. When you hover over a photo, it flips and its description is shown. It can be useful for Instagram-like websites.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Here we have a container with three photos. These photos are going to actually have two sides: front and back, just like a coin has heads and tails. The front contains the actual image, whereas the back (which is not visible initially) contains the description.
Now it’s time for some magic. I’d like children of the .photo block to be positioned in 3D with the help of transform-style property. This will allow us to achieve a feeling of perspective:
Now when you hover over the container, the .photo will rotate and you’ll be able to see its back with the description. You’ll probably want this to happen more smoothly, so add a simple CSS transition:
Without any doubts, CSS transformations and animations are very powerful tools that can be used to create interesting and beautiful effects. However, it’s important to be reasonable about their usage and not abuse them. Remember that you’re creating websites for users and not for yourself (in most cases, anyway). Therefore, CSS should be utilized to introduce better user experience, rather than to show all the cool tricks you’ve learned so far.
For one thing, too many effects on the page distracts the users. Some visitors may have motion sickness or vestibular disorders, so they’ll find it very hard to use a website with fast animations. On top of that, you should make sure that the page works with older browsers, because it may happen that some important element is hidden or inaccessible when the animations don’t work.
In this article, we have seen how CSS transformations in conjunction with other techniques can be used to solve various design tasks. We’ve seen how to vertically align elements on the page, create scalable arrows, bouncing and spinning loaders, and how to implement flip animation. Of course, you’ve learned only some techniques, but the only limit is your imagination.
继承 extends 多态
继承是面向对象最经常使用的特征之一:继承语法是通过继承发、基类的域和方法 //继承就是从现有的类中生成一个新的类,这个新类拥有现有类的所有extends是使用继承的关键字:
在A类中定义属性和方法;
class A{
//定义属性
int age;
//定义方法
public void go
hive DDL语法汇总
1、对表重命名
hive> ALTER TABLE table_name RENAME TO new_table_name;
2、修改表备注
hive> ALTER TABLE table_name SET TBLPROPERTIES ('comment' = new_comm