ในบทนี้ คุณจะได้เรียนรู้เกี่ยวกับคุณสมบัติอินเทอร์เฟซผู้ใช้ CSS ต่อไปนี้:
resize
outline-offset
ตัวเลขในตารางระบุเบราว์เซอร์เวอร์ชันแรกที่รองรับคุณสมบัตินี้โดยสมบูรณ์
Property | |||||
---|---|---|---|---|---|
resize | 4.0 | 79.0 | 5.0 | 4.0 | 15.0 |
outline-offset | 4.0 | 15.0 | 5.0 | 4.0 | 9.5 |
resize
คุณสมบัติระบุว่า (และอย่างไร) องค์ประกอบควรปรับขนาดได้โดยผู้ใช้
This div element is resizable by the user!
To resize: Click and drag the bottom right corner of this div element.
ตัวอย่างต่อไปนี้ให้ผู้ใช้ปรับขนาดความกว้างขององค์ประกอบ <div> เท่านั้น:
div
{
resize: horizontal;
overflow: auto;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: horizontal;
overflow: auto;
}
</style>
</head>
<body>
<h1>The resize Property</h1>
<div>
<p>Let the user resize only the width of this div element.</p>
<p>To resize: Click and drag the bottom right corner of this div element.</p>
</div>
</body>
</html>
ตัวอย่างต่อไปนี้ให้ผู้ใช้ปรับขนาดความสูงขององค์ประกอบ <div> เท่านั้น:
div
{
resize: vertical;
overflow: auto;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: vertical;
overflow: auto;
}
</style>
</head>
<body>
<h1>The resize Property</h1>
<div>
<p>Let the user resize only the height of this div element.</p>
<p>To resize: Click and drag the bottom right corner of this div element.</p>
</div>
</body>
</html>
ตัวอย่างต่อไปนี้ให้ผู้ใช้ปรับขนาดทั้งความสูงและความกว้างของ <div> องค์ประกอบ:
div
{
resize: both;
overflow: auto;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: both;
overflow: auto;
}
</style>
</head>
<body>
<h1>The resize Property</h1>
<div>
<p>Let the user resize both the height and the width of this div element.</p>
<p>To resize: Click and drag the bottom right corner of this div element.</p>
</div>
</body>
</html>
ในเบราว์เซอร์จำนวนมาก <textarea> สามารถปรับขนาดได้ตามค่าเริ่มต้น ที่นี่ เราได้ใช้คุณสมบัติการปรับขนาดเพื่อปิดการใช้งานการปรับขนาด:
textarea {
resize: none;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
textarea#test {
resize: none;
}
</style>
</head>
<body>
<h1>The resize Property</h1>
<p>In many browsers, textarea elements are resizable by default. In this example, we have used the resize property to disable the resizability:</p>
<textarea id="test">Textarea - Not resizable</textarea>
<br><br>
<textarea>Textarea - Resizable (default)</textarea>
</body>
</html>
outline-offset
คุณสมบัติเพิ่มช่องว่างระหว่างโครงร่างและขอบหรือเส้นขอบขององค์ประกอบ
หมายเหตุ: โครงร่างแตกต่างจากเส้นขอบ! โครงร่างนั้นต่างจากเส้นขอบ วาดนอกเส้นขอบขององค์ประกอบ และอาจทับซ้อนเนื้อหาอื่น อีกทั้งโครงร่างก็คือ ไม่ใช่ส่วนหนึ่งของมิติข้อมูลขององค์ประกอบ ความกว้างและความสูงรวมขององค์ประกอบ ไม่ได้รับผลกระทบจากความกว้างของโครงร่าง
ตัวอย่างต่อไปนี้ใช้คุณสมบัติ outline-offset
เพื่อเพิ่มช่องว่าง ระหว่างเส้นขอบกับโครงร่าง:
div.ex1 {
margin: 20px;
border:
1px solid black;
outline: 4px solid red;
outline-offset: 15px;
}
div.ex2 {
margin: 10px;
border: 1px solid black;
outline: 5px dashed blue;
outline-offset: 5px;
}
ลองด้วยตัวคุณเอง →
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
margin: 20px;
border: 1px solid black;
outline: 4px solid red;
outline-offset: 15px;
}
div.ex2 {
margin: 10px;
border: 1px solid black;
outline: 5px dashed blue;
outline-offset: 5px;
}
</style>
</head>
<body>
<h1>The outline-offset Property</h1>
<div class="ex1">This div has a 4 pixels solid red outline 15 pixels outside the border edge.</div>
<br>
<div class="ex2">This div has a 5 pixels dashed blue outline 5 pixels outside the border edge.</div>
</body>
</html>
ตารางต่อไปนี้แสดงรายการคุณสมบัติอินเทอร์เฟซผู้ใช้ทั้งหมด:
เพิ่มช่องว่างระหว่างโครงร่างและขอบหรือเส้นขอบขององค์ประกอบ
ระบุว่าองค์ประกอบสามารถปรับขนาดได้โดยผู้ใช้หรือไม่