安装 Bootstrap
详情查看:https://getbootstrap.com/docs/5.0/getting-started/webpack/
安装
# bootstrap npm install bootstrap @popperjs/core引⼊ Bootstrap
// 实际引⼊的是 Bootstrap.js import { Button } from ‘bootstrap’;基本样式⽀持
安装
# sass npm i -D sass sass-loader配置 sass-loader
{
test: /.(scss)$/, use: [{ // inject CSS to page loader: ‘style-loader’ }, { // translates CSS into CommonJS modules loader: ‘css-loader’ }, { // Run postcss actions loader: ‘postcss-loader’, options: { //postcssOptions
is needed for postcss 8.x;
// if you use postcss 7.x skip the key
postcssOptions: {
// postcss plugins, can be exported to postcss.config.js
plugins: function () {
return [
require(‘autoprefixer’)
];
}
}
}
},{
// compiles Sass to CSS loader: ‘sass-loader’ }]}
导⼊样式
import ‘bootstrap/dist/css/bootstrap.min.css’;⾃定义样式
声明⾃定义样式
// ./src/css/custom.scss ⾃定义样式 $body-bg: #dfb; $primary: #0074d9; $danger: #ff4136; // ./src/css/main.scss @import “custom”; @import “~bootstrap/scss/bootstrap”;引⼊⾃定义样式
import ‘./css/main.scss’验证效果
声明容器
详情参考:https://getbootstrap.com/docs/5.0/layout/containers/
class=“container container-sm container-md container-lg conta
iner-xl container-xxl”>
添加导航菜单
class=“container container-sm container-md container-lg cont
ainer-xl container-xxl”>
声明轮播图
class=“container container-sm container-md container-lg cont
ainer-xl container-xxl”>
id=“carouselExampleIndicators” class=“carousel slide” data
-bs-ride=“carousel”>
class=“carousel-indicators”>
class=“carousel-inner”>
class=“carousel-item active”>
src=“…” class=“d-block w-100” alt=“…”>
class=“carousel-item active”>
src=“…” class=“d-block w-100” alt=“…”>
class=“carousel-item active”>
src=“…” class=“d-block w-100” alt=“…”>