css3常用技巧

Though, CSS3 isn’t a complex language but you’ll there are greater chances that you’ll stumble across certain new things that’ll probably leave you in a puzzled state. For instance, adding properties that you won’t have used, or adding details of the specifications that you aren’t aware of, and so on.

虽然,CSS3不是一种复杂的语言,但是您将有更多的机会偶然发现某些新事物,这些新事物可能会使您感到困惑。 例如,添加您不会使用的属性,或者添加您不了解的规范的详细信息,等等。

If you want to become a CSS3 styling expert, then below are a few tips that you should consider:

如果您想成为CSS3样式专家,那么以下是您应该考虑的一些技巧:

  1. 以CSS为中心 (Centering in CSS)

    Many people find centering things in CSS pretty hard. In fact, people haven’t been able to crack the centering problem in web design. However, it’s not that hard and is rather a kind of doable thing.

    Generally, designers use absolute positioning to make the elements perfectly centered. But, when it comes to vertical centering you should use a CSS3 transform instead. Though, you’ll require a container div for offering an absolute reference, but you can auto-adjust the vertical positioning by using the transform as follows:

    div.container {
    height: however many em you want;
    position: relative }div.container p {
    margin: 0;           //Kills lingering offsets
    position: absolute;
    top: 50%;       //(Nearly) centre the element vertically
    transform: translate(0, -50%); }   //Nudge it up by half its height

    This is a great solution for animation, as it visually make changes to the elements by transforming their appearance. Using CSS3 transform you can apply several visual effects to your elements like move, rotate, skew and other effects. In order to center the 3D or 2D element vertically and horizontally, add or change the height and width of the element as shown below:

    许多人发现CSS中的居中很难。 实际上,人们无法解决网页设计中的居中问题。 但是,这并不困难,而是一种可行的事情。

    通常,设计人员使用绝对定位来使元素完美居中。 但是,在垂直居中时,您应该改用CSS3转换。 虽然,您将需要一个容器div来提供绝对参考,但是您可以通过使用以下转换自动调整垂直位置:

    div.container {
    height: however many em you want;
    position: relative }div.container p {
    margin: 0;           //Kills lingering offsets
    position: absolute;
    top: 50%;       //(Nearly) centre the element vertically
    transform: translate(0, -50%); }   //Nudge it up by half its height

    对于动画而言,这是一个很好的解决方案,因为它可以通过变换外观来直观地更改元素。 使用CSS3转换,您可以将多种视觉效果应用于元素,例如移动,旋转,倾斜和其他效果。 为了使3D或2D元素垂直和水平居中,如下所示添加或更改元素的高度和宽度:

  2. 了解CSS特异性 (Understanding CSS Specificity)

    Specificity isn’t a very common word and chances are that you might not have even heard of it, but it’s a fundamental concept that any person who want to become good at styling CSS must understand. Specificity helps a browser choose most relevant property values to an element and gets them applied by the browsers. The problem with specificity is that it restricts CSS-rules to be applied to some elements, even though you think that the rules should have been applied.

    In order to resolve the problem you need to remember certain specificity rules, such as:

    • ID selectors have higher specificity in comparison to attribute selectors.
    • Rules having more specific selectors will have greater specificity.
    • The last defined rule will override previous and conflicting rules and so on.

    In case you’re facing specificity issues, make sure to avoid using !important declaration. In addition, try using minimum number of selectors required for styling an element. And put your styles in LVHA (link-visited-hover-active) order.

    特异性不是一个很常见的词,可能您甚至没有听说过它,但这是一个想要精通CSS样式的人必须理解的基本概念。 特殊性可帮助浏览器选择与元素最相关的属性值,并使它们由浏览器应用。 特殊性的问题是,即使您认为应该已应用规则,它也会限制将CSS规则应用于某些元素。

    为了解决该问题,您需要记住某些特定性规则,例如:

    • 与属性选择器相比,ID选择器具有更高的特异性。
    • 具有更具体选择器的规则将具有更大的特异性。
    • 最后定义的规则将覆盖先前的规则和有冲突的规则,依此类推。

    如果遇到特殊性问题,请确保避免使用!important声明。 此外,请尝试使用最少的元素样式选择器数量。 并将您的样式置于LVHA(链接访问的悬停活动)顺序中。

  3. 在RGB上使用HSL (Use HSL Over RGB)

    Generally, most of the web designers make use of the age-old “RGB Hex tag system” to define colors. Define red, green and blue colors individually, include opacity if required. This approach is fine until you’re working with a color wheel, and merely want to determine complementary/contrasting hues having resembling saturations.

    In such a situation you’ll have to look for an RGB to HSLa calculator and perform plenty of conversions. Fortunately, CSS3 supports HSLa colour specs, as follows:

    background-color: hsla(120, 50%, 50%, 1);

    通常,大多数网页设计师都使用古老的“ RGB Hex标签系统”来定义颜色。 分别定义红色,绿色和蓝色,如果需要,可以包括不透明度。 除非您使用色轮,并且只想确定具有类似饱和度的互补/对比色相,否则这种方法很好。

    在这种情况下,您将不得不寻找RGB到HSLa计算器并执行大量转换。 幸运的是,CSS3支持HSLa颜色规范,如下所示:

  4. CSS3阴影 (CSS3 Drop Shadows)

    Rather than slicing the image and then capturing the shadow, it would be better if you could replicate the task using CSS3. For this purpose, you’ll have to include two lines of codes into your CSS, so as to make the effect work in all latest browsers:

    -abc-box-shadow: 1px 4px 10px #ccc;-xyz-box-shadow: 1px 4px 10px #ccc;

    如果您可以使用CSS3复制任务,则比切片图像然后捕获阴影要好。 为此,您必须在CSS中包含两行代码,以使效果在所有最新的浏览器中均有效:

  5. 简化字体样式 (Simplify Your Font Style)

    When using @font-face, probably you’ll use different weights and styles for the same font, but make sure to tag them using font-weight:normal and font-style:normal, as shown in the snippet below:

    @font-face {
    font-family: ‘Italic name goes here’;
    src: url(‘URL-of-italic-font’);
    format:(‘Usually truetype’);
    font-weight:normal;
    font-style:normal;
    }

    Rather than collecting all the related fonts when typing, you should collect them into a single family at the time of loading. And then, use ‘font-weight: bold’ for elements that needs to be bold and use ‘font-style: italic’ for elements that needs to be italic, and apply them to CSS:

    使用@font-face ,可能会对同一字体使用不同的权重和样式,但是请确保使用font-weight:normalfont-style:normal标记它们,如下面的代码片段所示:

    @font-face {
    font-family: ‘Italic name goes here’;
    src: url(‘URL-of-italic-font’);
    format:(‘Usually truetype’);
    font-weight:normal;
    font-style:normal;
    }

    而不是在键入时收集所有相关字体,而是应在加载时将它们收集到一个家族中。 然后,对需要使用粗体的元素使用“字体权重:粗体”,对需要使用斜体的元素使用“字体样式:斜体”,并将其应用于CSS:

结束吧! (Let’s Wrap Up!)

While working in CSS3 you’re less likely to come across obstacles, because of the its syntax. The syntax is clear and easy-to-understand for any newbie or inexperienced designer. In fact, it’s so simple that you could style your CSS just within a few hours of learning it. Even though, your site might look good in browsers like Safari and others, but what if your site doesn’t work in IE, or behave in a different manner as you’ve expected. Well, then it is recommended that you should consider the above discussed CSS3 trips and tricks.

在CSS3中工作时,由于其语法的原​​因,您遇到障碍的可能性较小。 对于任何新手或经验不足的设计师来说,语法都是清晰易懂的。 实际上,它非常简单,您可以在学习CSS的几个小时内就可以设置CSS样式。 即使您的网站在Safari等浏览器中看起来可能不错,但是如果您的网站无法在IE中运行,或者行为方式与您期望的不同,该怎么办。 好了,那么建议您考虑上面讨论CSS3之旅和技巧。

Author Bio: Being a well known PSD to WordPress theme conversion service provider across the globe. Mike is treated as wordpress junkie who shares valuable content on markup conversion and web design aspects.

作者简介:作为全球知名的PSD到WordPress主题转换服务提供商。 Mike被视为Wordpress迷,他在标记转换和网页设计方面分享了宝贵的内容。

翻译自: https://www.journaldev.com/6620/css3-tips-tricks-that-you-might-have-missed

css3常用技巧

css3常用技巧_您可能错过的5个CSS3技巧和窍门相关推荐

  1. python工程技巧_重点来了!掌握这些Python技巧,将给你节省大量时间

    希望你们可以将这些技巧运用到项目中.尽管没有运行时的速度或性能优势,但是与从零开始实施此逻辑相比,这将为你节省大量时间.因此,言归正传,让我们来看这三点吧: 1.拉姆达函数(Lambda Functi ...

  2. 图像标注技巧_保护互联网上图像的一个简单技巧

    图像标注技巧 补习 (TUTORIAL) Have you ever worried about sharing your images on the Internet? Anytime you up ...

  3. python怎么学比较有技巧_学python必须知道的30个技巧

    收集这些有用的捷径技巧 1. 原地进行交换两个数字 我们对赋值的右侧进行一个新的元组,左侧解析(unpack)那个(未被引用的)元组到变量 和 赋值完成时,新的元组变成了未被引用状态并且被标记没用处, ...

  4. idrmyimage 技巧_王者荣耀公孙离2000场-心得技巧,教你究极进阶!

    不喜勿喷,干货技巧,文章较长,献给真心喜欢阿离的进阶玩家,有兴趣的朋友可以耐心看完. 一.阿离技能特性小技巧: 1.卡时间减CD: 特性: 阿离被动一次标记爆炸可以减少技能1秒CD 技巧: 放单个技能 ...

  5. idea调试debug技巧_被我用烂的DEBUG调试技巧,专治各种搜索不到的问题

    摘要 在开发过程中,遇到问题,我们经常会使用搜索引擎来查找问题的解决方案,然后予以解决.但是有些问题一时半会搜索不到解决方案,需要自己去解决.这里分享下我解决这些问题使用的调试技巧,给大家一个解决问题 ...

  6. java 注解应用技巧_改善Java应用程序性能的快速技巧

    java 注解应用技巧 曾经遇到过性能问题吗? 我也是. 如果我的经理再喊一次" faaaaster",我一生都会有听力障碍. 顺便说一句,我能听到所有噪音中的德语发音吗? ;-) ...

  7. 采访拍摄镜头技巧_采访开放文化公司的6个技巧

    采访拍摄镜头技巧 在过去的几年中,我一直在一个开放的组织和工作大师的未来下学习. 而且,我想起的时间长于我所能记住的时间,即业务应该以不同的方式运作-真正以员工可以创新的速度前进,而不是站在任职时间最 ...

  8. 车内看车头正不正技巧_一看就会的倒车入库技巧!比驾校教的要简单,新手必看_搜狐汽车...

    在现在这个社会中,汽车已经走向了千家万户,基本上每个家庭都会有自己的一辆私家车.由于私家车的增多,路上的车况复杂多样,以及停车难的问题越发增多.开车的人每天都要面临停车难题,特别是新手司机,每天在路上 ...

  9. python3 爬虫技巧_用 python 爬虫抓站的一些技巧总结

    学用python也有3个多月了,用得最多的还是各类爬虫脚本:写过抓代理本机验证的脚本,写过在discuz论坛中自动登录自动发贴的脚本,写过自动收邮件的脚本,写过简单的验证码识别的脚本,本来想写goog ...

最新文章

  1. JW Player使用简介
  2. SQLSERVER 2008 R2 事务日志已满
  3. spring boot validated的使用
  4. 刚体运动中变换矩阵的逆
  5. ConcurrentHashMap 解读
  6. python如何导入numpy简书_如何使用python3.x成功导入numpy?
  7. OO第一单元总结——多项式求导
  8. 如何利用大数据技术构建用户画像
  9. jQuery鼠标悬停文字渐隐渐现动画效果
  10. 基于大数据的软件智能化开发方法与环境
  11. linux添加windows隐藏属性,解决文件夹隐藏属性无法取消的办法
  12. 清除微信或者企业微信的缓存或cookie
  13. 从新品抽奖小程序思考微信工具型小程序的发展
  14. Hark的数据结构与算法练习之桶排序
  15. 中英文在线翻译的方法
  16. ECharts地图,自定义map地图显示不同图标点,点击标点显示不同弹框
  17. 拍卖商城系统源码下载 拍卖商城系统平台开发
  18. matlab车牌识别的外文文献翻译,汽车车牌识别系统(带外文翻译).doc
  19. 【今日第17个世界肾脏日】肾癌/肾病治疗最新研究进展(2022年3月)
  20. 图书购物商城 图书后台管理系统

热门文章

  1. ContentPresenter元素
  2. 采样干扰十大滤波算法程序大全
  3. [转载] python staticmethod有什么意义_Python 中的 classmethod 和 staticmethod 有什么具体用途
  4. [转载] 使用python完成冒泡排序_使用python实现-冒泡排序
  5. [转载] python-TypeError: Object of type ‘Decimal‘ is not JSON serializable 报错
  6. [转载] python字典查询功能_Python中的字典功能
  7. Description Resource Path LocationType Java compiler level does not match the version of the instal
  8. 捷信达会员管理系统SQL语句相关
  9. 获取类路径的方法之一
  10. MYSQL:RELPACE用法