Skip to content

Commit 7c0edb4

Browse files
committed
Update documentation
1 parent d9fb07b commit 7c0edb4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ For example:
233233

234234
In this example, the "hidden" class will only be applied when the value of the `foo` data attribute is `true`.
235235

236+
**`x-bind` for style attributes**
237+
238+
`x-bind` behaves a little differently when binding to the `style` attribute.
239+
240+
For styles, you pass in an object who's keys are style names, and values are either CSS property values (strings) or falsy. If the value is falsy the style will not be applied.
241+
242+
For example:
243+
`<div x-bind:class="{ display: foo && 'inline', fontSize: 20 + 'px' }"></div>`
244+
245+
In this example, the "display" style will only be applied when the value of the `foo` data attribute is `true`.
246+
247+
`style` bindings also support arrays and will merge/override rules.
248+
249+
For example:
250+
`<div style="display: inline" x-bind:style="['display: hidden; width: 200px;', 'height: 20px;']"></div>`
251+
252+
In this example, the "display" style will be set to "hidden", "width" will be "200px" and height will be "20px"
253+
236254
**`x-bind` for boolean attributes**
237255

238256
`x-bind` supports boolean attributes in the same way that value attributes, using a variable as the condition or any JavaScript expression that resolves to `true` or `false`.

0 commit comments

Comments
 (0)