This repository was archived by the owner on May 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Dynamic CSS
Pascal edited this page Sep 3, 2017
·
4 revisions
Vue.js documentation: https://vuejs.org/v2/guide/class-and-style.html
https://github.com/oanstein/VueJS-Complete-Guide-Code/tree/master/01_dom_interaction/13_dynamic_css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<style>
.demo {
width: 100px;
height: 100px;
background-color: gray;
display: inline-block;
margin: 10px;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
</style>
<body>
<div id="app">
<div class="demo" @click="attachRed = !attachRed" :class="divClasses"></div>
<div class="demo" :class="{red: attachRed}"></div>
<div class="demo" :class="[color, {red: attachRed}]"></div>
<hr>
<input type="text" v-model="color">
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
el: '#app',
data: {
attachRed: false,
color: 'green'
},
computed: {
divClasses: function(){
return {
red: this.attachRed,
blue: !this.attachRed
}
}
}
});
</script>
</body>
</html>- 00 Home
-
01 DOM Interactions
- 01 Events and Methods
- 02 HTML Binding
- 03 Computed Props
- 04_conditional_and_lists
- 05_filters
- 06 Components
- 07_disable_rerendering
- 08_raw_html
- 09_events
- 10_two_way_binding
- 11_computed_counts
- 12_shorthand
- 13 Dynamic CSS
- 14_using_style
- Exercise 1
- Exercise 2
- Exercise 3
- Exercise 4
-
02 Conditionals and Lists
- 01_v_if
- 02 v-for
- Exercise
- 03_monster_slayer
-
04_vue_instance
- 01_instance_vue
- 02_vue_lifecycle_in_practice
- 05_vue_cli
- 06_components
- 07_component_assignment
- 08 Communication between Components
-
09_advanced_components
- Assignment_8
- advanced_components
- 10_Wonderful_quoute_project
-
11 Forms
- form_assignments
- form_input
-
12_directives
- Assignment_directives
- custom_directives
-
13_filters_and_mixins
- assignment_filters_and_mixins
- filters_and_mixins
- 14 Animations and Transitions
-
15_http
- vue-resource
-
16 Routing
- routes
-
17 Vuex
- State Management
- vuex_master
-
18 Final Project
- the_stock_trader_app
- Assignment_7
- VueImages
- vue-mindspace