
正文
css样式的写法,编写css样式
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
css样式怎么写
css样式是HTML的一个补充,简单的css使用样式如下:
html
body
div id=div/div
/body
style type="text/css"
width:300px;//设置div的宽度300像素
height:500px;//设置div高度500像素
background-color:red;//设置div的背景颜色为红色
/style
/html
css代码位于style之间,详细的css代码解释见代码注释。
相关问答
Q1: css样式写法
html
head
style type="text/css"
.time span{
line-height: 80px;
vertical-align: middle;
font-weight: bold;
color: white;
background-color: grey;
font-size: 60px;
padding:6px;
}
span.sep {
background-color: white;
color: grey;
}
/style
/head
body
div class = "time"
span23/span
span class ="sep":/span
span30/span
span class ="sep":/span
span32/span
/div
/body
/html
Q2: 简单CSS样式表的写法
html
head
style type="text/css"
a.top:link {font-family: 宋体} /*链接字体*/
a.top:link {font-weight: normal;} /*设置链接文字中的字符粗细*/
a.top:link {font-size: 12} /*设置链接文字的大小*/
a.top:link {text-decoration: none;} /*设置链接文字没有下划线*/
a.top:hover {text-decoration: underline;} /*鼠标放在链接上时有下划线*/
a.top:link {color: #000000} /*设置链接文字的颜色*/
a.top:visited {color: #000000} /*访问过的链接*/
a.top:hover {color: #B50000} /*鼠标放在链接上字体的颜色*/
a.tj:link {font-family: 宋体}
a.tj:link {font-weight: normal;}
a.tj:link {font-size: 12}
a.tj:link {text-decoration: none;}
a.tj:hover {text-decoration: none;}
a.tj:link {color: #000000}
a.tj:visited {color: #0000ff}
a.tj:hover {background: #FFFFCC}
h1 {font-size:12px}
h1 {font-family: "宋体"}
h1 {font-weight: normal;}
h1 {color: #000000}
h2 {font-size:14px}
h2 {font-family: "宋体"}
h2 {font-weight: normal;}
h2 {color: #000000}
h3 {font-size:24px}
h3 {font-weight: 1;}
h3 {color: #000000}
body {
margin-top: 1px; /*上边距*/
margin-bottom: 1px; /*下边距*/
}
/style
meta http-equiv="Content-Type" content="text/html; charset=gb2312"/head
body
pMouse over the links to see them change layout./p
pba href="default.asp" target="_blank" class="top"电脑对怀孕其实没啥影响/a/b/p
pba href="default.asp" target="_blank" class="tj"电脑对怀孕其实没啥影响/a/b/p
h1电脑对怀孕其实没啥影响/h1
h2电脑对怀孕其实没啥影响/h2
h3电脑对怀孕其实没啥影响/h3
/body
/html
Q3: HTML样式CSS的三种写法
CSS是样式层叠表,有三种引入方式。下面,我们来看看HTML样式CSS的三种写法吧。
01
行内样式
CSS可以直接放到行内样式中引入即可,比如代码如下图:
p style="color: blue; background: red;"
hello world!
/p
02
嵌入式
还可以采用潜入方式引入CSS,就是把CSS写到style标签中,这种方式比较实用,如下图所示:
style type="text/css"
h1 {color: red;}
/style
h1hello world/h1
03
外部样式表
还有一种叫做外部样式,也就是把CSS写在另外一张页面上,然后再引用到指定页面就可以了,这种也很常见。
@import url(main.css);
Q4: 引用CSS的写法有几种?
目前有两种引用方式,一种是通过在head里面的link来引用,另外一种是直接通过import来引用,示例代码如下:
第一种:link引用
link rel="stylesheet" href="/css/mycss.css" /
第二种:@import引用
style type="text/css"
@import url(/css/mycss.css)
/style
link和import语法结构不同,前者link是html标签,只能放入html源代码中使用,后者可看作为css样式,作用是引入css样式功能。
import在html使用时候需要style type="text/css"标签,同时可以直接“@import url(CSS文件路径地址);”放入css文件或css代码里引入其它css文件。
本质上两者使用选择区别不大,但为了软件中编辑布局网页html代码,一般使用link较多,也推荐使用link。






