前几天我看了看bootstrap,发觉里面的布局的css里有对各种不同情况下的屏幕分辨率有着规定,所以我就用这些css弄了一下适配的问题,因为以前看网页和自己写一点网页,对于适配总是很迷惑,所以我现在做一下,进行尝试一下。一下是我写的代码。我的代码写的不怎么漂亮,所以请见谅。
[html] view plain copy
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>bootstrap</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!-- 新 Bootstrap4 核心 CSS 文件 -->
- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
- <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
- <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
- <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
- <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
- <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
- <script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
- <!-- <link rel="stylesheet" type="text/css" href="dist/css/bootstrap-grid.css"> -->
- </head>
- <style type="text/css">
- #nav_l{padding: 3px;font-size: 20px;}
- #nav{border-bottom: solid 1px grey;}
- #ban{padding-top: 10px;}
- .overlay {
- height: 0%;
- width: 100%;
- position: fixed;
- z-index: 1;
- top: 0;
- left: 0;
- background-color: rgb(0,0,0);
- background-color: rgba(0,0,0, 0.9);
- overflow-y: hidden;
- transition: 0.5s;
- }
- .overlay-content {
- position: relative;
- top: 25%;
- width: 100%;
- text-align: center;
- margin-top: 30px;
- }
- .overlay a {
- padding: 8px;
- text-decoration: none;
- font-size: 36px;
- color: #818181;
- display: block;
- transition: 0.3s;
- }
- .overlay a:hover, .overlay a:focus {
- color: #f1f1f1;
- }
- .overlay .closebtn {
- position: absolute;
- top: 20px;
- right: 45px;
- font-size: 60px;
- }
- </style>
- <body>
- <div class="container">
- <div class="row">
- <div class="col-sm-2 d-none d-sm-block">
- <img src="http://placehold.it/200x120"/>
- </div>
- <div class="col-sm-8 d-none d-sm-block">
- <h3 align="center">This is a Test</h3>
- <h5 align="center"> this is for bootstrap</h5>
- </div>
- <div class="col-sm-2 d-none d-sm-block">
- <img src="http://placehold.it/200x120"/>
- </div>
- <div class="col-sm-12 d-block d-sm-none">
- <h3 align="center">This is a Test</h3>
- <h5 align="center"> this is for bootstrap</h5>
- </div>
- </div>
- <div class="row" style="height:50px;" id="nav">
- <!--div class="col-sm-1" id="nav_l"><a href="#">home</a></div>
- <div class="col-sm-1" id="nav_l"><a href="#">page</a></div>
- <div class="col-sm-1" id="nav_l"><a href="#">article</a></div>
- <div class="col-sm-1" id="nav_l"><a href="#">conection</a></div-->
- <div class="col-sm-12 d-none d-md-block">
- <ul class="nav nav-tabs " style="font-size: 18px;">
- <li class="nav-item"><a href="#" class="nav-link active" >home</a></li>
- <li class="nav-item"><a href="#" class="nav-link">page</a></li>
- <li class="nav-item"><a href="#" class="nav-link">article</a></li>
- <li class="nav-item"><a href="#" class="nav-link">conection</a></li>
- </ul>
- </div>
- <div class="col-sm-12 d-block d-md-none">
- <div id="myNav" class="overlay">
- <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
- <div class="overlay-content">
- <a href="#">home</a>
- <a href="#">page</a>
- <a href="#">article</a>
- <a href="#">connection</a>
- </div>
- </div>
- <span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ </span>
- </div>
- <script type="text/javascript">
- function openNav() {
- document.getElementById("myNav").style.height = "100%";
- }
- function closeNav() {
- document.getElementById("myNav").style.height = "0%";
- }
- </script>
- </div>
- <div class="row" id="ban" >
- <div class="carousel slide" data-ride="carousel" id="demo">
- <!-- <img src="http://placehold.it/1100x440"/> -->
- <ul class="carousel-indicators">
- <li data-target="#demo" class="active" data-slide-to="0"></li>
- <li data-target="#demo" data-slide-to="1"></li>
- <li data-target="#demo" data-slide-to="2"></li>
- </ul>
- <div class=" carousel-inner d-none d-md-block">
- <div class="carousel-item active"><img src="http://placehold.it/1100x440"/></div>
- <div class="carousel-item "><img src="http://placehold.it/1100x440"/></div>
- <div class="carousel-item "><img src="http://placehold.it/1100x440"/></div>
- </div>
- <div class=" carousel-inner ">
- <div class="carousel-item active"><img class="mw-100" src="http://placehold.it/1100x440"/></div>
- <div class="carousel-item "><img class="mw-100" src="http://placehold.it/1100x440"/></div>
- <div class="carousel-item "><img class="mw-100" src="http://placehold.it/1100x440"/></div>
- </div>
- <a href="#demo" class="carousel-control-prev" data-slide="prev">
- <span class="carousel-control-prev-icon" ></span>
- </a>
- <a href="#demo" class="carousel-control-next" data-slide="next">
- <span class="carousel-control-next-icon"></span>
- </a>
- </div>
- </div>
- <div class="row" style="margin-top: 10px;">
- <div class="col-sm-8">
- <img src="http://placehold.it/700x440"/ class="d-none d-md-block">
- <img src="http://placehold.it/700x440" class="mw-100 d-block d-md-none" />
- <h3><a href="#">Llamas: Great Pets or the Best Pets?</a></h3>
- <p>Intrepid reporter Jordan Humphreys went to Happy Time Llama Farm to investigate: are llamas merely great pets, or he best pets? Read the full article to find out!</p> <p><a href="#" class="small radius nice blue button">Read More →</a></p>
- </div>
- <div class="col-sm-4" >
- <div class="row">
- <div class="col-sm-6">
- <img src="http://placehold.it/160x150"/>
- </div>
- <div class="col-sm-6">
- <h5><a href="">Alpaca Farm Closed</a></h5>
- <p>Anthony Tadina reports on this tragic closing.<br /><a href="#">Read More →</a></p>
- </div>
- </div>
- <div class="row">
- <div class="col-sm-6">
- <img src="http://placehold.it/160x150"/>
- </div>
- <div class="col-sm-6">
- <h5><a href="">Alpaca Farm Closed</a></h5>
- <p>Anthony Tadina reports on this tragic closing.<br /><a href="#">Read More →</a></p>
- </div>
- </div>
- <div class="row">
- <div class="col-sm-6">
- <img src="http://placehold.it/160x150"/>
- </div>
- <div class="col-sm-6">
- <h5><a href="">Alpaca Farm Closed</a></h5>
- <p>Anthony Tadina reports on this tragic closing.<br /><a href="#">Read More →</a></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="container" style="border-top: solid 1px grey; padding-top: 10px;">
- <div class="row">
- <div class="col-sm-3">
- <img src="http://placehold.it/260x190" />
- <h5><a href="#">Feature 1</a></h5>
- <p>Description<br /><a href="#">Read More →</a></p>
- </div>
- <div class="col-sm-3">
- <img src="http://placehold.it/260x190" />
- <h5><a href="#">Feature 1</a></h5>
- <p>Description<br /><a href="#">Read More →</a></p>
- </div>
- <div class="col-sm-3">
- <img src="http://placehold.it/260x190" />
- <h5><a href="#">Feature 1</a></h5>
- <p>Description<br /><a href="#">Read More →</a></p>
- </div>
- <div class="col-sm-3">
- <img src="http://placehold.it/260x190" />
- <h5><a href="#">Feature 1</a></h5>
- <p>Description<br /><a href="#">Read More →</a></p>
- </div>
- </div>
- <div class="row"><p><strong>The Foundation Times</strong><br />© 2025 no rights reserved.</p></div>
- </div>
- </body>
- </html>