Home > Web Front-end > Bootstrap Tutorial > How to add background to bootstrap

How to add background to bootstrap

下次还敢
Release: 2024-04-05 02:15:20
Original
1011 people have browsed it

There are two ways to add a background in Bootstrap: using built-in CSS classes, such as .bg- (monochrome background) and .bg-gradient- (gradient background); using custom CSS rules, such as setting background-color and background-image properties.

How to add background to bootstrap

How to add background in Bootstrap

Bootstrap is a popular front-end framework that provides an easy way to add a background to an HTML element. There are two main ways to do this:

Method 1: Using CSS Classes

Bootstrap provides a series of built-in CSS classes that add different Type of background:

  • .bg-*: Adds a solid color background to the element, where * can be any color, for example bg- primary, bg-warning, etc.
  • .bg-gradient-*: Add a gradient background to the element, where * can be primary, secondary , success, etc.
  • .bg-image: Add an image background to the element. The URL or path to the image needs to be specified.

How to use:

<code class="html"><div class="bg-primary">This is a blue background.</div>
<div class="bg-gradient-primary">This is a blue gradient background.</div>
<div class="bg-image" style="background-image: url('image.png');">This is a background image.</div></code>
Copy after login

Method 2: Use custom CSS

If you need more granular Control, you can also use custom CSS rules to add backgrounds to elements:

<code class="css">body {
  background-color: #ccc;
}

.my-background {
  background-image: url('image.png');
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
}</code>
Copy after login

Usage:

<code class="html"><body class="my-background"></body></code>
Copy after login

Please note that custom CSS rules have higher priority than Bootstrap's built-in CSS classes.

The above is the detailed content of How to add background to bootstrap. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template