Source

ภาพรวม

ส่วนประกอบและตัวเลือกสำหรับการจัดวางโปรเจ็กต์ Bootstrap ของคุณ รวมทั้งการห่อคอนเทนเนอร์ ระบบกริดอันทรงพลัง ออบเจ็กต์สื่อที่ยืดหยุ่น และคลาสยูทิลิตี้ที่ตอบสนอง

ตู้คอนเทนเนอร์

คอนเทนเนอร์เป็นองค์ประกอบเลย์เอาต์พื้นฐานที่สุดใน Bootstrap และจำเป็นเมื่อใช้ระบบกริดเริ่มต้นของเรา เลือกจากคอนเทนเนอร์ความกว้างคงที่ที่ตอบสนอง (หมายถึงการmax-widthเปลี่ยนแปลงที่จุดพักแต่ละจุด) หรือความกว้างของไหล (หมายความว่า100%กว้างตลอดเวลา)

แม้ว่าคอนเทนเนอร์จะซ้อนกันได้ แต่เลย์เอาต์ส่วนใหญ่ไม่ต้องการคอนเทนเนอร์ที่ซ้อนกัน

<div class="container">
  <!-- Content here -->
</div>

ใช้.container-fluidสำหรับคอนเทนเนอร์เต็มความกว้าง ขยายความกว้างทั้งหมดของวิวพอร์ต

<div class="container-fluid">
  ...
</div>

เบรกพอยต์ที่ตอบสนอง

เนื่องจาก Bootstrap ได้รับการพัฒนาให้เป็นมือถือก่อน เราจึงใช้การสืบค้นสื่อ จำนวนหนึ่ง เพื่อสร้างจุดสั่งหยุดที่สมเหตุสมผลสำหรับเลย์เอาต์และอินเทอร์เฟซของเรา เบรกพอยต์เหล่านี้ส่วนใหญ่อิงตามความกว้างของวิวพอร์ตขั้นต่ำ และทำให้เราสามารถขยายขนาดองค์ประกอบเมื่อวิวพอร์ตเปลี่ยนไป

Bootstrap ใช้ช่วงการสืบค้นสื่อหรือเบรกพอยต์ต่อไปนี้เป็นหลักในไฟล์ Sass ต้นทางของเราสำหรับเลย์เอาต์ ระบบกริด และส่วนประกอบของเรา

// Extra small devices (portrait phones, less than 576px)
// No media query for `xs` since this is the default in Bootstrap

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }

เนื่องจากเราเขียนซอร์สโค้ด CSS ใน Sass การสืบค้นสื่อทั้งหมดของเราจึงพร้อมใช้งานผ่าน Sass mixins:

// No media query necessary for xs breakpoint as it's effectively `@media (min-width: 0) { ... }`
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }

// Example: Hide starting at `min-width: 0`, and then show at the `sm` breakpoint
.custom-class {
  display: none;
}
@include media-breakpoint-up(sm) {
  .custom-class {
    display: block;
  }
}

บางครั้งเราใช้การสืบค้นสื่อที่ไปในทิศทางอื่น (ขนาดหน้าจอที่กำหนดหรือเล็กกว่า ):

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }

// Small devices (landscape phones, less than 768px)
@media (max-width: 767.98px) { ... }

// Medium devices (tablets, less than 992px)
@media (max-width: 991.98px) { ... }

// Large devices (desktops, less than 1200px)
@media (max-width: 1199.98px) { ... }

// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width

โปรดทราบว่าเนื่องจากเบราว์เซอร์ไม่สนับสนุนการสืบค้นบริบทแบบช่วงเราจึงหลีกเลี่ยงข้อจำกัดmin-และmax-คำนำหน้าและวิวพอร์ตที่มีความกว้างแบบเศษส่วน (ซึ่งสามารถเกิดขึ้นได้ภายใต้เงื่อนไขบางประการในอุปกรณ์ที่มีความละเอียดสูง เป็นต้น) โดยใช้ค่าที่มีความแม่นยำสูงกว่าสำหรับการเปรียบเทียบเหล่านี้ .

อีกครั้ง แบบสอบถามสื่อเหล่านี้ยังมีให้ผ่านมิกซ์อิน Sass:

@include media-breakpoint-down(xs) { ... }
@include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... }
// No media query necessary for xl breakpoint as it has no upper bound on its width

// Example: Style from medium breakpoint and down
@include media-breakpoint-down(md) {
  .custom-class {
    display: block;
  }
}

นอกจากนี้ยังมีคิวรีสื่อและมิกซ์อินสำหรับการกำหนดเป้าหมายกลุ่มขนาดหน้าจอเดียวโดยใช้ความกว้างของเบรกพอยต์ต่ำสุดและสูงสุด

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) and (max-width: 767.98px) { ... }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) and (max-width: 991.98px) { ... }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) and (max-width: 1199.98px) { ... }

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }

แบบสอบถามสื่อเหล่านี้ยังมีให้ผ่านทางมิกซ์อิน Sass:

@include media-breakpoint-only(xs) { ... }
@include media-breakpoint-only(sm) { ... }
@include media-breakpoint-only(md) { ... }
@include media-breakpoint-only(lg) { ... }
@include media-breakpoint-only(xl) { ... }

ในทำนองเดียวกัน คิวรีสื่ออาจขยายความกว้างของเบรกพอยต์ได้หลายแบบ:

// Example
// Apply styles starting from medium devices and up to extra large devices
@media (min-width: 768px) and (max-width: 1199.98px) { ... }

The Sass mixin for targeting the same screen size range would be:

@include media-breakpoint-between(md, xl) { ... }

Z-index

Several Bootstrap components utilize z-index, the CSS property that helps control layout by providing a third axis to arrange content. We utilize a default z-index scale in Bootstrap that’s been designed to properly layer navigation, tooltips and popovers, modals, and more.

These higher values start at an arbitrary number, high and specific enough to ideally avoid conflicts. We need a standard set of these across our layered components—tooltips, popovers, navbars, dropdowns, modals—so we can be reasonably consistent in the behaviors. There’s no reason we couldn’t have used 100+ or 500+.

We don’t encourage customization of these individual values; should you change one, you likely need to change them all.

$zindex-dropdown:          1000 !default;
$zindex-sticky:            1020 !default;
$zindex-fixed:             1030 !default;
$zindex-modal-backdrop:    1040 !default;
$zindex-modal:             1050 !default;
$zindex-popover:           1060 !default;
$zindex-tooltip:           1070 !default;

ในการจัดการกับเส้นขอบที่ทับซ้อนกันภายในส่วนประกอบต่างๆ (เช่น ปุ่มและอินพุตในกลุ่มอินพุต) เราใช้z-indexค่าตัวเลขหลักเดียวต่ำของ1, 2และ3สำหรับสถานะเริ่มต้น โฮเวอร์ และสถานะที่ใช้งานอยู่ เมื่อวางเมาส์เหนือ/โฟกัส/แอ็คทีฟ เรานำองค์ประกอบเฉพาะมาไว้แถวหน้าด้วยz-indexค่าที่สูงกว่าเพื่อแสดงเส้นขอบขององค์ประกอบที่อยู่เหนือองค์ประกอบระดับเดียวกัน