css的排版方法
2015-08-26 12:07
603 查看
在今天的设计中,排版常常被忽视,特别是被网页设计师忽视。这真是件遗憾的事情因为CSS可以做很多事情来控制我们的排版。也就是说,我们被局限于某些“网络安全”排版,但是我们不应该限制我们自己的创造性。本文整理了一些用于在网页上排版的CSS技巧。
预览
文字大小为1.2em.
文字大小为12px.
文字大小为10pt.
PS:关于font-size,推荐一下码头写的《http://www.css88.com/archives/821》
预览
font-weight设置为normal
font-weight设置为bold
font-weight设置为bolder
font-weight设置为lighter
预览
Capitalizes the first letter in every word
Allows your html to be lower case the converts it all to uppercase characters
ALLOWS YOUR HTML TO BE UPPERCASE THEN CONVERTS IT TO LOWERCASE, THIS WAS TYPED IN ALLCAPS
inherits the text-transform property from its parent element
预览
text-decoration设置为none
text-decoration设置为underline
text-decoration设置为overline
text-decoration设置为line-through
text-decoration设置为blink (只有Firefox 和Opera 支持)
预览
Font Variant 设置为 normal
Font Variant 设置为 small-caps
Font variant 设置为 inherit
预览
Letter spacing 设置为 normal
Letter spacing 设置为 2px
Letter spacing设置为 inherit
请注意上面的缩写的书写顺序。另外,如果这里不设置line-height,元素的line-height将会被设置为默认的1,而不会从父级元素或body元素继承。使用缩写的时候,font-size和font-family是必须的,其它几项可根据情况不写。
比如如果你的文字大小是12px,用30乘以它,也就是360px,这样每行大约可以呈现65个英文字符。
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
比如,如果你的文字大小是12px,加上6px就是你的行高,也就是18px。
specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
PS:关于line-height的设置,推荐一下码头写的《line-height的继承问题》
unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only
five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only
five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
示例代码
前端观察 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
这是处理文字的最大的功能,但是随之而来的是它的负面效果。由于版权问题,只有少数的字体“被允许”使用。这些字体也就是CSS3安全就在这里里面提到的。当然,对于中文字体来说,除了版权问题,还有网速的问题,一般中文字体动辄几MB的大小,字体文件下载到浏览器就要几分钟,这对于用户来说是不划算的。
PS:关于页面的嵌入字体,推荐阅读《如何在网页设计中使用个性化字体》
示例标题
示例标题2
示例标题3
PS:呃,其实前端观察的文章标题和章节的二级标题都用了text-shadow,而且还是用了更漂亮的RGBa颜色。关于CSS阴影,强烈推荐阅读《CSS阴影详解》
@ThreeStyles
Font属性
CSS提供了font属性,它允许我们在我们的页面中调整文字。这是一系列的关于语法和如何使用CSS调整文字的概述。Font-size
使用font-size可以修改你的文字的大小。font-size: 1.2em; font-size: 12px; font-size: 10pt;
预览
文字大小为1.2em.
文字大小为12px.
文字大小为10pt.
PS:关于font-size,推荐一下码头写的《http://www.css88.com/archives/821》
Font-weight
该属性用来改变你的文字的粗细(比如bold, bolder)font-weight: normal; font-weight: bold; font-weight: bolder; font-weight: lighter;
预览
font-weight设置为normal
font-weight设置为bold
font-weight设置为bolder
font-weight设置为lighter
font-weight属性还可以使用100,200,300,400,500,600,700,800,900等数字值,数字越大,文字越粗。
400等效于
normal,
700等效于
bold。
Text-transform
text-transform属性允许你应用
uppercase(大写),
lowercase(小写), 以及
capitalize(首字母大写)等效果到你的文字。当然,该属性不能用于中文。
text-transform: capitalize; text-transform: uppercase; text-transform: lowercase; text-transform: inherit;
预览
Capitalizes the first letter in every word
Allows your html to be lower case the converts it all to uppercase characters
ALLOWS YOUR HTML TO BE UPPERCASE THEN CONVERTS IT TO LOWERCASE, THIS WAS TYPED IN ALLCAPS
inherits the text-transform property from its parent element
Text-decoration
text-decoration属性允许你使用一些文字修饰,比如下划线(
underline)、上划线(
overline)、删除线(
line-through)以及文字闪动(
blink)。
text-decoration: none; text-decoration: underline; text-decoration: overline; text-decoration: line-through; text-decoration: blink;
预览
text-decoration设置为none
text-decoration设置为underline
text-decoration设置为overline
text-decoration设置为line-through
text-decoration设置为blink (只有Firefox 和Opera 支持)
Font-Variant
font-variant属性允许你制作小型大写字母效果,也就是将小写字母变成大写并减小字体型号font-variant: normal; font-variant: small-caps; font-variant: inherit;
预览
Font Variant 设置为 normal
Font Variant 设置为 small-caps
Font variant 设置为 inherit
Letter-Spacing 和 word-spacing
这两个属性都用来添加他们对应的元素中的空白。letter-spacing添加字母之间的空白,而word-spacing添加每个单词之间的空白。请注意,word-spacing对中文无效。letter-spacing: normal; letter-spacing: 2px; letter-spacing: inherit;
预览
Letter spacing 设置为 normal
Letter spacing 设置为 2px
Letter spacing设置为 inherit
font缩写
上面的font属性可以缩写,这样可以大大的提高你的css的效率。font:font-style font-variant font-weight font-size[/line-height] font-family
请注意上面的缩写的书写顺序。另外,如果这里不设置line-height,元素的line-height将会被设置为默认的1,而不会从父级元素或body元素继承。使用缩写的时候,font-size和font-family是必须的,其它几项可根据情况不写。
制作有吸引力的段落
对于更有吸引力的段落排版,可以采用Robert Bringhurst的方法,它约定:用你的文字大小乘以30就可以得到段落的宽度。比如如果你的文字大小是12px,用30乘以它,也就是360px,这样每行大约可以呈现65个英文字符。
不正确的段落大小:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimenbook. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
正确的段落大小
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimenbook. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
Line-height示例
行高用来限定每行文字之间的空白大小。一个经验之谈就是让行高比你的字体大6-7px。比如,如果你的文字大小是12px,加上6px就是你的行高,也就是18px。
不正确的Line-Height
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a typespecimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
正确的Line-Height
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It hassurvived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
PS:关于line-height的设置,推荐一下码头写的《line-height的继承问题》
清晰的强调文字
下划线应该只用于文字链接,而斜体是一个更清晰的可选方案.不正确的例子
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when anunknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only
five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
正确的例子
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when anunknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only
five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
first-letter与first-line
顾名思义,first-letter就是第一个字母,
first-line是第一行文字,它们是少有的被所有主流浏览器支持的CSS 2.1 伪元素,你可以为它们定义任意样式。
示例代码
#demo6{ width:400px;} #demo6:first-letter{ font-size:32px;color:green} #demo6:first-line{color:red;}
前端观察 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
前瞻 – CSS3
已经有一部分很棒的CSS3特性可以用到你的设计中了。当然这些中的一部分新属性还不能用于IE,但是你或许了解这对IE来说是常事儿,所以你不妨试试。@Font-face
@font-face允许你上次一个字体文件到你的网站服务器并将其引入到你的外部CSS文件中,然后就可以将它应用到你的网站的任何文字上。
这是处理文字的最大的功能,但是随之而来的是它的负面效果。由于版权问题,只有少数的字体“被允许”使用。这些字体也就是CSS3安全就在这里里面提到的。当然,对于中文字体来说,除了版权问题,还有网速的问题,一般中文字体动辄几MB的大小,字体文件下载到浏览器就要几分钟,这对于用户来说是不划算的。
使用@font-face
在这个例子中我在我的网站的根目录下放了一个font文件夹,然后将需要用到的字体放入该文件夹。你首先需要声明@font-face 属性以导入你的字体文件,然后使用该字体名称来控制其它元素的字体。/* 声明字体 */ @font-face { src:(font/diavlo.otf) } /* 将改字体应用到一个元素 */ h1 {font-family: diavlo, Arial; }
PS:关于页面的嵌入字体,推荐阅读《如何在网页设计中使用个性化字体》
Text-Shadow
text-shadow属性赶走了用Photoshop为某些元素制作下拉阴影的需求,并给你提供动态的阴影控制。当然,该属性IE并不支持。
示例标题
p { font-size: 2em; font-weight: bold; color: #777; text-shadow: 1px 1px 1px #222; }
示例标题2
p {text-shadow: 2px 2px 2px #222;}
示例标题3
p {text-shadow: 1px 1px 5px #FFF;}
PS:呃,其实前端观察的文章标题和章节的二级标题都用了text-shadow,而且还是用了更漂亮的RGBa颜色。关于CSS阴影,强烈推荐阅读《CSS阴影详解》
挑战
本文中提到的这些技术都只是一个入门指南。试着采用并实现你喜欢的技术到你的设计中。排版可能是一个网站中最重要的部分,请不要无视它。关于原作者
Shane Jeffers是Three Styles的创办者和作者。他对设计趋势和教程有独特的喜好。你可以通过这个联系页面和他联系到他或者在twitter上关注他@ThreeStyles
相关文章推荐
- django css样式,图片路径问题解决方案
- 自定义 CheckBox样式
- div+css实现仿淘宝的产品分类菜单效果代码
- table布局与DIV+CSS布局的区别
- css笔记
- div+css实现仿猪八戒首页导航菜单效果
- css垂直居中那点事
- CSS学习笔记——响应式布局
- css min-width与max-width的使用
- HTML+CSS笔记
- PHPExcel样式控制
- CSS中display和visibility隐藏元素的区别
- html引入css文件的名字大小写问题
- 关于HTML,css3自适应屏幕,自适应宽度
- CSS浏览器兼容性问题集()两
- CSS代码段
- 慢慢说CSS第三天
- 15-07-27 HTML-样式-格式与布局
- CSS中的居中:完全指导
- CSS学习------之简单图片切换