当前位置:   article > 正文

web前端(3)_使用html的属性style,在属性内添加css样式,只影响当前元素

使用html的属性style,在属性内添加css样式,只影响当前元素

内联样式表

内联样式表就是使用HTML属性style,在style属性内添加CSS样式。内联样式是仅
影响一个元素的CSS声明,也就是被style属性包括着的元素。
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>杯弓蛇影</title>
  6. </head>
  7. <body>
  8. <h1 style="text-align:center;color:blue"> 杯弓蛇影 </h1>
  9. <p style="padding:20px;background:yellow">
  10. 有一天,乐广请他的朋友在家里大厅中喝酒。那个朋友在喝酒的时候,突然看见自己的酒杯里,
  11. 有一条小蛇的影子在晃动,他心里很厌恶,可还是把酒喝了下去。喝了之后,心里到底不自在,
  12. 放心不下。回到家中就生起病来。隔了几天,乐广听到那个朋友生病的消息,了解了他得病的
  13. 原因。乐广心里想:酒杯里绝对不会有蛇的!于是,他就跑到那天喝酒的地方去察看。原来,
  14. 在大厅墙上,挂有一把漆了彩色的弓。那把弓的影子,恰巧映落在那朋友放过酒杯的地方,乐
  15. 广就跑到那个朋友那里去,把这事解释给他听。这人明白了原因以后,病就立刻好了。
  16. 后来人们就用杯弓蛇影比喻疑神疑鬼,自相惊扰。
  17. </p>
  18. </body>
  19. </html>

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>if 条件语句</title>
  6. </head>
  7. <body>
  8. <script>
  9. var score = 78
  10. if (score>=90)
  11. {
  12. document.write("<b>成绩优秀</b>");
  13. }
  14. else if (score>=80 && score<90)
  15. {
  16. document.write("<b>成绩良好</b>");
  17. }
  18. else if (score>=60 && score<80)
  19. {
  20. document.write("<b>成绩及格</b>");
  21. }
  22. else
  23. {
  24. document.write("<b>成绩不及格</b>");
  25. }
  26. </script>
  27. </body>
  28. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>switch语句</title>
  6. </head>
  7. <body>
  8. <script>
  9. var d=new Date().getDay();
  10. switch (d)
  11. {
  12. case 0:
  13. x="今天是星期日";
  14. break;
  15. case 1:
  16. x="今天是星期一";
  17. break;
  18. case 2:
  19. x="今天是星期二";
  20. break;
  21. case 3:
  22. x="今天是星期三";
  23. break;
  24. case 4:
  25. x="今天是星期四";
  26. break;
  27. case 5:
  28. x="今天是星期五";
  29. break;
  30. case 6:
  31. x="今天是星期六";
  32. break;
  33. }
  34. document.write(x);
  35. </script>
  36. </body>
  37. </html>

 

 

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>for...in语句</title>
  6. </head>
  7. <body>
  8. <script>
  9. // 学生成绩信息
  10. var person={name:"andy",age:18,score:{chinese:100,english:90}};
  11. var txt = ''
  12. for (x in person) // x 为属性名
  13. {
  14. if (x == 'score') { // 分数内容是对象,需要再次遍历
  15. for (y in person['score']){
  16. txt = y+':'+ person['score'][y] + '<br>';
  17. document.write(txt);
  18. }
  19. }else{ // 其他信息直接输出
  20. txt = x+':'+ person[x] + '<br>';
  21. document.write(txt);
  22. }
  23. }
  24. </script>
  25. </body>
  26. </html>

 

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>函数参数</title>
  6. </head>
  7. <body>
  8. <div id="demo"></div>
  9. <script>
  10. function myFunction(a,b){
  11. return a*b;
  12. }
  13. document.getElementById("demo").innerHTML=myFunction(4,3);
  14. </script>
  15. </script>
  16. </body>
  17. </html>

 运行结果为12

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号