การผสานรวม HTML, CSS และ JavaScript
ทำความเข้าใจว่าเทคโนโลยีเว็บมาตรฐานเป็นโครงสร้างหลักของส่วนติดต่อผู้ใช้ Electron ได้อย่างไร ทำให้คุณใช้ความเชี่ยวชาญด้านการพัฒนาเว็บที่มีอยู่ได้
การผสานรวม HTML, CSS และ JavaScript เป็นบทเรียน Electron Desktop App Development ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Electron Desktop App Development และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Electron Desktop App Development มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Web UI with HTML, CSS, JS
Welcome! In Electron, you build desktop app interfaces using the same technologies you'd use for a website: HTML, CSS, and JavaScript.
This means your existing web development skills are directly transferable. Let's see how!
Meet the Renderer Process
An Electron app has a Main Process and one or more Renderer Processes.
- The Main Process handles native OS interactions.
- The Renderer Process is essentially a Chromium web browser instance. It's where your HTML, CSS, and JavaScript run, forming your app's user interface.
Think of each Electron window as its own renderer process.
HTML for Structure & Content
HTML (HyperText Markup Language) is the backbone of any web page, including your Electron app's UI.
It defines the structure and content:
- Headings (
<h1>,<h2>) - Paragraphs (
<p>) - Buttons (
<button>)
It's like the blueprint for your app's layout.
Displaying HTML Content
Your Electron main process loads an HTML file into a renderer process (a new window). This HTML file becomes your app's initial view.
Here's how `main.js` loads a simple `index.html` file:
The `index.html` might contain:<h1>Hello Electron!</h1><p>My first desktop UI.</p>
const { app, BrowserWindow } = require('electron');
const path = require('path');
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true
}
});
// Load the index.html file
win.loadFile(path.join(__dirname, 'index.html'));
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});CSS for Styling Your UI
CSS (Cascading Style Sheets) is used to control the presentation of your HTML content. It dictates how your app looks.
With CSS, you can define:
- Colors and backgrounds
- Fonts and text sizes
- Layout (margins, padding, positioning)
It turns your HTML blueprint into a visually appealing interface.
Linking & Applying Styles
You link a CSS file to your HTML using a <link> tag in the <head> section of your `index.html`.
For example, to style the previous `h1` element:
Your `index.html` would include:<link rel="stylesheet" href="style.css">
And `style.css` could contain:h1 { color: #3366ff; text-align: center; }
const { app, BrowserWindow } = require('electron');
const path = require('path');
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true
}
});
win.loadFile(path.join(__dirname, 'index.html'));
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});JavaScript for Interactivity
JavaScript (JS) adds dynamic behavior and interactivity to your Electron app's UI.
It allows you to:
- Respond to user actions (clicks, key presses)
- Manipulate HTML content and CSS styles
- Fetch data from APIs
JS turns a static page into a dynamic, responsive application.
Implementing UI Logic with JS
You can embed JavaScript directly in your HTML using <script> tags or link external .js files.
Let's add a button and make it display an alert when clicked:
Your `index.html` would include:<button id="myButton">Click Me!</button><script>document.getElementById('myButton').addEventListener('click', () => { alert('Hello from Electron!'); });</script>
const { app, BrowserWindow } = require('electron');
const path = require('path');
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true
}
});
win.loadFile(path.join(__dirname, 'index.html'));
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});HTML, CSS, JS: A Unified Stack
Together, HTML, CSS, and JavaScript form a powerful and familiar stack for building Electron user interfaces.
- HTML provides the content and structure.
- CSS defines the visual presentation.
- JavaScript adds interactivity and dynamic behavior.
This allows web developers to leverage their existing knowledge to create robust desktop applications.
Web Tech Roles
Which of the following statements correctly describe the role of HTML, CSS, and JavaScript in an Electron renderer process?
Recap: Web UI Basics
Today, we learned that Electron uses familiar web technologies – HTML, CSS, and JavaScript – to build desktop application user interfaces.
- The renderer process is where these web technologies run.
- HTML structures the content.
- CSS styles the appearance.
- JavaScript adds dynamic behavior.
You now understand the fundamental building blocks of an Electron UI. Next, we'll explore how to integrate popular frontend frameworks.
คำถามที่พบบ่อย
บทเรียน “การผสานรวม HTML, CSS และ JavaScript” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การผสานรวม HTML, CSS และ JavaScript” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Electron Desktop App Development ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Electron Desktop App Development มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การผสานรวม HTML, CSS และ JavaScript”
ทำความเข้าใจว่าเทคโนโลยีเว็บมาตรฐานเป็นโครงสร้างหลักของส่วนติดต่อผู้ใช้ Electron ได้อย่างไร ทำให้คุณใช้ความเชี่ยวชาญด้านการพัฒนาเว็บที่มีอยู่ได้ คุณปฏิบัติ Electron Desktop App Development ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Electron Desktop App Development หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Electron Desktop App Development บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “การผสานรวม HTML, CSS และ JavaScript” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Electron Desktop App Development นี้ได้ไหม
ได้ บทเรียน Electron Desktop App Development ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การผสานรวม HTML, CSS และ JavaScript
- การใช้เฟรมเวิร์กฟรอนต์เอนด์
- การออกแบบเดสก์ท็อปแบบตอบสนอง
- การกำหนดธีมและการรองรับโหมดมืด