Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
---
2
layout: docs
3
title: Overview
4
description: Components and options for laying out your Bootstrap project, including wrapping containers, a powerful grid system, a flexible media object, and responsive utility classes.
5
group: layout
6
aliases: "/docs/4.6/layout/"
7
toc: true
8
---
9
 
10
## Containers
11
 
12
Containers are the most basic layout element in Bootstrap and are **required when using our default grid system**. Containers are used to contain, pad, and (sometimes) center the content within them. While containers *can* be nested, most layouts do not require a nested container.
13
 
14
Bootstrap comes with three different containers:
15
 
16
- `.container`, which sets a `max-width` at each responsive breakpoint
17
- `.container-fluid`, which is `width: 100%` at all breakpoints
18
- `.container-{breakpoint}`, which is `width: 100%` until the specified breakpoint
19
 
20
The table below illustrates how each container's `max-width` compares to the original `.container` and `.container-fluid` across each breakpoint.
21
 
22
See them in action and compare them in our [Grid example]({{< docsref "/examples/grid#containers" >}}).
23
 
24
<table class="table">
25
  <thead>
26
    <tr>
27
      <th></th>
28
      <th>
29
        Extra small<br>
30
        <span class="font-weight-normal">&lt;576px</span>
31
      </th>
32
      <th>
33
        Small<br>
34
        <span class="font-weight-normal">&ge;576px</span>
35
      </th>
36
      <th>
37
        Medium<br>
38
        <span class="font-weight-normal">&ge;768px</span>
39
      </th>
40
      <th>
41
        Large<br>
42
        <span class="font-weight-normal">&ge;992px</span>
43
      </th>
44
      <th>
45
        Extra large<br>
46
        <span class="font-weight-normal">&ge;1200px</span>
47
      </th>
48
    </tr>
49
  </thead>
50
  <tbody>
51
    <tr>
52
      <td><code>.container</code></td>
53
      <td class="text-muted">100%</td>
54
      <td>540px</td>
55
      <td>720px</td>
56
      <td>960px</td>
57
      <td>1140px</td>
58
    </tr>
59
    <tr>
60
      <td><code>.container-sm</code></td>
61
      <td class="text-muted">100%</td>
62
      <td>540px</td>
63
      <td>720px</td>
64
      <td>960px</td>
65
      <td>1140px</td>
66
    </tr>
67
    <tr>
68
      <td><code>.container-md</code></td>
69
      <td class="text-muted">100%</td>
70
      <td class="text-muted">100%</td>
71
      <td>720px</td>
72
      <td>960px</td>
73
      <td>1140px</td>
74
    </tr>
75
    <tr>
76
      <td><code>.container-lg</code></td>
77
      <td class="text-muted">100%</td>
78
      <td class="text-muted">100%</td>
79
      <td class="text-muted">100%</td>
80
      <td>960px</td>
81
      <td>1140px</td>
82
    </tr>
83
    <tr>
84
      <td><code>.container-xl</code></td>
85
      <td class="text-muted">100%</td>
86
      <td class="text-muted">100%</td>
87
      <td class="text-muted">100%</td>
88
      <td class="text-muted">100%</td>
89
      <td>1140px</td>
90
    </tr>
91
    <tr>
92
      <td><code>.container-fluid</code></td>
93
      <td class="text-muted">100%</td>
94
      <td class="text-muted">100%</td>
95
      <td class="text-muted">100%</td>
96
      <td class="text-muted">100%</td>
97
      <td class="text-muted">100%</td>
98
    </tr>
99
  </tbody>
100
</table>
101
 
102
### All-in-one
103
 
104
Our default `.container` class is a responsive, fixed-width container, meaning its `max-width` changes at each breakpoint.
105
 
106
```html
107
<div class="container">
108
  <!-- Content here -->
109
</div>
110
```
111
 
112
### Fluid
113
 
114
Use `.container-fluid` for a full width container, spanning the entire width of the viewport.
115
 
116
```html
117
<div class="container-fluid">
118
  ...
119
</div>
120
```
121
 
122
### Responsive
123
 
124
Responsive containers are new in Bootstrap v4.4. They allow you to specify a class that is 100% wide until the specified breakpoint is reached, after which we apply `max-width`s for each of the higher breakpoints. For example, `.container-sm` is 100% wide to start until the `sm` breakpoint is reached, where it will scale up with `md`, `lg`, and `xl`.
125
 
126
```html
127
<div class="container-sm">100% wide until small breakpoint</div>
128
<div class="container-md">100% wide until medium breakpoint</div>
129
<div class="container-lg">100% wide until large breakpoint</div>
130
<div class="container-xl">100% wide until extra large breakpoint</div>
131
```
132
 
133
## Responsive breakpoints
134
 
135
Since Bootstrap is developed to be mobile first, we use a handful of [media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.
136
 
137
Bootstrap primarily uses the following media query ranges—or breakpoints—in our source Sass files for our layout, grid system, and components.
138
 
139
```scss
140
// Extra small devices (portrait phones, less than 576px)
141
// No media query for `xs` since this is the default in Bootstrap
142
 
143
// Small devices (landscape phones, 576px and up)
144
@media (min-width: 576px) { ... }
145
 
146
// Medium devices (tablets, 768px and up)
147
@media (min-width: 768px) { ... }
148
 
149
// Large devices (desktops, 992px and up)
150
@media (min-width: 992px) { ... }
151
 
152
// Extra large devices (large desktops, 1200px and up)
153
@media (min-width: 1200px) { ... }
154
```
155
 
156
Since we write our source CSS in Sass, all our media queries are available via Sass mixins:
157
 
158
```scss
159
// No media query necessary for xs breakpoint as it's effectively `@media (min-width: 0) { ... }`
160
@include media-breakpoint-up(sm) { ... }
161
@include media-breakpoint-up(md) { ... }
162
@include media-breakpoint-up(lg) { ... }
163
@include media-breakpoint-up(xl) { ... }
164
 
165
// Example: Hide starting at `min-width: 0`, and then show at the `sm` breakpoint
166
.custom-class {
167
  display: none;
168
}
169
@include media-breakpoint-up(sm) {
170
  .custom-class {
171
    display: block;
172
  }
173
}
174
```
175
 
176
We occasionally use media queries that go in the other direction (the given screen size *or smaller*):
177
 
178
```scss
179
// Extra small devices (portrait phones, less than 576px)
180
@media (max-width: 575.98px) { ... }
181
 
182
// Small devices (landscape phones, less than 768px)
183
@media (max-width: 767.98px) { ... }
184
 
185
// Medium devices (tablets, less than 992px)
186
@media (max-width: 991.98px) { ... }
187
 
188
// Large devices (desktops, less than 1200px)
189
@media (max-width: 1199.98px) { ... }
190
 
191
// Extra large devices (large desktops)
192
// No media query since the extra-large breakpoint has no upper bound on its width
193
```
194
 
195
{{< callout info >}}
196
{{< partial "callout-info-mediaqueries-breakpoints.md" >}}
197
{{< /callout >}}
198
 
199
Once again, these media queries are also available via Sass mixins:
200
 
201
```scss
202
@include media-breakpoint-down(xs) { ... }
203
@include media-breakpoint-down(sm) { ... }
204
@include media-breakpoint-down(md) { ... }
205
@include media-breakpoint-down(lg) { ... }
206
// No media query necessary for xl breakpoint as it has no upper bound on its width
207
 
208
// Example: Style from medium breakpoint and down
209
@include media-breakpoint-down(md) {
210
  .custom-class {
211
    display: block;
212
  }
213
}
214
```
215
 
216
There are also media queries and mixins for targeting a single segment of screen sizes using the minimum and maximum breakpoint widths.
217
 
218
```scss
219
// Extra small devices (portrait phones, less than 576px)
220
@media (max-width: 575.98px) { ... }
221
 
222
// Small devices (landscape phones, 576px and up)
223
@media (min-width: 576px) and (max-width: 767.98px) { ... }
224
 
225
// Medium devices (tablets, 768px and up)
226
@media (min-width: 768px) and (max-width: 991.98px) { ... }
227
 
228
// Large devices (desktops, 992px and up)
229
@media (min-width: 992px) and (max-width: 1199.98px) { ... }
230
 
231
// Extra large devices (large desktops, 1200px and up)
232
@media (min-width: 1200px) { ... }
233
```
234
 
235
These media queries are also available via Sass mixins:
236
 
237
```scss
238
@include media-breakpoint-only(xs) { ... }
239
@include media-breakpoint-only(sm) { ... }
240
@include media-breakpoint-only(md) { ... }
241
@include media-breakpoint-only(lg) { ... }
242
@include media-breakpoint-only(xl) { ... }
243
```
244
 
245
Similarly, media queries may span multiple breakpoint widths:
246
 
247
```scss
248
// Example
249
// Apply styles starting from medium devices and up to extra large devices
250
@media (min-width: 768px) and (max-width: 1199.98px) { ... }
251
```
252
 
253
The Sass mixin for targeting the same screen size range would be:
254
 
255
```scss
256
@include media-breakpoint-between(md, xl) { ... }
257
```
258
 
259
## Z-index
260
 
261
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.
262
 
263
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`+.
264
 
265
We don't encourage customization of these individual values; should you change one, you likely need to change them all.
266
 
267
```scss
268
$zindex-dropdown:          1000 !default;
269
$zindex-sticky:            1020 !default;
270
$zindex-fixed:             1030 !default;
271
$zindex-modal-backdrop:    1040 !default;
272
$zindex-modal:             1050 !default;
273
$zindex-popover:           1060 !default;
274
$zindex-tooltip:           1070 !default;
275
```
276
 
277
To handle overlapping borders within components (e.g., buttons and inputs in input groups), we use low single digit `z-index` values of `1`, `2`, and `3` for default, hover, and active states. On hover/focus/active, we bring a particular element to the forefront with a higher `z-index` value to show their border over the sibling elements.