Skip to content

Commit 44fc945

Browse files
panietoarmiljan-aleksic
authored andcommitted
Class and Style section translation (#10)
1 parent efff5d1 commit 44fc945

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/v2/guide/class-and-style.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
---
2-
title: Class and Style Bindings
2+
title: V-bind en Clases y Estilos
33
type: guide
44
order: 6
55
---
66

7-
A common need for data binding is manipulating an element's class list and its inline styles. Since they are both attributes, we can use `v-bind` to handle them: we just need to calculate a final string with our expressions. However, meddling with string concatenation is annoying and error-prone. For this reason, Vue provides special enhancements when `v-bind` is used with `class` and `style`. In addition to strings, the expressions can also evaluate to objects or arrays.
7+
Una necesidad común para usar `v-bind` con los datos es manipular la lista de clases de un elemento, así como sus estilos en línea. Como ambos son atributos, podemos usar `v-bind` para controlarlos: sólo debemos calcular un string final con nuestras expresiones. Sin embargo, trabajar con concatenaciones de strings es molesto y propenso a errores. Por esta razón, Vue ofrece mejoras especiales cuando `v-bind` es usado junto con `class` and `style`. En adición a strings, las expresiones pueden también ser evaluadas a objetos o arrays.
88

9-
## Binding HTML Classes
9+
## V-bind en Clases HTML
1010

11-
### Object Syntax
11+
### Sintaxis de Objeto
1212

13-
We can pass an object to `v-bind:class` to dynamically toggle classes:
13+
Podemos pasar un objeto a `v-bind:class` para intercambiar dinámicamente las clases:
1414

1515
``` html
1616
<div v-bind:class="{ active: isActive }"></div>
1717
```
1818

19-
The above syntax means the presence of the `active` class will be determined by the [truthiness](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) of the data property `isActive`.
19+
La anterior sintaxis ilustra que la presencia de la clase `active` será determinada por el [thrutiness](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) de la propiedad `isActive`.
2020

21-
You can have multiple classes toggled by having more fields in the object. In addition, the `v-bind:class` directive can also co-exist with the plain `class` attribute. So given the following template:
21+
Puede intercambiar múltiples clases si tiene más campos en el objeto. Adicionalmente, la directiva `v-bind:class` puede coexistir con el atributo común `class`. De modo que en la siguiente plantilla:
2222

2323
``` html
2424
<div class="static"
2525
v-bind:class="{ active: isActive, 'text-danger': hasError }">
2626
</div>
2727
```
2828

29-
And the following data:
29+
Y los siguientes datos:
3030

3131
``` js
3232
data: {
@@ -35,15 +35,15 @@ data: {
3535
}
3636
```
3737

38-
It will render:
38+
Se va a renderizar:
3939

4040
``` html
4141
<div class="static active"></div>
4242
```
4343

44-
When `isActive` or `hasError` changes, the class list will be updated accordingly. For example, if `hasError` becomes `true`, the class list will become `"static active text-danger"`.
44+
Siempre que `isActive` o `hasError` cambie, la lista de clases será actualizada acordemente. Por ejemplo, si `hasError` toma el valor `true`, la lista de clases cambiará a `"static active text-danger".`
4545

46-
The bound object doesn't have to be inline:
46+
El objeto asignado a `v-bind` no necesariamente debe ser en líenea:
4747

4848
``` html
4949
<div v-bind:class="classObject"></div>
@@ -57,7 +57,7 @@ data: {
5757
}
5858
```
5959

60-
This will render the same result. We can also bind to a [computed property](computed.html) that returns an object. This is a common and powerful pattern:
60+
Esto mostrará el mismo resultado. También podemos usar `v-bind` con una [propiedad calculada](computed.html) que retorne un objeto. Esto es un patrón muy común y poderoso:
6161

6262
``` html
6363
<div v-bind:class="classObject"></div>
@@ -77,9 +77,9 @@ computed: {
7777
}
7878
```
7979

80-
### Array Syntax
80+
### Sintaxis de Array
8181

82-
We can pass an array to `v-bind:class` to apply a list of classes:
82+
Podemos pasar un array a `v-bind:class` para aplicar una lista de clases:
8383

8484
``` html
8585
<div v-bind:class="[activeClass, errorClass]">
@@ -91,69 +91,69 @@ data: {
9191
}
9292
```
9393

94-
Which will render:
94+
Lo cual renderizará:
9595

9696
``` html
9797
<div class="active text-danger"></div>
9898
```
9999

100-
If you would like to also toggle a class in the list conditionally, you can do it with a ternary expression:
100+
Si quisiera también intercambiar una clase en el listado de clases condicionalmente, lo puede hacer con una expresión ternaria:
101101

102102
``` html
103103
<div v-bind:class="[isActive ? activeClass : '', errorClass]">
104104
```
105105

106-
This will always apply `errorClass`, but will only apply `activeClass` when `isActive` is `true`.
106+
Esto siempre aplicará `errorClass`, pero solo aplicará `activeClass` cuando `isActive` tenga valor `true`.
107107

108-
However, this can be a bit verbose if you have multiple conditional classes. That's why it's also possible to use the object syntax inside array syntax:
108+
Sin embargo, esto puede ser un poco extenso si tiene múltiples clases condicionales. Por esto también es posible usar la sintaxis de objeto dentro de la sintaxis de array:
109109

110110
``` html
111111
<div v-bind:class="[{ active: isActive }, errorClass]">
112112
```
113113

114-
### With Components
114+
### Con Componentes
115115

116-
> This section assumes knowledge of [Vue Components](components.html). Feel free to skip it and come back later.
116+
> Esta sección asume conocimientos previos de [Componentes Vue](components.html). Sé libre de saltar ésta sección y regresar más adelante.
117117
118-
When you use the `class` attribute on a custom component, those classes will be added to the component's root element. Existing classes on this element will not be overwritten.
118+
Cuando usa el atributo `class` en un componente personalizado, aquellos cambios serán adicionados al elemento raíz del componente. Las clases existentes de dicho elemento no serán sobreescritas.
119119

120-
For example, if you declare this component:
120+
Por ejemplo, si declara este componente:
121121

122122
``` js
123123
Vue.component('my-component', {
124124
template: '<p class="foo bar">Hi</p>'
125125
})
126126
```
127127

128-
Then add some classes when using it:
128+
Luego agrega algunas clases mientras lo usa:
129129

130130
``` html
131131
<my-component class="baz boo"></my-component>
132132
```
133133

134-
The rendered HTML will be:
134+
El HTML renderizado será:
135135

136136
``` html
137137
<p class="foo bar baz boo">Hi</p>
138138
```
139139

140-
The same is true for class bindings:
140+
Lo mismo aplica para uso de `v-bind` en clases:
141141

142142
``` html
143143
<my-component v-bind:class="{ active: isActive }"></my-component>
144144
```
145145

146-
When `isActive` is truthy, the rendered HTML will be:
146+
Cuando `isActive` es verdadero, el HTML renderizado será:
147147

148148
``` html
149149
<p class="foo bar active"></p>
150150
```
151151

152-
## Binding Inline Styles
152+
## V-bind en estilos en línea
153153

154-
### Object Syntax
154+
### Sintaxis de objeto
155155

156-
The object syntax for `v-bind:style` is pretty straightforward - it looks almost like CSS, except it's a JavaScript object. You can use either camelCase or kebab-case for the CSS property names:
156+
La sintaxis de objetos para `v-bind:style` es bastante sencillo - casi parece CSS, excepto que es un objeto javascript. Puede usar camelCase o kebab-case para los nombres de propiedades:
157157

158158
``` html
159159
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
@@ -165,7 +165,7 @@ data: {
165165
}
166166
```
167167

168-
It is often a good idea to bind to a style object directly so that the template is cleaner:
168+
Es a menudo una buena idea usar `v-bind` con un objeto de estilos directamente para que la plantilla sea más limpia:
169169

170170
``` html
171171
<div v-bind:style="styleObject"></div>
@@ -179,16 +179,16 @@ data: {
179179
}
180180
```
181181

182-
Again, the object syntax is often used in conjunction with computed properties that return objects.
182+
De nuevo, la sintaxis de objeto es comúnmente usado junto con propiedades calculadas que retornan objetos.
183183

184-
### Array Syntax
184+
### Sintaxis de Array
185185

186-
The array syntax for `v-bind:style` allows you to apply multiple style objects to the same element:
186+
La sintaxis de array para `v-bind:style` le permite aplicar múltiples objetos de estilo al mismo elemento:
187187

188188
``` html
189189
<div v-bind:style="[baseStyles, overridingStyles]">
190190
```
191191

192-
### Auto-prefixing
192+
### Prefijos automáticos
193193

194-
When you use a CSS property that requires vendor prefixes in `v-bind:style`, for example `transform`, Vue will automatically detect and add appropriate prefixes to the applied styles.
194+
Cuando usa una propiedad CSS que requiera prefijos de navegador en `v-bind:style`, por ejemplo `transform`, Vue automáticamente detectará y agregará los prefijos apropiados a los estilos aplicados.

0 commit comments

Comments
 (0)