💻
React - The Complete Guide (incl Hooks, React Rout
  • What you'll learn
  • Getting Started
    • Introduction
    • What is React
    • Learning Community
    • Components
    • Writing our First React Code
    • Why Should we Choose React
    • React Alternatives
    • SPA and MPA
      • Single Page Applications
      • Multi Page Applications
    • Course Outline
    • How to get the Most out of This Course
    • Useful Resources & Links
  • Two kinds of application
  • Hiều về let và const
  • Arrow Functions
  • Export và Import
  • Hiểu các tính năng cơ bản & Cú pháp
    • Module Introduction
    • The Build Workflow
    • Node.js Download
    • Using Create React App
    • Understanding the Folder Structure
    • Understanding Component Basics
    • Understanding JSX
    • JSX Restrictions
    • Creating a Functional Component
    • Components & JSX Cheat Sheet
    • Working with Components & Re-Using Them
    • Outputting Dynamic Content
    • Working with Props
    • Understanding the "children" Pro
    • Understanding & Using State
    • Props & State
    • Xử lý các sự kiện bằng các phương thức
    • Bạn có thể nghe những sự kiện nào?
    • Xử lý State
    • Đặt tên Function Components
    • Sử dụng useState() Hook cho xử lý State
    • Stateless vs Stateful Components
    • Truyền Method References giữa các Component
    • Liên kết hai chiều(Two-way Binding)
    • Thêm Styling với Stylesheets
    • Làm việc với Inline Styles
    • Tài nguyên & Liên kết hữu ích
Powered by GitBook
On this page

Was this helpful?

  1. Hiểu các tính năng cơ bản & Cú pháp

Làm việc với Inline Styles

Trong React, Inline Styles không được chỉ định dưới dạng chuỗi(string). Thay vào đó, chúng được chỉ định với một đối tượng(object) có key là phiên bản camelCase của tên kiểu và có giá trị là giá trị của kiểu, thường là một chuỗi:

const loveStyle = {
  color: 'white',
  backgroundImage: 'url(' + imgUrl + ')',
  WebkitTransition: 'all', // lưu ý viết hoa 'W' ở đây
  msTransition: 'all' // 'ms' là tiền tố nhà cung cấp chữ thường duy nhất
};

ReactDOM.render(<div style={loveStyle}>Hello World!</div>, mountNode);

Các khóa kiểu được camelCase để phù hợp với việc truy cập các thuộc tính trên các nút DOM từ JS (ví dụ: node.style.backgroundImage). Tiền tố nhà cung cấp bắt đầu bằng chữ in hoa. Đây là lý do tại sao WebkitTransition có chữ hoa "W".

PreviousThêm Styling với StylesheetsNextTài nguyên & Liên kết hữu ích

Last updated 4 years ago

Was this helpful?