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: List group
4
description: List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.
5
group: components
6
toc: true
7
---
8
 
9
## Basic example
10
 
11
The most basic list group is an unordered list with list items and the proper classes. Build upon it with the options that follow, or with your own CSS as needed.
12
 
13
{{< example >}}
14
<ul class="list-group">
15
  <li class="list-group-item">An item</li>
16
  <li class="list-group-item">A second item</li>
17
  <li class="list-group-item">A third item</li>
18
  <li class="list-group-item">A fourth item</li>
19
  <li class="list-group-item">And a fifth one</li>
20
</ul>
21
{{< /example >}}
22
 
23
## Active items
24
 
25
Add `.active` to a `.list-group-item` to indicate the current active selection.
26
 
27
{{< example >}}
28
<ul class="list-group">
29
  <li class="list-group-item active" aria-current="true">An active item</li>
30
  <li class="list-group-item">A second item</li>
31
  <li class="list-group-item">A third item</li>
32
  <li class="list-group-item">A fourth item</li>
33
  <li class="list-group-item">And a fifth one</li>
34
</ul>
35
{{< /example >}}
36
 
37
## Disabled items
38
 
39
Add `.disabled` to a `.list-group-item` to make it _appear_ disabled. Note that some elements with `.disabled` will also require custom JavaScript to fully disable their click events (e.g., links).
40
 
41
{{< example >}}
42
<ul class="list-group">
43
  <li class="list-group-item disabled" aria-disabled="true">A disabled item</li>
44
  <li class="list-group-item">A second item</li>
45
  <li class="list-group-item">A third item</li>
46
  <li class="list-group-item">A fourth item</li>
47
  <li class="list-group-item">And a fifth one</li>
48
</ul>
49
{{< /example >}}
50
 
51
## Links and buttons
52
 
53
Use `<a>`s or `<button>`s to create _actionable_ list group items with hover, disabled, and active states by adding `.list-group-item-action`. We separate these pseudo-classes to ensure list groups made of non-interactive elements (like `<li>`s or `<div>`s) don't provide a click or tap affordance.
54
 
55
Be sure to **not use the standard `.btn` classes here**.
56
 
57
{{< example >}}
58
<div class="list-group">
59
  <a href="#" class="list-group-item list-group-item-action active" aria-current="true">
60
    The current link item
61
  </a>
62
  <a href="#" class="list-group-item list-group-item-action">A second link item</a>
63
  <a href="#" class="list-group-item list-group-item-action">A third link item</a>
64
  <a href="#" class="list-group-item list-group-item-action">A fourth link item</a>
65
  <a class="list-group-item list-group-item-action disabled">A disabled link item</a>
66
</div>
67
{{< /example >}}
68
 
69
With `<button>`s, you can also make use of the `disabled` attribute instead of the `.disabled` class. Sadly, `<a>`s don't support the disabled attribute.
70
 
71
{{< example >}}
72
<div class="list-group">
73
  <button type="button" class="list-group-item list-group-item-action active" aria-current="true">
74
    The current button
75
  </button>
76
  <button type="button" class="list-group-item list-group-item-action">A second item</button>
77
  <button type="button" class="list-group-item list-group-item-action">A third button item</button>
78
  <button type="button" class="list-group-item list-group-item-action">A fourth button item</button>
79
  <button type="button" class="list-group-item list-group-item-action" disabled>A disabled button item</button>
80
</div>
81
{{< /example >}}
82
 
83
## Flush
84
 
85
Add `.list-group-flush` to remove some borders and rounded corners to render list group items edge-to-edge in a parent container (e.g., cards).
86
 
87
{{< example >}}
88
<ul class="list-group list-group-flush">
89
  <li class="list-group-item">An item</li>
90
  <li class="list-group-item">A second item</li>
91
  <li class="list-group-item">A third item</li>
92
  <li class="list-group-item">A fourth item</li>
93
  <li class="list-group-item">And a fifth one</li>
94
</ul>
95
{{< /example >}}
96
 
97
## Horizontal
98
 
99
Add `.list-group-horizontal` to change the layout of list group items from vertical to horizontal across all breakpoints. Alternatively, choose a responsive variant `.list-group-horizontal-{sm|md|lg|xl}` to make a list group horizontal starting at that breakpoint's `min-width`. Currently **horizontal list groups cannot be combined with flush list groups.**
100
 
101
**ProTip:** Want equal-width list group items when horizontal? Add `.flex-fill` to each list group item.
102
 
103
{{< example >}}
104
{{< list-group.inline >}}
105
{{- range $.Site.Data.breakpoints }}
106
<ul class="list-group list-group-horizontal{{ .abbr }}">
107
  <li class="list-group-item">An item</li>
108
  <li class="list-group-item">A second item</li>
109
  <li class="list-group-item">A third item</li>
110
</ul>
111
{{- end -}}
112
{{< /list-group.inline >}}
113
{{< /example >}}
114
 
115
## Contextual classes
116
 
117
Use contextual classes to style list items with a stateful background and color.
118
 
119
{{< example >}}
120
<ul class="list-group">
121
  <li class="list-group-item">A simple default list group item</li>
122
{{< list.inline >}}
123
{{- range (index $.Site.Data "theme-colors") }}
124
  <li class="list-group-item list-group-item-{{ .name }}">A simple {{ .name }} list group item</li>
125
{{- end -}}
126
{{< /list.inline >}}
127
</ul>
128
{{< /example >}}
129
 
130
Contextual classes also work with `.list-group-item-action`. Note the addition of the hover styles here not present in the previous example. Also supported is the `.active` state; apply it to indicate an active selection on a contextual list group item.
131
 
132
{{< example >}}
133
<div class="list-group">
134
  <a href="#" class="list-group-item list-group-item-action">A simple default list group item</a>
135
{{< list.inline >}}
136
{{- range (index $.Site.Data "theme-colors") }}
137
  <a href="#" class="list-group-item list-group-item-action list-group-item-{{ .name }}">A simple {{ .name }} list group item</a>
138
{{- end -}}
139
{{< /list.inline >}}
140
</div>
141
{{< /example >}}
142
 
143
{{< callout warning >}}
144
{{< partial "callout-warning-color-assistive-technologies.md" >}}
145
{{< /callout >}}
146
 
147
## With badges
148
 
149
Add badges to any list group item to show unread counts, activity, and more with the help of some [utilities]({{< docsref "/utilities/flex" >}}).
150
 
151
{{< example >}}
152
<ul class="list-group">
153
  <li class="list-group-item d-flex justify-content-between align-items-center">
154
    A list item
155
    <span class="badge badge-primary badge-pill">14</span>
156
  </li>
157
  <li class="list-group-item d-flex justify-content-between align-items-center">
158
    A second list item
159
    <span class="badge badge-primary badge-pill">2</span>
160
  </li>
161
  <li class="list-group-item d-flex justify-content-between align-items-center">
162
    A third list item
163
    <span class="badge badge-primary badge-pill">1</span>
164
  </li>
165
</ul>
166
{{< /example >}}
167
 
168
## Custom content
169
 
170
Add nearly any HTML within, even for linked list groups like the one below, with the help of [flexbox utilities]({{< docsref "/utilities/flex" >}}).
171
 
172
{{< example >}}
173
<div class="list-group">
174
  <a href="#" class="list-group-item list-group-item-action active">
175
    <div class="d-flex w-100 justify-content-between">
176
      <h5 class="mb-1">List group item heading</h5>
177
      <small>3 days ago</small>
178
    </div>
179
    <p class="mb-1">Some placeholder content in a paragraph.</p>
180
    <small>And some small print.</small>
181
  </a>
182
  <a href="#" class="list-group-item list-group-item-action">
183
    <div class="d-flex w-100 justify-content-between">
184
      <h5 class="mb-1">List group item heading</h5>
185
      <small class="text-muted">3 days ago</small>
186
    </div>
187
    <p class="mb-1">Some placeholder content in a paragraph.</p>
188
    <small class="text-muted">And some muted small print.</small>
189
  </a>
190
  <a href="#" class="list-group-item list-group-item-action">
191
    <div class="d-flex w-100 justify-content-between">
192
      <h5 class="mb-1">List group item heading</h5>
193
      <small class="text-muted">3 days ago</small>
194
    </div>
195
    <p class="mb-1">Some placeholder content in a paragraph.</p>
196
    <small class="text-muted">And some muted small print.</small>
197
  </a>
198
</div>
199
{{< /example >}}
200
 
201
## JavaScript behavior
202
 
203
Use the tab JavaScript plugin—include it individually or through the compiled `bootstrap.js` file—to extend our list group to create tabbable panes of local content.
204
 
205
<div class="bd-example" role="tabpanel">
206
  <div class="row">
207
    <div class="col-4">
208
      <div class="list-group" id="list-tab" role="tablist">
209
        <a class="list-group-item list-group-item-action active" id="list-home-list" data-toggle="tab" href="#list-home" role="tab" aria-controls="list-home">Home</a>
210
        <a class="list-group-item list-group-item-action" id="list-profile-list" data-toggle="tab" href="#list-profile" role="tab" aria-controls="list-profile">Profile</a>
211
        <a class="list-group-item list-group-item-action" id="list-messages-list" data-toggle="tab" href="#list-messages" role="tab" aria-controls="list-messages">Messages</a>
212
        <a class="list-group-item list-group-item-action" id="list-settings-list" data-toggle="tab" href="#list-settings" role="tab" aria-controls="list-settings">Settings</a>
213
      </div>
214
    </div>
215
    <div class="col-8">
216
      <div class="tab-content" id="nav-tabContent">
217
        <div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-list">
218
          <p>Some placeholder content in a paragraph relating to "Home". And some more content, used here just to pad out and fill this tab panel. In production, you would obviously have more real content here. And not just text. It could be anything, really. Text, images, forms.</p>
219
        </div>
220
        <div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">
221
          <p>Some placeholder content in a paragraph relating to "Profile". And some more content, used here just to pad out and fill this tab panel. In production, you would obviously have more real content here. And not just text. It could be anything, really. Text, images, forms.</p>
222
        </div>
223
        <div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">
224
          <p>Some placeholder content in a paragraph relating to "Messages". And some more content, used here just to pad out and fill this tab panel. In production, you would obviously have more real content here. And not just text. It could be anything, really. Text, images, forms.</p>
225
        </div>
226
        <div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">
227
          <p>Some placeholder content in a paragraph relating to "Settings". And some more content, used here just to pad out and fill this tab panel. In production, you would obviously have more real content here. And not just text. It could be anything, really. Text, images, forms.</p>
228
        </div>
229
      </div>
230
    </div>
231
  </div>
232
</div>
233
 
234
```html
235
<div class="row">
236
  <div class="col-4">
237
    <div class="list-group" id="list-tab" role="tablist">
238
      <a class="list-group-item list-group-item-action active" id="list-home-list" data-toggle="list" href="#list-home" role="tab" aria-controls="home">Home</a>
239
      <a class="list-group-item list-group-item-action" id="list-profile-list" data-toggle="list" href="#list-profile" role="tab" aria-controls="profile">Profile</a>
240
      <a class="list-group-item list-group-item-action" id="list-messages-list" data-toggle="list" href="#list-messages" role="tab" aria-controls="messages">Messages</a>
241
      <a class="list-group-item list-group-item-action" id="list-settings-list" data-toggle="list" href="#list-settings" role="tab" aria-controls="settings">Settings</a>
242
    </div>
243
  </div>
244
  <div class="col-8">
245
    <div class="tab-content" id="nav-tabContent">
246
      <div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-list">...</div>
247
      <div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">...</div>
248
      <div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">...</div>
249
      <div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">...</div>
250
    </div>
251
  </div>
252
</div>
253
```
254
 
255
### Using data attributes
256
 
257
You can activate a list group navigation without writing any JavaScript by simply specifying `data-toggle="list"` or on an element. Use these data attributes on `.list-group-item`.
258
 
259
```html
260
<div role="tabpanel">
261
  <!-- List group -->
262
  <div class="list-group" id="myList" role="tablist">
263
    <a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab">Home</a>
264
    <a class="list-group-item list-group-item-action" data-toggle="list" href="#profile" role="tab">Profile</a>
265
    <a class="list-group-item list-group-item-action" data-toggle="list" href="#messages" role="tab">Messages</a>
266
    <a class="list-group-item list-group-item-action" data-toggle="list" href="#settings" role="tab">Settings</a>
267
  </div>
268
 
269
  <!-- Tab panes -->
270
  <div class="tab-content">
271
    <div class="tab-pane active" id="home" role="tabpanel">...</div>
272
    <div class="tab-pane" id="profile" role="tabpanel">...</div>
273
    <div class="tab-pane" id="messages" role="tabpanel">...</div>
274
    <div class="tab-pane" id="settings" role="tabpanel">...</div>
275
  </div>
276
</div>
277
```
278
 
279
### Via JavaScript
280
 
281
Enable tabbable list item via JavaScript (each list item needs to be activated individually):
282
 
283
```js
284
$('#myList a').on('click', function (event) {
285
  event.preventDefault()
286
  $(this).tab('show')
287
})
288
```
289
 
290
You can activate individual list item in several ways:
291
 
292
```js
293
$('#myList a[href="#profile"]').tab('show') // Select tab by name
294
$('#myList a:first-child').tab('show') // Select first tab
295
$('#myList a:last-child').tab('show') // Select last tab
296
$('#myList a:nth-child(3)').tab('show') // Select third tab
297
```
298
 
299
### Fade effect
300
 
301
To make tabs panel fade in, add `.fade` to each `.tab-pane`. The first tab pane must also have `.show` to make the initial content visible.
302
 
303
```html
304
<div class="tab-content">
305
  <div class="tab-pane fade show active" id="home" role="tabpanel">...</div>
306
  <div class="tab-pane fade" id="profile" role="tabpanel">...</div>
307
  <div class="tab-pane fade" id="messages" role="tabpanel">...</div>
308
  <div class="tab-pane fade" id="settings" role="tabpanel">...</div>
309
</div>
310
```
311
 
312
### Methods
313
 
314
#### $().tab
315
 
316
Activates a list item element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
317
 
318
```html
319
<div class="list-group" id="myList" role="tablist">
320
  <a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab">Home</a>
321
  <a class="list-group-item list-group-item-action" data-toggle="list" href="#profile" role="tab">Profile</a>
322
  <a class="list-group-item list-group-item-action" data-toggle="list" href="#messages" role="tab">Messages</a>
323
  <a class="list-group-item list-group-item-action" data-toggle="list" href="#settings" role="tab">Settings</a>
324
</div>
325
 
326
<div class="tab-content">
327
  <div class="tab-pane active" id="home" role="tabpanel">...</div>
328
  <div class="tab-pane" id="profile" role="tabpanel">...</div>
329
  <div class="tab-pane" id="messages" role="tabpanel">...</div>
330
  <div class="tab-pane" id="settings" role="tabpanel">...</div>
331
</div>
332
 
333
<script>
334
  $(function () {
335
    $('#myList a:last-child').tab('show')
336
  })
337
</script>
338
```
339
 
340
#### .tab('show')
341
 
342
Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (for example, before the `shown.bs.tab` event occurs).
343
 
344
```js
345
$('#someListItem').tab('show')
346
```
347
 
348
### Events
349
 
350
When showing a new tab, the events fire in the following order:
351
 
352
1. `hide.bs.tab` (on the current active tab)
353
2. `show.bs.tab` (on the to-be-shown tab)
354
3. `hidden.bs.tab` (on the previous active tab, the same one as for the `hide.bs.tab` event)
355
4. `shown.bs.tab` (on the newly-active just-shown tab, the same one as for the `show.bs.tab` event)
356
 
357
If no tab was already active, the `hide.bs.tab` and `hidden.bs.tab` events will not be fired.
358
 
359
<table class="table table-bordered table-striped">
360
  <thead>
361
    <tr>
362
      <th style="width: 150px;">Event type</th>
363
      <th>Description</th>
364
    </tr>
365
  </thead>
366
  <tbody>
367
    <tr>
368
      <td>show.bs.tab</td>
369
      <td>This event fires on tab show, but before the new tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
370
    </tr>
371
    <tr>
372
      <td>shown.bs.tab</td>
373
      <td>This event fires on tab show after a tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
374
    </tr>
375
    <tr>
376
      <td>hide.bs.tab</td>
377
      <td>This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use <code>event.target</code> and <code>event.relatedTarget</code> to target the current active tab and the new soon-to-be-active tab, respectively.</td>
378
    </tr>
379
    <tr>
380
      <td>hidden.bs.tab</td>
381
      <td>This event fires after a new tab is shown (and thus the previous active tab is hidden). Use <code>event.target</code> and <code>event.relatedTarget</code> to target the previous active tab and the new active tab, respectively.</td>
382
    </tr>
383
  </tbody>
384
</table>
385
 
386
```js
387
$('a[data-toggle="list"]').on('shown.bs.tab', function (event) {
388
  event.target // newly activated tab
389
  event.relatedTarget // previous active tab
390
})
391
```