html+CSS+js部分基础运用17

  1. 在图书列表中,为书名“零基础学JavaScript”和“HTML5+CSS3精彩编程200例”添加颜色。(请用class或style属性实现),效果如下图1所示:

图1 图书列表

  1. Class和style的综合应用。(1)应用class的对象、数组语法;(2)应用style的对象、数组语法.  

           图2 class和style的综合应用

代码可以截图或者复制黏贴放置在“调试过程及实验结果”中

  1. 补全代码,页面效果如下图3所示:

图3 输出古诗

  • 1. 在图书列表中,为书名“零基础学JavaScript”和“HTML5+CSS3精彩编程200例”添加颜色。(请用class或style属性实现)

  • 2. Class和style的综合应用。(1)应用class的对象、数组语法;(2)应用style的对象、数组语法

3. 补全代码,页面效果如下图3所示

  • 1. 在图书列表中,为书名“零基础学JavaScript”和“HTML5+CSS3精彩编程200例”添加颜色。(请用class或style属性实现)

  • 2. Class和style的综合应用。(1)应用class的对象、数组语法;(2)应用style的对象、数组语法

3. 补全代码,页面效果如下图3所示

8.1

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>为指定书名添加颜色</title>

<style>

.item{

width:350px;

height:100px;

line-height:100px;

border-bottom:1px solid #999999;}

.item img{

width:100px;

float:left}

.active{

height:100px;

line-height:100px;

color:#FF0000

}

</style>

<script src="vue.js"></script>

</head>

<body>

<div id="example">

    <div>

          <div class="item" v-for="book in books">

              <img v-bind:src="book.image">

              <span v-bind:class="{active : book.active}">{{book.bookname}}</span>

          </div>

    </div>

</div>

<script type="text/javascript">

var vm = new Vue({

    el:'#example',

    data:{

        books : [{//定义图书信息数组

            bookname : '零基础学JavaScript',

            image : 'images/javascript.png',

            active : true

        },{

            bookname : '零基础学HTML5+CSS3',

            image : 'images/htmlcss.png',

            active : false

        },{

            bookname : 'JavaScript精彩编程200',

            image : 'images/javascript200.png',

            active : false

        },{

            bookname : 'HTML5+CSS3精彩编程200',

            image : 'images/htmlcss200.png',

            active : true

        }]

    }

})

</script>

</body>

</html>



 

8.2

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>模拟古诗垂直显示文本</title>

<script src="vue.js"></script>

</head>

<body>

<div id="example">

    <!--

        1baseStyle设置背景色为lightblue,

        2fontStyle设置字体为36px,颜色为green,文本水平居中,字体类型为华文楷体

        3styleRadius设置边框样式1px solid #CCCCCC,文本垂直排列,设置边框阴影

    -->

    <div v-bind:style="[baseStyle, fontStyle, styleRadius]">

        <h4>枫桥夜泊</h4>

        <p>

            月落乌啼霜满天,<br>江枫渔火对愁眠。<br>姑苏城外寒山寺,<br>夜半钟声到客船。

        </p>

    </div>

</div>

<script type="text/javascript">

var vm = new Vue({

    el:'#example',

    data:{

        bgcolor : 'lightblue',

        family : "华文楷体",

        fontSize : 36,

        color : 'green',

        align : 'center',

        border : '1px solid #CCCCCC',

        mode : 'vertical-rl',//垂直方向自右而左的书写方式

       

    },

    computed: {

        baseStyle: function () {//基本样式

            return{

                'background-color':this.bgcolor,

            }

        },

        fontStyle: function(){//字体样式

            return{

                fontSize:this.fontSize+'px',

                color:this.color,

                'text-align':this.align,

                'font-family':this.family,

            }

        },

        styleRadius: function () {

            return {

                border:this.border,

                'writing-mode':this.mode,

               

            }

        }

    }

})

</script>

</body>

</html>



 

8.3

<!-- vue-3-6.html -->

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <title>classstyle绑定综合应用实战</title>

        <script src="vue.js"></script>

        <style type="text/css">

            .redP {color: red;font-size: 28px;font-weight: bold;}

            .class-a {color: green;font-size: 36px;font-weight: bolder;}

            .class-b {border: 1px dashed #0033CC;}

            .active {color: blue;text-decoration: underline;}

        </style>

    </head>

    <body>

        <div id="vue36">

            <p v-bind:class="myClass">1.1 普通变量:Vue应用前景宽广!</p>

              <!-- 1.2 使用非内联的形式:classObject为一个对象,使用.class-a".class-b样式 -->

            <p :class="classObject">1.2 对象-非内联:Vue应用前景宽广!</p>

             <!-- 1.3 使用内联的形式:渲染.active样式 -->

            <div v-bind:class="{active: isActive }">1.3 对象-内联:Vue应用前景宽广!</div>

            <!-- 1.4 使用计算属性,渲染.class-a".class-b样式 -->

            <div v-bind:class="showClass">1.4 对象-计算属性:Vue应用前景宽广!</div>

            <div v-bind:class="[classA, classB]">1.5 数组:Vue非常好学!</div>          

            <div v-bind:style="{color:activeColor,fontSize:fontSize+'px'}">2.1 对象-内联:绑定style</div>

            <!-- 2.2 使用对象-非内联形式:通过styleObject对象实现字体大小为32px,边框为2px蓝色实线2px solid #0033CC -->

            <div :style="styleObject">2.2 对象-非内联:style对象</div>

            <div v-bind:style="[styleObjectA, styleObjectB]">2.3 数组:style数组</div>

            <!-- 2.4 使用计算属性,让2.4文本的colorbluefontSize32px -->

            <div v-bind:style="showStyle">2.4 对象-计算属性:Vue应用前景宽广!</div>

        </div>

        <script type="text/javascript">

            var myViewModel = new Vue({

                el: '#vue36',

                data: {

                    myClass: 'redP',

                   

                    isActive:true,

                    classA: 'class-a',

                    classB: 'class-b',

                    activeColor: '#99DD33',

                    fontSize: 36,

                    classObject:{

                        'class-a':true,

                        'class-b':true,

                    },

                    styleObject: {

                        border: '2px' + 'solid' + '#0033CC',

                        fontSize: 32 + 'px',

                    },

                    styleObjectA: {

                        color: 'blue',

                        fontSize: 36 + 'px'

                    },

                    styleObjectB: {

                        background: '#DFDFDF'

                    }

                },

                computed:{

                    showClass:function(){

                        return {

                            'class-a':true,

                            'class-b':true,

                        }

                    },

                    showStyle:function(){

                        return {

                            color:'blue',

                            fontSize:'32px',

                        }

                    }

                }

            })

        </script>

    </body>

</html>

  • 13
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-Initiation

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值