CSS Tables

border

border: border-width border-style border-color|initial|inherit;

border-width

border-width: medium|thin|thick|length|initial|inherit;

border-style

border-style:none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset|initial|inherit;

Table Borders

Example

 table, th, td {
border: 1px solid black;
}

border-collapse

  • Specify whether the table borders are collapsed into a single border or detached as in standard HTML.
border-collapse: separate|collapse|initial|inherit;

border-spacing

  • Specify the distance between the borders of adjacent cells (only for the "separated borders" model).
border-spacing: length|initial|inherit;

Example

 table {
border-collapse: separate;
border-spacing: 10px 50px;
}

Horizontal Alignment

text-align: left|right|center;

Vertical Alignment

vertical-align: top|bottom|middle;

Caption-side

  • Specify the placement of a table caption.
caption-side: top|bottom|initial|inherit;

Table-layout

  • Specify the table layout algorithm to be used for a table.
table-layout: auto|fixed|initial|inherit;
Value Description
auto Automatic table layout algorithm (this is default):

  • The column width is set by the widest unbreakable content in the cells
  • Can be slow, since it needs to read through all the content in the table, before determining the final layout
fixed Fixed table layout algorithm:

  • The horizontal layout only depends on the table's width and the width of the columns, not the contents of the cells
  • Allows a browser to lay out the table faster than the automatic table layout
  • The browser can begin to display the table once the first row has been received

Empty-cells

  • Specify whether or not to display borders and background on empty cells in a table (only for the "separated borders" model).
empty-cells: show|hide|initial|inherit;

Table Padding

  • Control the space between the border and the content in a table

Example

th, td {
padding: 15px;
text-align: left;
}

 

  • Use the :hover selector on <tr> to highlight table rows on mouse over
tr:hover {background-color: #f5f5f5}

Striped Tables

  • Use the nth-child() selector and add a background-color to all even (or odd) table rows

tr:nth-child(even) {background-color: #f2f2f2}

Responsive Table

  • display a horizontal scroll bar if the screen is too small to display the full content

Example

 <div style="overflow-x:auto;">

 <table>
... table content ...
</table> </div>

CSS Box Model

Explanation of the different parts:

  • Content - The content of the box, where text and images appear
  • Padding - Clears an area around the content. The padding is transparent
  • Border - A border that goes around the padding and content
  • Margin - Clears an area outside the border. The margin is transparent

Width and Height of an Element

Important:

  When you set the width and height properties of an element with CSS, you just set the width and height of the content area. To calculate the full size of an element, you must also add padding, borders and margins.

Example

 div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin:;
}

Total element width = width + left padding + right padding + left border + right border + left margin + right margin

CSS Outline

  • An outline is a line drawn around an element - outside the border.
  • The outline is NOT a part of an element's dimensions.
  • the element's total width and height is not affected by the width of the outline.

outline-style values

  • dotted - Defines a dotted outline
  • dashed - Defines a dashed outline
  • solid - Defines a solid outline
  • double - Defines a double outline
  • groove - Defines a 3D grooved outline. The effect depends on the outline-color value
  • ridge - Defines a 3D ridged outline. The effect depends on the outline-color value
  • inset - Defines a 3D inset outline. The effect depends on the outline-color value
  • outset - Defines a 3D outset outline. The effect depends on the outline-color value
  • none - Defines no outline
  • hidden - Defines a hidden outline

Example

 p {
border: 1px solid black;
outline-color: red;
} p.dotted {outline-style: dotted;}
p.dashed {outline-style: dashed;}
p.solid {outline-style: solid;}
p.double {outline-style: double;}
p.groove {outline-style: groove;}
p.ridge {outline-style: ridge;}
p.inset {outline-style: inset;}
p.outset {outline-style: outset;}

Result

A dotted outline.

A dashed outline.

A solid outline.

A double outline.

A groove outline. The effect depends on the outline-color value.

A ridge outline. The effect depends on the outline-color value.

An inset outline. The effect depends on the outline-color value.

An outset outline. The effect depends on the outline-color value.

Outline - Shorthand property

  • same to border

Example

 p {
border: 1px solid black;
outline: 5px dotted red;
}
  • Specify the space between an outline and the edge or border of an element
outline-offset: length|initial|inherit;

Example:

div {
border: 2px solid black;
outline: 2px solid red;
outline-offset: 15px;
}

CSS 笔记三(Tables/Box Model/Outline)的更多相关文章

  1. CSS 盒子模型(Box model)中的 padding 与 margin

    本文将讲述 HTML 和 CSS 的关键—盒子模型 (Box model) .理解 Box model 的关键便是 margin 和 padding 属性,而正确理解这两个属性也是学习用 CSS 布局 ...

  2. HTML和CSS的盒子模型(Box model)

    本文作为属性篇的最后一篇文章, 将讲述HTML和CSS的关键—盒子模型(Box model). 理解Box model的关键便是margin和padding属性, 而正确理解这两个属性也是学习用css ...

  3. 教你吃透CSS的盒子模型(Box Model)

    CSS 盒子模型(Box Model) 所有HTML元素可以看作盒子,在CSS中,"box model"这一术语是用来设计和布局时使用. CSS盒模型本质上是一个盒子,封装周围的H ...

  4. CSS盒子模型(Box Model)

    一.背景 作为CSS的重点,三大模块之一的盒子模型,这部分无论如何也要精通透彻.在任何一个网页当中,都有自己的布局方式,所谓网页布局方式就是如何把网页里面的文字.图片,很好的排版成美工设计的样式,这时 ...

  5. CSS盒模型(Box Model)

    阅读目录 1. 什么是CSS盒模型 2. IE盒模型和W3C盒模型 3. CSS3属性box-sizing 4. 关于盒模型的使用 在最初接触CSS的时候,对于CSS盒模型的不了解,撞了很多次的南墙呀 ...

  6. CSS3与页面布局学习笔记(二)——盒子模型(Box Model)、边距折叠、内联与块标签、CSSReset

    一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...

  7. CSS魔法堂:重新认识Box Model、IFC、BFC和Collapsing margins

    前言   盒子模型作为CSS基础中的基础,曾一度以为掌握了IE和W3C标准下的块级盒子模型即可,但近日在学习行级盒子模型时发现原来当初是如此幼稚可笑.本文尝试全面叙述块级.行级盒子模型的特性.作为近日 ...

  8. css盒模型(Box Model)

    所有HTML元素可以看作盒子,在CSS中,"box model"这一术语是用来设计和布局时使用. CSS盒模型本质上是一个盒子,封装周围的HTML元素,它包括:边距,边框,填充,和 ...

  9. CSS Box Model(盒子模型)

    CSS Box Model(盒子模型) 一.简介 所有HTML元素可以看作盒子,在CSS中,"box model"这一术语是用来设计和布局时使用. CSS盒模型本质上是一个盒子,封 ...

随机推荐

  1. ListView的HeaderView和Footer

    HeaderView介绍 HeaderView用法 属性中添加 ListView中属性listHeader和overScrollHeader区别: android:overScrollHeader=& ...

  2. [LintCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. The number is guaranteed to be within the range fro ...

  3. 三种线程不安全现象描述(escaped state以及hidden mutable state)

    hidden mutable state和escaped state是两种线程不安全问题:两者原因不同,前者主要是由于类成员变量中含有其他对象的引用,而这个引用是immutable的:后者是成员方法的 ...

  4. bzoj4518: [Sdoi2016]征途--斜率DP

    题目大意:把一个数列分成m段,计算每段的和sum,求所有的sum的方差,使其最小. 由方差*m可以化简得ans=m*sigma(ki^2)-sum[n]^2 很容易得出f[i][j]=min{f[i- ...

  5. asl 和 lgpl的区别

    按照使用条件的不同,开源软件许可证可以分为三类(严苛程度递减) 1. 使用该开源软件的代码再散布(redistribute)时,源码也必须以相同许可证公开. 代表许可类型:GPL, AGPL 2. 使 ...

  6. 2016HUAS暑假集训训练2 L - Points on Cycle

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/L 这是一道很有意思的题,就是给定一个以原点为圆心的圆,然后给定 一个点  求最大三 ...

  7. 整数与IP地址间的转换

    描述 原理:ip地址的每段可以看成是一个0-255的整数,把每段拆分成一个二进制形式组合起来,然后把这个二进制数转变成一个长整数.举例:一个ip地址为10.0.3.193每段数字            ...

  8. poj2142-The Balance(扩展欧几里德算法)

    一,题意: 有两个类型的砝码,质量分别为a,b;现在要求称出质量为d的物品, 要用多少a砝码(x)和多少b砝码(y),使得(x+y)最小.(注意:砝码位置有左右之分). 二,思路: 1,砝码有左右位置 ...

  9. 算法与数据结构题目的 PHP 实现:栈和队列 由两个栈组成的队列

    思路:同样使用 PHP 的数组模拟栈.栈的特点是先进后出,队列的特点是先进先出,可以用第一个栈(StackPush)作为压入栈,压入数据的时候只往这个栈中压入数据,第二个栈作(StackPop)为弹出 ...

  10. 使用NPOI将TABLE内容导出到EXCEL

    项目中需要将页面中的table内容导出到EXCEL,在用了几种方法后发现NPO是最快&最好的 需要应用 NPOI.dll 还有个Ionic.Zip.dll不知道有用没,没去研究,两个DLL都放 ...