Skip to content

Commit 7705576

Browse files
committed
Improve inline style instructions
1 parent 468803f commit 7705576

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/content/2/en/part2e.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,12 @@ React also makes it possible to write styles directly in the code as so-called [
207207

208208
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.
209209

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:
211211

212212
```css
213213
{
214214
color: green;
215215
font-style: italic;
216-
font-size: 16px;
217216
}
218217
```
219218

@@ -222,32 +221,40 @@ But as a React inline-style object it would look like this:
222221
```js
223222
{
224223
color: 'green',
225-
fontStyle: 'italic',
226-
fontSize: 16
224+
fontStyle: 'italic'
227225
}
228226
```
229227

230228
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.
231229

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:
233231

234232
```js
235-
// highlight-start
236233
const Footer = () => {
237234
const footerStyle = {
238235
color: 'green',
239-
fontStyle: 'italic',
240-
fontSize: 16
236+
fontStyle: 'italic'
241237
}
242238

243239
return (
244240
<div style={footerStyle}>
245241
<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
244+
</p>
247245
</div>
248246
)
249247
}
250-
// highlight-end
248+
249+
export default Footer
250+
```
251+
252+
```js
253+
import { useState, useEffect } from 'react'
254+
import Footer from './components/Footer' // highlight-line
255+
import Note from './components/Note'
256+
import Notification from './components/Notification'
257+
import noteService from './services/notes'
251258

252259
const App = () => {
253260
// ...

src/content/2/fi/osa2e.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,12 @@ React mahdollistaa tyylien kirjoittamisen myös suoraan komponenttien koodin jou
207207

208208
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ä.
209209

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än ja kursivoidun fontin, määrittely ilmaistaan CSS-syntaksilla seuraavasti:
211211

212212
```css
213213
{
214214
color: green;
215215
font-style: italic;
216-
font-size: 16px;
217216
}
218217
```
219218

@@ -222,31 +221,41 @@ Vastaava tyyli kirjoitetaan Reactin inline-tyylin määrittelevänä oliona seur
222221
```js
223222
{
224223
color: 'green',
225-
fontStyle: 'italic',
226-
fontSize: 16
224+
fontStyle: 'italic'
227225
}
228226
```
229227

230228
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.
231229

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:
233231

234232
```js
235233
const Footer = () => {
236234
const footerStyle = {
237235
color: 'green',
238-
fontStyle: 'italic',
239-
fontSize: 16
236+
fontStyle: 'italic'
240237
}
241238

242239
return (
243240
<div style={footerStyle}>
244241
<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
244+
</p>
246245
</div>
247246
)
248247
}
249248

249+
export default Footer
250+
```
251+
252+
```js
253+
import { useState, useEffect } from 'react'
254+
import Footer from './components/Footer' // highlight-line
255+
import Note from './components/Note'
256+
import Notification from './components/Notification'
257+
import noteService from './services/notes'
258+
250259
const App = () => {
251260
// ...
252261

0 commit comments

Comments
 (0)