This article is a part of our AtoZ CSS Series. You can find other entries to the series here View the full screencast and transcript for Hover here.
本文是我们的AtoZ CSS系列的一部分。 你可以找到其他条目的一系列这里查看悬停全截屏和成绩单这里 。
Welcome to our AtoZ CSS series! In this series, I’ll be exploring different CSS values (and properties) beginning with a letter of the alphabet. We know that sometimes screencasts are just not enough, in this article we’ve added a new quick tip about Hover for you.
欢迎来到我们的AtoZ CSS系列! 在本系列中,我将探索以字母开头的不同CSS值(和属性)。 我们知道有时候视频广播还不够,在本文中,我们为您添加了一个有关悬停的新快速提示。
![1H-01](https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/08/14731453271H-01-1024x576.png)
H代表悬停和高度 (H is for Hover and Height)
There’s not too much more I can say about Hover that I haven’t already covered in the video about the letter H. However, there are some cool animations that you can apply for a hover state. Google “CSS hover effects” and you’ll find plenty.
关于悬停,我能说的还不多,关于视频H的视频我还没有介绍过。但是,有一些很酷的动画可以申请悬停状态。 Google的“ CSS悬停效果”,您会发现很多。
Here are a couple of sites that have some nifty effects:
这是几个具有不错效果的网站:
Further to those, I recently produced a video for Code School, all about a library called hover.css.
除此之外,我最近还为Code School制作了一个视频 ,内容涉及一个名为hover.css的库。
Another CSS H (that I haven’t gone into much detail about on this site) is height
.
另一个CSS H(在此站点上我没有详细介绍)是height
。
The height property is used to define the content height on a containing element. All the standard length units (like px, em, rem, %, vw, vh and others) can be used to control height
.
height属性用于定义包含元素上的内容高度。 所有标准长度单位(例如px,em,rem,%,vw,vh等)均可用于控制height
。
If the height of an element is not specifically set, it’s calculated as the minimum height to hold all the containing elements (corresponding to the default value auto
).
如果未特别设置元素的高度,则将其计算为容纳所有包含元素的最小高度(对应于默认值auto
)。
It’s generally advisable to avoid explicitly setting a height on any elements as it restricts the flexibility of the element – meaning it can’t grow as the content changes. This is particularly risky when working on a responsive design when content needs to reflow vertically as the available width changes.
通常建议避免在任何元素上明确设置高度,因为它限制了元素的灵活性,这意味着它不能随着内容的更改而增长。 在响应式设计中,当内容需要随着可用宽度变化而垂直回流时,这特别危险。
As such, I tend to only set height
on elements that have predefined dimensions – like images. Another use case is when using absolute
or fixed
position as height
(and width
) shrink wrap around positioned elements.
因此,我倾向于仅在具有预定义尺寸的元素(例如图像)上设置height
。 另一个用例是使用absolute
或fixed
位置作为height
(和width
)收缩包裹在定位的元素周围。
Here’s an example that demonstrates the problem with setting a fixed height.
这是一个示例,演示了设置固定高度的问题。
See the Pen The height property by SitePoint (@SitePoint) on CodePen.
请参见CodePen上的SitePoint ( @SitePoint )提供的Pen height属性 。
While the first set of text looks styled correctly, as soon as the text is shorter or longer than the styling no longer looks correct – the containing box appears too big, or the text flows outside the box.
虽然第一组文本的样式正确,但只要其短于或长于样式不再正确,则包含的框看起来太大,或者文本在框外流动。
A solution to the overflowing text could be to use the overflow property, but this cuts off the text and makes it unreadable.
解决溢出文本的方法可能是使用overflow属性,但这会截断文本并使之难以阅读。
This situation could be completely avoided by not specifying the height in the first place. If I can improve the flexibility of my code without doing anything at all, that gets my vote!
如果不首先指定高度,则可以完全避免这种情况。 如果我不做任何事情就可以提高代码的灵活性,那将赢得我的投票!