0

why do some styles inside jsx (in case of a width) stop working, for example, the red color span seems broken and does not change to the width value to 100px, the green ones without jsx work correctly

<!DOCTYPE html>
<html>

<head>
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>

<body>

    <div id="root"></div>
    <div class="title test">df</div>
    <div class="title test">dfwertds4</div>
    <script type="text/babel">
        function App() {

            let arr = [
                { title: '12', text: 'text' },
                { title: '43', text: 'text' },
                { title: '23', text: 'text' },
                { title: '56w2345', text: 'text' },
                { title: '34234645436', text: 'text' },
                { title: '2344f', text: 'text' }
            ];
            return (
                <>
                            {arr.map((i, index) => {
                                return (
                                    <div className="item" key={i.title}>
                                        <span className="title" >
                                            {i.title}
                                        </span>
                                        <span>{i.text}</span>
                                    </div>
                                );
                            })}
                </>
            );
        }

        const root = ReactDOM.createRoot(document.getElementById('root'));
        root.render(
            <App />
        );
    </script>
    <style>
        .title {
            background: #e31937;
            border-radius: 4px;
            width: 100px;
            height: 20px;
        }

        .test {
            background: green;
        }
    </style>

</body>

</html>

Why is this happening? And why, for example, background works correctly both inside jsx and without jsx

Serio
  • 465
  • 4
  • 15

0 Answers0