使用CSS来显示XML
实现效果
学号 姓名 班级 课程 教师
表格背景设为绿色,单元格居中显示
学号部分,蓝色字体,16磅大小;
姓名部分红色字体,带有下划线,12磅大小
班级课程名,教师,绿色字体,12磅大小
XML代码:
1 <?xml version="1.0" encoding="UTF8"?> 2 <?xml-stylesheet type="text/css" href="student.css"?> 3 <students> 4 <student> 5 <sid>学号</sid> 6 <sname>姓名</sname> 7 <sclass>班级</sclass> 8 <scourse>课程</scourse> 9 <teacher>任课教师</teacher> 10 </student> 11 <student> 12 <sid>1215115001</sid> 13 <sname>果果</sname> 14 <sclass>软件设计</sclass> 15 <scourse>数据结构</scourse> 16 <teacher>王岷</teacher> 17 </student> 18 19 <student> 20 <sid>1215115001</sid> 21 <sname>明明</sname> 22 <sclass>数据库</sclass> 23 <scourse>算法分析</scourse> 24 <teacher>王博</teacher> 25 </student> 26 <student> 27 <sid>1215115001</sid> 28 <sname>贝贝</sname> 29 <sclass>游戏开发</sclass> 30 <scourse>数据库编程</scourse> 31 <teacher>陆路</teacher> 32 </student> 33 </students>
css代码:
1 students 2 { 3 border:1px solid; 4 color: #33FF66; 5 width:500px; 6 height:170px; 7 text-align:center; 8 vertical-align: middle; 9 position:middle; 10 } 11 student 12 { 13 background-color:#33FF66; 14 display:block; 15 margin:5px 5px 5px 5px ; 16 border:1px solid;//表格边框 17 width:500px; 18 19 } 20 sid 21 { 22 color:blue; 23 font-size:16pt; 24 display:inline; 25 line-height:30px;//表格高度 26 27 } 28 sname 29 { 30 color:red; 31 font-size:12pt; 32 text-decoration:underline; 33 display:inline; 34 line-height:30px; 35 36 } 37 sclass,scourse,teacher 38 { 39 40 color:green; 41 font-size:12pt; 42 display:inline; 43 line-height:30px; 44 }
参考链接:http://xml.jz123.cn/xml_display.asp.htm
http://www.divcss5.com/rumen/r119.shtml