使用Bootstrp怎么进行主页搭建?
目录
本期的大部分代码都来自Boostrap第五代官网,感兴趣的朋友们可以去看看哦~
记住复制过来的代码有的不能直接使用,得经过一定的修改才能正常使用哦~
编写项目前的必备操作
1. 首先导入Bootstrap文件
2. 然后在项目中导入以下几个语句
<!-- 必须要在所有CSS之前导不然不生效 -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="bootstrap-5.0.0-beta3-dist/css/bootstrap.css" rel="stylesheet">
<!-- Bootstrap JS -->
<script src="bootstrap-5.0.0-beta3-dist/js/bootstrap.js"></script>
本次项目所需要的文件
以下就是本次Web项目所需要的文件:
具体编写代码
top.jsp的代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%--导航栏--%>
<nav class="navbar navbar-dark bg-primary mb-2">
<div class="container-fluid">
<a class="navbar-brand" href="#">
天天商城
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#linkText"
aria-controls="navbarText" aria-expanded="false">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="linkText">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.jsp" id="index">首页</a>
</li>
<li class="nav-item">
<a class="nav-link" href="insert.jsp" id="insert">增加商品</a>
</li>
</ul>
<script>
$("#<%=request.getParameter("type")%>").addClass("active")
</script>
</div>
</div>
</nav>
</body>
</html>
index.jsp的代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/jquery-3.3.1.js"></script>
<link rel="stylesheet" href="bootstrap-5.0.0-beta3-dist/css/bootstrap.css">
<script src="bootstrap-5.0.0-beta3-dist/js/bootstrap.js"></script>
<style>
.carousel-item img{
height: 350px;
}
</style>
</head>
<body>
<jsp:include page="component/top.jsp">
<jsp:param name="type" value="index"/>
</jsp:include>
<%--容器--%>
<div class="container">
<%--轮播图--%>
<div id="myCarousel" class="carousel slide mb-3" data-bs-ride="carousel" data-bs-interval="1000">
<div class="carousel-indicators">
<button type="button" data-bs-target="#myCarousel" data-bs-slide-to="0" class="active"></button>
<button type="button" d