UI

增加了一些新的用户界面特性来调整元素尺寸,框尺寸和外边框。

在本章中,您将了解以下的用户界面属性:

  • resize
  • box-sizing
  • outline-offset

注意:Firefox、Chrome 以及 Safari 支持 resize 属性。Internet Explorer、Chrome、Safari 以及 Opera 支持 box-sizing 属性。Firefox 需要前缀 -moz-。所有主流浏览器都支持 outline-offset 属性,除了 Internet Explorer。

resize

resize 属性指定一个元素是否应该由用户去调整大小。可以使用 resize:bothresize:vertical 或者 resize:horizontal,用来分别设置元素是可以水平、垂直调整,垂直调整,水平调整。

例子

  1. .div-both {
  2. border: 1px solid green;
  3. margin-top: 20px;
  4. padding: 15px 30px;
  5. width: 250px;
  6. resize: both;
  7. overflow: auto;
  8. }
  9. .div-horizontal {
  10. border: 1px solid green;
  11. margin-top: 20px;
  12. padding: 15px 30px;
  13. width: 250px;
  14. resize: horizontal;
  15. overflow: auto;
  16. }
  17. .div-vertical {
  18. border: 1px solid green;
  19. margin-top: 20px;
  20. padding: 15px 30px;
  21. width: 250px;
  22. resize: vertical;
  23. overflow: auto;
  24. }

box-sizing

box-sizing 允许您以确切的方式定义适应某个区域的具体内容

例子

  1. .box-sizing {
  2. box-sizing: border-box;
  3. -moz-box-sizing: border-box; /* Firefox */
  4. width: 50%;
  5. border: 1em solid red;
  6. float: left;
  7. }

outline-offset

outline-offset 属性对轮廓进行偏移,并在超出边框边缘的位置绘制轮廓。

轮廓与边框有两点不同:

  • 轮廓不占用空间
  • 轮廓可能是非矩形

例子

  1. .outline-offset {
  2. width: 180px;
  3. height: 80px;
  4. border: 1px solid red;
  5. outline: 1px solid green;
  6. outline-offset: 20px;
  7. }

属性

属性 说明 CSS
appearance 允许您使一个元素的外观像一个标准的用户界面元素 3
box-sizing 允许你以适应区域而用某种方式定义某些元素 3
icon Provides the author the ability to style an element with an iconic equivalent 3
nav-down 指定在何处使用箭头向下导航键时进行导航 3
nav-index 指定一个元素的Tab的顺序 3
nav-left 指定在何处使用左侧的箭头导航键进行导航 3
nav-right 指定在何处使用右侧的箭头导航键进行导航 3
nav-up 指定在何处使用箭头向上导航键时进行导航 3
outline-offset 外轮廓修饰并绘制超出边框的边缘 3
resize 指定一个元素是否是由用户调整大小 3

源码

本文中所用例子源码参见https://github.com/waylau/css3-tutorialsamples 目录下的 userinterface.html