To make good looking Vue apps, we need to style our components. To make our lives easier, we can use components with styles built-in. In this article, we’ll look at how to add jumbotrons. We also look at how to create basic layouts.
Customizing Jumbotrons
We can add HTML content into a jumbotron by populating slots.
For example, we can write:
<template>
<div id="app">
<b-jumbotron>
<template v-slot:header>Hello</template>
<template v-slot:lead>Lead</template>
<p>World</p>
<b-button variant="primary" href="#">Go Somewhere</b-button>
</b-jumbotron>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
We added the template
tags.
And we have the v-slot
directives to populate different slots.
header
lets us set the header contents.
lead
lets us set the lead content, which is displayed below the header
.
Header and Lead Tags
We can change the header and lead tags with the header-tag
and lead-tag
props.
For instance, we can write:
<template>
<div id="app">
<b-jumbotron header="Hello" lead="Lead" header-tag="h2" lead-tag="p">
<p>World</p>
<b-button variant="primary" href="#">Go Somewhere</b-button>
</b-jumbotron>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
Now we set the header and lead tags to h2 and p respectively.
Styling Variants
We can change the styling by using the bg-variant
prop to change the background.
It can take the values info
, danger
, warning
, light
and dark
.
The border can set with the border-variant
prop. And the text style can ve set with the text-variant
prop.
For instance, we can write:
<template>
<div id="app">
<b-jumbotron text-variant='light' bg-variant="info" header="Hello" lead="Lead">
<p>World</p>
<b-button variant="primary" href="#">Go Somewhere</b-button>
</b-jumbotron>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
Then we get white text on a green background.
Layout and Grid System
BootstrapVue has its own layout and grid components.
It comes with the b-container
, b-row
, and b-col
components.
For example, we can write:
<template>
<div id="app">
<b-container>
<b-row>
<b-col>1</b-col>
<b-col>2</b-col>
<b-col>3</b-col>
</b-row>
</b-container>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
We used the b-container
component to contain a b-row
, and that contains 3 b-col
components.
b-row
is a row and b-col
is a column.
We can make it responsive with the fluid
prop.
Responsive Fluid Containers
The fluid
prop can take on a size value that indicates on what screen size it’s 100% wide.
For instance, we can write:
<b-container fluid="sm">
hello
</b-container>
so it’s 100% wide until the app hits the small breakpoint.
Likewise, 'md'
is 100% wide until the medium breakpoint.
'lg'
is 100% wide until the large breakpoint.
'xl'
is 100% wide until the extra-large breakpoint.
Rows
The b-row
and b-form-row
components let us add rows.
b-form-row
is different from b-row
in that the margins of b-form-row
are smaller.
Columns
We can create columns with equal without any props and the b-col
component.
We can write:
<template>
<div id="app">
<b-container>
<b-row>
<b-col>1</b-col>
<b-col>2</b-col>
<b-col>3</b-col>
</b-row>
</b-container>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
to create them.
We can also create equal width multiline columns by adding a div with class w-100
between the columns.
For instance, if we have:
<template>
<div id="app">
<b-container>
<b-row>
<b-col>1</b-col>
<b-col>2</b-col>
<div class="w-100"></div>
<b-col>3</b-col>
<b-col>4</b-col>
</b-row>
</b-container>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
Then we have 2 columns on top and 2 below them.
Setting One Column Width
We can change the column width the cols
prop.
For example, we can write:
<template>
<div id="app">
<b-container>
<b-row>
<b-col>1</b-col>
<b-col cols="8">2</b-col>
<b-col>3</b-col>
</b-row>
</b-container>
</div>
</template>
<script>
export default {
name: "App"
};
</script>
We have cols
set to 8 so that the column takes 8 / 12 of the screens’ width.
A grid is divided into 12 columns.
The other columns will fill the remaining space evenly.
Conclusion
We can add columns and rows to create responsive rows and columns.
Jumbotrons can be used to display attention-grabbing text.