2020-09-16 23:30:49 +00:00
---
title: Block
2024-03-21 16:11:54 +00:00
layout: docs
theme: library
2020-09-16 23:30:49 +00:00
doc-tab: elements
doc-subtab: block
breadcrumb:
2024-03-21 16:11:54 +00:00
- home
- documentation
- elements
- elements-block
2020-09-16 23:30:49 +00:00
meta:
colors: false
sizes: false
variables: true
---
{% capture block_example %}
< div class = "block" >
This text is within a < strong > block< / strong > .
< / div >
< div class = "block" >
This text is within a < strong > second block< / strong > . Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean efficitur sit amet massa fringilla egestas. Nullam condimentum luctus turpis.
< / div >
< div class = "block" >
This text is within a < strong > third block< / strong > . This block has no margin at the bottom.
< / div >
{% endcapture %}
{% capture no_block_example %}
< div >
2020-09-27 09:35:07 +00:00
This text is < em > not< / em > within a < strong > block< / strong > .
2020-09-16 23:30:49 +00:00
< / div >
< div >
2020-09-27 09:35:07 +00:00
This text < em > isn't< / em > within a < strong > block< / strong > either. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean efficitur sit amet massa fringilla egestas. Nullam condimentum luctus turpis.
2020-09-16 23:30:49 +00:00
< / div >
< div >
2020-09-27 09:35:07 +00:00
This text is also < em > not< / em > within a < strong > block< / strong > .
2020-09-16 23:30:49 +00:00
< / div >
{% endcapture %}
{% capture block_css %}
.block:not(:last-child) {
margin-bottom: 1.5rem;
}
{% endcapture %}
2021-01-27 23:30:42 +00:00
{% capture no_block %}
< p class = "title mb-0" > Without block< / p >
< div class = "block mb-0" >
< div class = "field is-grouped" >
< div class = "control is-expanded" >
< input class = "input" type = "text" placeholder = "Text input" >
< / div >
< div class = "control" >
< button class = "button is-primary" > Button< / button >
< / div >
< / div >
< / div >
< nav class = "pagination mb-0" role = "navigation" aria-label = "pagination" >
< a class = "pagination-previous" title = "This is the first page" disabled > Previous< / a >
< a class = "pagination-next" > Next page< / a >
< ul class = "pagination-list" >
< li >
< a class = "pagination-link is-current" aria-label = "Page 1" aria-current = "page" > 1< / a >
< / li >
< li >
< a class = "pagination-link" aria-label = "Goto page 2" > 2< / a >
< / li >
< li >
< a class = "pagination-link" aria-label = "Goto page 3" > 3< / a >
< / li >
< / ul >
< / nav >
< progress class = "progress is-success mb-0" value = "30" max = "100" > 30%< / progress >
< div class = "notification is-warning mb-0" >
< button class = "delete" > < / button >
Primar lorem ipsum dolor sit amet, consectetur adipiscing elit lorem ipsum dolor.
< / div >
< article class = "message is-danger mb-0" >
< div class = "message-header" >
< p > Error< / p >
< button class = "delete" aria-label = "delete" > < / button >
< / div >
< div class = "message-body" >
Lorem ipsum dolor sit amet, consectetur adipiscing elit. < strong > Pellentesque risus mi< / strong > , tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum < a > felis venenatis< / a > efficitur.
< / div >
< / article >
{% endcapture %}
{% capture with_block %}
< p class = "title" > With block< / p >
< div class = "block" >
< div class = "field is-grouped" >
< div class = "control is-expanded" >
< input class = "input" type = "text" placeholder = "Text input" >
< / div >
< div class = "control" >
< button class = "button is-primary" > Button< / button >
< / div >
< / div >
< / div >
< nav class = "pagination" role = "navigation" aria-label = "pagination" >
< a class = "pagination-previous" title = "This is the first page" disabled > Previous< / a >
< a class = "pagination-next" > Next page< / a >
< ul class = "pagination-list" >
< li >
< a class = "pagination-link is-current" aria-label = "Page 1" aria-current = "page" > 1< / a >
< / li >
< li >
< a class = "pagination-link" aria-label = "Goto page 2" > 2< / a >
< / li >
< li >
< a class = "pagination-link" aria-label = "Goto page 3" > 3< / a >
< / li >
< / ul >
< / nav >
< progress class = "progress is-success" value = "30" max = "100" > 30%< / progress >
< div class = "notification is-warning" >
< button class = "delete" > < / button >
Primar lorem ipsum dolor sit amet, consectetur adipiscing elit lorem ipsum dolor.
< / div >
< article class = "message is-danger" >
< div class = "message-header" >
< p > Error< / p >
< button class = "delete" aria-label = "delete" > < / button >
< / div >
< div class = "message-body" >
Lorem ipsum dolor sit amet, consectetur adipiscing elit. < strong > Pellentesque risus mi< / strong > , tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum < a > felis venenatis< / a > efficitur.
< / div >
< / article >
{% endcapture %}
<!-- -->
2020-09-16 23:30:49 +00:00
< div class = "content" >
< p >
2024-03-21 16:11:54 +00:00
The < code > block< / code > element is a simple < strong > spacer tool< / strong > . It allows < strong > sibling< / strong > HTML
elements to have a consistent margin between them:
2020-09-16 23:30:49 +00:00
< / p >
< / div >
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=block_example %}
2020-09-16 23:30:49 +00:00
< div class = "content" >
< p >
2024-03-21 16:11:54 +00:00
As you can see, the first two blocks have a < code > margin-bottom< / code > applied, but
< strong > not the third .< / strong > . That is because Bulma applies a space on all blocks,
< strong > except the last one< / strong > . This means you can use as many blocks as you want, the spacing will only
appear < strong > between them< / strong > .
2020-09-16 23:30:49 +00:00
< / p >
2024-03-21 16:11:54 +00:00
< p > Without using < code > block< / code > , the HTML elements would have no space between them:< / p >
2020-09-16 23:30:49 +00:00
< / div >
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=no_block_example %}
2020-09-16 23:30:49 +00:00
2021-01-27 23:30:42 +00:00
<!-- -->
2020-09-16 23:30:49 +00:00
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor.html name="You're already using it" %}
2020-09-16 23:30:49 +00:00
< div class = "content" >
< p >
2024-03-21 16:11:54 +00:00
As a matter of fact, you're < strong > already using< / strong > the < code > block< / code > without knowing it. Its CSS
properties are < strong > shared< / strong > across several Bulma elements and components:
2020-09-16 23:30:49 +00:00
< / p >
< ul >
< li > < code > breadcrumb< / code > < / li >
< li > < code > level< / code > < / li >
< li > < code > message< / code > < / li >
< li > < code > pagination< / code > < / li >
< li > < code > tabs< / code > < / li >
< li > < code > box< / code > < / li >
< li > < code > content< / code > < / li >
< li > < code > notification< / code > < / li >
< li > < code > other< / code > < / li >
< li > < code > progress< / code > < / li >
< li > < code > table< / code > < / li >
< li > < code > title< / code > < / li >
< / ul >
2024-03-21 16:11:54 +00:00
< p > This is thanks to the < code > @extend %block< / code > Sass placeholder feature.< / p >
2020-09-16 23:30:49 +00:00
2024-03-21 16:11:54 +00:00
< p > Here's how it would look like in comparison:< / p >
2021-01-27 23:30:42 +00:00
< / div >
< div class = "columns is-size-6" >
< div class = "column" >
{{ no_block }}
< / div >
< div class = "column" >
{{ with_block }}
< / div >
< / div >
< div class = "content" >
< p >
2024-03-21 16:11:54 +00:00
No matter which Bulma elements and components you are using, and no matter their order, they will have a
< strong > consistent space< / strong > between them.
2021-01-27 23:30:42 +00:00
< / p >
< / div >
<!-- -->
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor.html name="One line of CSS" %}
2021-01-27 23:30:42 +00:00
< div class = "content" >
< p >
2024-03-21 16:11:54 +00:00
As you can see, the CSS of the < code > block< / code > is very simple: it applies a < code > margin-bottom< / code > on all
siblings, < strong > except the last one< / strong > .
2021-01-27 23:30:42 +00:00
< / p >
< / div >
2024-03-21 16:11:54 +00:00
{% highlight css %}
{{ block_css }}
{% endhighlight %}
2021-01-27 23:30:42 +00:00
< div class = "content" >
2024-03-21 16:11:54 +00:00
< p > This prevents the last sibling from adding unnecessary space at the bottom.< / p >
2020-09-16 23:30:49 +00:00
< / div >
2024-03-21 16:11:54 +00:00