使用bootstrap框架设计一个主页面,包含css和html代码
时间: 2024-06-08 16:10:34 浏览: 180
以下是一个简单的使用Bootstrap的主页面的HTML和CSS代码:
HTML代码:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap Main Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">My Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h1>Welcome to my website</h1>
<p>This is a simple Bootstrap template for a main page</p>
<button type="button" class="btn btn-primary">Learn More</button>
</div>
<div class="container-fluid bg-grey">
<h2>About Us</h2>
<h4>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="container">
<h2>Services</h2>
<div class="row">
<div class="col-sm-4">
<h4>Web Design</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="col-sm-4">
<h4>Web Development</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="col-sm-4">
<h4>Graphic Design</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
<div class="container-fluid bg-grey">
<h2>Portfolio</h2>
<div class="row">
<div class="col-sm-4">
<img src="https://via.placeholder.com/350x150" class="img-responsive" style="width:100%" alt="Image">
</div>
<div class="col-sm-4">
<img src="https://via.placeholder.com/350x150" class="img-responsive" style="width:100%" alt="Image">
</div>
<div class="col-sm-4">
<img src="https://via.placeholder.com/350x150" class="img-responsive" style="width:100%" alt="Image">
</div>
</div>
</div>
<div class="container">
<h2>Contact Us</h2>
<div class="row">
<div class="col-sm-5">
<p>Contact us and we'll get back to you within 24 hours.</p>
<p><span class="glyphicon glyphicon-map-marker"></span> Chicago, US</p>
<p><span class="glyphicon glyphicon-phone"></span> +00 1515151515</p>
<p><span class="glyphicon glyphicon-envelope"></span> myemail@something.com</p>
</div>
<div class="col-sm-7">
<form action="/action_page.php">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="comments" name="comments" placeholder="Comment" rows="5"></textarea><br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" type="submit">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
<footer class="container-fluid text-center">
<p>Footer Text</p>
</footer>
</body>
</html>
```
CSS代码:
```
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
h1 {
font-size: 4em;
text-align: center;
margin-top: 100px;
color: #333;
}
h2 {
font-size: 3em;
text-align: center;
margin-top: 50px;
color: #333;
}
h4 {
font-size: 2em;
text-align: center;
margin-top: 50px;
color: #333;
}
p {
font-size: 1.5em;
text-align: center;
margin: 0 auto;
width: 80%;
color: #666;
}
.bg-grey {
background-color: #f6f6f6;
}
.navbar {
margin-bottom: 0;
background-color: #ffffff;
z-index: 9999;
border: 0;
font-size: 1.2em !important;
line-height: 1.7em !important;
letter-spacing: 4px;
border-radius: 0;
}
.navbar li a, .navbar .navbar-brand {
color: #666 !important;
}
.navbar-nav li a:hover, .navbar-nav li.active a {
color: #333 !important;
background-color: #fff !important;
}
.navbar-default .navbar-toggle {
border-color: transparent;
color: #666 !important;
}
.container {
margin-top: 50px;
margin-bottom: 50px;
}
.btn-primary {
background-color: #333;
border-color: #333;
font-size: 1.5em;
letter-spacing: 2px;
margin-top: 50px;
margin-bottom: 50px;
}
.btn-primary:hover {
background-color: #666;
border-color: #666;
}
footer {
background-color: #333;
color: #fff;
padding: 20px;
}
```
阅读全文