Как сделать фон сайта bootstrap 5

от admin

Background

Convey meaning through background-color and add decoration with gradients.

Background color

Similar to the contextual text color classes, set the background of an element to any contextual class. Background utilities do not set color , so in some cases you’ll want to use .text-* color utilities.

Background gradient

By adding a .bg-gradient class, a linear gradient is added as background image to the backgrounds. This gradient starts with a semi-transparent white which fades out to the bottom.

Do you need a gradient in your custom CSS? Just add background-image: var(—bs-gradient); .

In addition to the following Sass functionality, consider reading about our included CSS custom properties (aka CSS variables) for colors and more.

Variables

Most background-color utilities are generated by our theme colors, reassigned from our generic color palette variables.

Grayscale colors are also available, but only a subset are used to generate any utilities.

Theme colors are then put into a Sass map so we can loop over them to generate our utilities, component modifiers, and more.

Grayscale colors are also available as a Sass map. This map is not used to generate any utilities.

Mixins

No mixins are used to generate our background utilities, but we do have some additional mixins for other situations where you’d like to create your own gradients.

Как сделать фон сайта bootstrap 5

Передайте смысл с помощью background-color и добавьте украшения с помощью градиентов.

Фоновый цвет

Подобно классам цвета контекстного текста, установите фон элемента для любого контекстного класса. Фоновые утилиты не устанавливают color , поэтому в некоторых случаях Вы захотите использовать .text-* утилиты цвета.

Фоновый градиент

При добавлении класса .bg-gradient , линейный градиент добавляется как фоновое изображение к фону. Этот градиент начинается с полупрозрачного белого цвета, который постепенно исчезает к низу.

Вам нужен градиент в вашем собственном CSS? Просто добавьте background-image: var(—bs-gradient); .

Непрозрачность

Начиная с версии 5.1.0, утилиты background-color генерируются с помощью Sass с использованием переменных CSS. Это позволяет изменять цвет в реальном времени без компиляции и динамических изменений альфа-прозрачности.

Как это устроено

Рассмотрим нашу стандартную утилиту .bg-success .

Мы используем RGB-версию нашей переменной CSS —bs-success (со значением 25, 135, 84 ) и добавляем вторую переменную CSS, —bs-bg-opacity , для альфа-прозрачности. (со значением по умолчанию 1 благодаря локальной переменной CSS). Это означает, что каждый раз, когда вы сейчас используете .bg-success , вашим вычисленным значением color будет rgba(25, 135, 84, 1) . Локальная переменная CSS внутри каждого класса .bg-* позволяет избежать проблем с наследованием, поэтому вложенные экземпляры утилит не имеют автоматически измененной альфа-прозрачности.

Пример

Чтобы изменить эту непрозрачность, переопределите —bs-bg-opacity с помощью пользовательских стилей или встроенных стилей.

Bootstrap 5 Background Image

Setting a background image in Bootstrap can seem troublesome, especially for novice web developers. Thanks to this tutorial, you will not only learn how to use this functionality without any problems, but you will also learn advanced tricks that will allow you to create truly amazing projects with unconventional design.

Also, try these ready-to-use templates to see how you can implement the background image in a real project.

Video tutorial

Basic example

This is a basic example of a full-page background image. If you need a background image with different settings have a look at other sections of this docs.

  1. Add background-image via inline CSS.
  2. Define the background height. In the example below we use vh units, which stands for «viewport height» ( height: 100vh means 100% of available height.)
  3. Add .bg-image class to scale the image properly and to enable responsiveness

How it works

You can easily set the background image in each HTML element by adding a single line of CSS:

Inside of the url(») we need to provide a link to our image.

If you want to use the image on your computer, the path should look like this:

Path Description
img src=»https://mdbootstrap.com/docs/standard/content-styles/background-image/picture.webp» The «picture.webp» file is located in the same folder as the current page
img src=»https://mdbootstrap.com/docs/standard/content-styles/background-image/images/picture.webp» The «picture.webp» file is located in the images folder in the current folder
img src=»https://mdbootstrap.com/images/picture.webp» The «picture.webp» file is located in the images folder at the root of the current web
img src=»https://mdbootstrap.com/docs/standard/content-styles/picture.webp» The «picture.webp» file is located in the folder one level up from the current folder

You can also use an absolute path and add a link to the image directly from the Internet.

Then we just need to add this CSS line to the HTML element.

However, despite this, our picture does not appear. Take a look at the demo:

That’s because we need to provide a height to this HTML element. Let’s add height: 400px; to set a height.

Now it works . partially. We see the picture, but it is cut and unsightly.

Click on the images to launch the live demo.

Читать:
Pabcwork net что это

Fortunately, there is a class in MDBootstrap that fixes this issue. Just add .bg-image to the class and you will see the problem magically disappear.

Full page background image

Now we can easily make this background image to cover the full available space and make it a full-page background image.

Just replace height: 400px; with height: 100vh;

vh stands for viewport height.

height: 100vh; means 100% of available height.

Note: If you want to stretch the image to the full available height and width remember to use the image with enough high resolution. However, be careful not to overdo it. Heigh-resolution images weigh a lot and can slow down your website.

Half page background image

You can also stretch the background image half page (or any other percentage). Just replace «height: 100vh» with «height: 50vh» .

This is a very useful design that is often used in many landing pages.

Jumbotron with background image

In bootstrap 5 there is no dedicated jumbotron component, but it’s not a problem at all. You can easily create your own component by using available classes.

Cards with background image

Using the same technique as with the jumbotron, we can easily create cards with an image in the background.

Как сделать фон сайта bootstrap 5

Setting a background image in Bootstrap can seem troublesome, especially for novice web developers. Thanks to this tutorial, you will not only learn how to use this functionality without any problems, but you will also learn advanced tricks that will allow you to create truly amazing projects with unconventional design.

Also, try these ready-to-use templates to see how you can implement the background image in a real project.

Video tutorial

Basic example

This is a basic example of a full-page background image. If you need a background image with different settings have a look at other sections of this docs.

  1. Add background-image via inline CSS.
  2. Define the background height. In the example below we use vh units, which stands for «viewport height» ( height: 100vh means 100% of available height.)
  3. Add .bg-image class to scale the image properly and to enable responsiveness

How it works

You can easily set the background image in each HTML element by adding a single line of CSS:

Inside of the url(») we need to provide a link to our image.

If you want to use the image on your computer, the path should look like this:

Path Description
img src=»https://mdbootstrap.com/docs/standard/content-styles/background-image/picture.webp» The «picture.webp» file is located in the same folder as the current page
img src=»https://mdbootstrap.com/docs/standard/content-styles/background-image/images/picture.webp» The «picture.webp» file is located in the images folder in the current folder
img src=»https://mdbootstrap.com/images/picture.webp» The «picture.webp» file is located in the images folder at the root of the current web
img src=»https://mdbootstrap.com/docs/standard/content-styles/picture.webp» The «picture.webp» file is located in the folder one level up from the current folder

You can also use an absolute path and add a link to the image directly from the Internet.

Then we just need to add this CSS line to the HTML element.

However, despite this, our picture does not appear. Take a look at the demo:

That’s because we need to provide a height to this HTML element. Let’s add height: 400px; to set a height.

Now it works . partially. We see the picture, but it is cut and unsightly.

Click on the images to launch the live demo.

Fortunately, there is a class in MDBootstrap that fixes this issue. Just add .bg-image to the class and you will see the problem magically disappear.

Full page background image

Now we can easily make this background image to cover the full available space and make it a full-page background image.

Just replace height: 400px; with height: 100vh;

vh stands for viewport height.

height: 100vh; means 100% of available height.

Note: If you want to stretch the image to the full available height and width remember to use the image with enough high resolution. However, be careful not to overdo it. Heigh-resolution images weigh a lot and can slow down your website.

Half page background image

You can also stretch the background image half page (or any other percentage). Just replace «height: 100vh» with «height: 50vh» .

This is a very useful design that is often used in many landing pages.

Jumbotron with background image

In bootstrap 5 there is no dedicated jumbotron component, but it’s not a problem at all. You can easily create your own component by using available classes.

Cards with background image

Using the same technique as with the jumbotron, we can easily create cards with an image in the background.

Похожие статьи