You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/2/en/part2e.md
+17-10Lines changed: 17 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,13 +207,12 @@ React also makes it possible to write styles directly in the code as so-called [
207
207
208
208
The idea behind defining inline styles is extremely simple. Any React component or element can be provided with a set of CSS properties as a JavaScript object through the [style](https://react.dev/reference/react-dom/components/common#applying-css-styles) attribute.
209
209
210
-
CSS rules are defined slightly differently in JavaScript than in normal CSS files. Let's say that we wanted to give some element the color green and italic font that's 16 pixels in size. In CSS, it would look like this:
210
+
CSS rules are defined slightly differently in JavaScript than in normal CSS files. Let's say that we wanted to give some element the color green and italic font. In CSS, it would look like this:
211
211
212
212
```css
213
213
{
214
214
color: green;
215
215
font-style: italic;
216
-
font-size: 16px;
217
216
}
218
217
```
219
218
@@ -222,32 +221,40 @@ But as a React inline-style object it would look like this:
222
221
```js
223
222
{
224
223
color:'green',
225
-
fontStyle:'italic',
226
-
fontSize:16
224
+
fontStyle:'italic'
227
225
}
228
226
```
229
227
230
228
Every CSS property is defined as a separate property of the JavaScript object. Numeric values for pixels can be simply defined as integers. One of the major differences compared to regular CSS, is that hyphenated (kebab case) CSS properties are written in camelCase.
231
229
232
-
Next, we could add a "bottom block" to our application by creating a <i>Footer</i> component and defining the following inline styles for it:
230
+
Let's add a footer component, <i>Footer</i>, to our application and define inline styles for it. The component is defined in the file _components/Footer.jsx_ and used in the file _App.jsx_ as follows:
233
231
234
232
```js
235
-
// highlight-start
236
233
constFooter= () => {
237
234
constfooterStyle= {
238
235
color:'green',
239
-
fontStyle:'italic',
240
-
fontSize:16
236
+
fontStyle:'italic'
241
237
}
242
238
243
239
return (
244
240
<div style={footerStyle}>
245
241
<br />
246
-
<em>Note app, Department of Computer Science, University of Helsinki 2025</em>
242
+
<p>
243
+
Note app, Department of Computer Science, University of Helsinki 2025
Copy file name to clipboardExpand all lines: src/content/2/fi/osa2e.md
+17-8Lines changed: 17 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,13 +207,12 @@ React mahdollistaa tyylien kirjoittamisen myös suoraan komponenttien koodin jou
207
207
208
208
Periaate inline-tyylien määrittelyssä on erittäin yksinkertainen. Mihin tahansa React-komponenttiin tai elementtiin voi liittää attribuutin [style](https://react.dev/reference/react-dom/components/common#applying-css-styles), jolle annetaan arvoksi JavaScript-oliona määritelty joukko CSS-sääntöjä.
209
209
210
-
CSS-säännöt määritellään JavaScriptin avulla hieman eri tavalla kuin normaaleissa CSS-tiedostoissa. Jos haluamme asettaa jollekin elementille esimerkiksi vihreän, kursivoidun ja 16 pikselin korkuisen fontin, määrittely ilmaistaan CSS-syntaksilla seuraavasti:
210
+
CSS-säännöt määritellään JavaScriptin avulla hieman eri tavalla kuin normaaleissa CSS-tiedostoissa. Jos haluamme asettaa jollekin elementille esimerkiksi vihreänja kursivoidun fontin, määrittely ilmaistaan CSS-syntaksilla seuraavasti:
211
211
212
212
```css
213
213
{
214
214
color: green;
215
215
font-style: italic;
216
-
font-size: 16px;
217
216
}
218
217
```
219
218
@@ -222,31 +221,41 @@ Vastaava tyyli kirjoitetaan Reactin inline-tyylin määrittelevänä oliona seur
222
221
```js
223
222
{
224
223
color:'green',
225
-
fontStyle:'italic',
226
-
fontSize:16
224
+
fontStyle:'italic'
227
225
}
228
226
```
229
227
230
228
Jokainen CSS-sääntö on olion kenttä, joten ne erotetaan JavaScript-syntaksin mukaan pilkuilla. Pikseleinä ilmaistut numeroarvot voidaan määritellä kokonaislukuina. Merkittävin ero normaaliin CSS:ään on väliviivan sisältämien CSS-ominaisuuksien kirjoittaminen camelCase-muodossa.
231
229
232
-
Voimme nyt lisätä sovellukseemme alapalkin muodostavan komponentin <i>Footer</i> ja määritellä sille inline-tyylit seuraavasti:
230
+
Lisätään sovellukseemme alapalkin muodostava komponentti <i>Footer</i> ja määritellään sille inline-tyylit. Määritellään komponentti tiedostossa _components/Footer.jsx_ otetaan se käyttöön tiedostossa _App.jsx_ seuraavasti:
233
231
234
232
```js
235
233
constFooter= () => {
236
234
constfooterStyle= {
237
235
color:'green',
238
-
fontStyle:'italic',
239
-
fontSize:16
236
+
fontStyle:'italic'
240
237
}
241
238
242
239
return (
243
240
<div style={footerStyle}>
244
241
<br />
245
-
<em>Note app, Department of Computer Science, University of Helsinki 2025</em>
242
+
<p>
243
+
Note app, Department of Computer Science, University of Helsinki 2025
0 commit comments