前端技术Bootstrap的hello world

简介:

----对于用户来说,界面就是程序本身。那么一个漂亮的web一定是你继续使用这个应用的前题。

 

这一节我们来一起写个Bootstrap的hello wrold。

Bootstrap 

Bootstrap 是最受欢迎的 HTML、CSS 和 JS 框架,用于开发响应式布局、移动设备优先的 WEB 项目。

 

 

如何使用Bootstrap?                                             

 

Bootstrap的使用一般有两种方法。一种是引用在线的Bootstrap的样式,一种是将Bootstrap下载到本地进行引用。

 

引用在线样式:

引用在线样式的好处就是不用本地安装Bootstrap,也是不用考虑引用时的路径问题。缺点是担心性能问题,一旦在线样式挂了,那么自己的网站页面样式也就乱掉了。

http://v3.bootcss.com/getting-started/#download

Bootstrap中文网为 Bootstrap 专门构建了自己的免费 CDN 加速服务。

使用方法非常简单:

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Hello Bootstrap</title>
    <!-- Bootstrap core CSS -->
    <link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        <h1>hello Bootstrap<h1>
    </body>
</html>
复制代码

<link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">  这一行已经将在线的样式引进来了。注意本文使用的是当前最新的Bootstrap3.2.0。

 

使用本地的Bootstrap

下载Bootstrap到本地进行解压,解压完成,你将得到一个Bootstrap目录,结构如下:

复制代码
bootstrap/
├── css/
│   ├── bootstrap.css
│   ├── bootstrap.min.css
│   ├── bootstrap-theme.css
│   └── bootstrap-theme.min.css
├── js/
│   ├── bootstrap.js
│   └── bootstrap.min.js
└── fonts/
    ├── glyphicons-halflings-regular.eot
    ├── glyphicons-halflings-regular.svg
    ├── glyphicons-halflings-regular.ttf
    └── glyphicons-halflings-regular.woff
复制代码

本地调用如下:

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Hello Bootstrap</title>
    <!-- Bootstrap core CSS -->
    <link href="./bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet">
    <style type='text/css'>
      body {
        background-color: #CCC;
      }
    </style>
    </head>
    <body>
        <h1>hello Bootstrap<h1>
    </body>
</html>
复制代码

<link href="./bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet">  --表示引入当前目录下的Bootstrap样式。

<link href="D:/bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet"> --当然也可以使用绝对路径。

我们多加了一个背景色效果如下:

 

 

下面利用Bootstrap的样式编写一个网站出来。

 

 

添加导航行栏和登录框                                           

 

复制代码
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">首页</a>
          <a class="navbar-brand" href="#">测试</a>
          <a class="navbar-brand" href="#">开发</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right" role="form">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">Sign in</button>
          </form>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>
复制代码

浏览器效果如下:

 

 

添加一篇文章                                                        

 

复制代码
    <div class="jumbotron">
      <div id='content' class='row-fluid'>
        <h2>Hello, world!</h2>
        <p class="blog-post-meta">January 1, 2014 by <a href="#">Mark</a></p>
        <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
        <p><a class="btn btn-primary btn-lg" role="button">阅读全文 &raquo;</a></p>
      </div>
    </div>
复制代码

浏览器效果如下:

 

 

添加底部介绍与友情链接                                            

 

复制代码
<div class="col-sm-3 col-sm-offset-1 blog-sidebar">
          <div class="sidebar-module sidebar-module-inset">
            <h4>About</h4>
            <p>Etiam porta <em>sem malesuada magna</em> mollis euismod. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur.</p>
          </div>
          <div class="sidebar-module">
            <h4>Elsewhere</h4>
            <ol class="list-unstyled">
              <li><a href="#">博客园</a></li>
              <li><a href="#">开源中国</a></li>
              <li><a href="#">infoq</a></li>
            </ol>
          </div>
    </div>
复制代码

最终效果如下:

 

完整代码:

  View Code

 

 

样式的继承                                                          

 

你一定很好奇,这些样式是怎么玩的?如何你细心的就会留意到div 标签的class属性。

通过class的属性值去继承Bootstrap的样式定义,那么就达到了某种样式效果。

复制代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta charset="utf-8" /> 
    <title>自定义样式</title>
    <!--自定义侧边栏样式-->
    <style> 
        .divcss5-right{width:320px; height:120px;border:1px solid #F00;float:right}
    </style> 
</head> 
<body>
    <!--class属性引用自定义样式--> 
    <div class="divcss5-right">
        <h4>友情链接:</h4>
            <ol class="list-unstyled">
              <li><a href="#">博客园</a></li>
              <li><a href="#">开源中国</a></li>
              <li><a href="#">infoq</a></li>
            </ol>
    </div> 
</body> 
</html> 
复制代码

玩前端就是要不断的修改里面的属性或信息,然后看浏览器上的展示效果。

 

 

目录
相关文章
|
10天前
|
前端开发 JavaScript 关系型数据库
从前端到后端:构建现代化Web应用的技术探索
在当今互联网时代,Web应用的开发已成为了各行各业不可或缺的一部分。从前端到后端,这篇文章将带你深入探索如何构建现代化的Web应用。我们将介绍多种技术,包括前端开发、后端开发以及各种编程语言(如Java、Python、C、PHP、Go)和数据库,帮助你了解如何利用这些技术构建出高效、安全和可扩展的Web应用。
|
29天前
|
XML 前端开发 JavaScript
AJAX 前端开发利器:实现网页动态更新的核心技术
**AJAX** 允许网页在不刷新的情况下更新内容,实现异步与服务器交换数据。通过JavaScript的XMLHttpRequest对象,可发送和接收数据。当用户触发事件(如点击),函数向服务器发送GET请求,服务器响应后更新指定HTML部分。AJAX并非编程语言,而是利用浏览器内置对象、JavaScript和DOM技术。核心是XMLHttpRequest对象,它有多种方法(如`open()`和`send()`)和属性(如`onreadystatechange`、`readyState`和`status`)来处理请求和响应。
52 2
AJAX 前端开发利器:实现网页动态更新的核心技术
|
1月前
|
机器学习/深度学习 前端开发 搜索推荐
未来趋势下的前端开发技术探索
随着人工智能和物联网技术的快速发展,前端开发领域也面临着新的挑战和机遇。本文将探讨未来趋势下前端开发技术的发展方向和应用场景,为广大前端开发者提供启示与思路。
|
1月前
|
存储 前端开发 JavaScript
从前端到后端,探索现代Web开发技术
本文探索了现代Web开发技术的各个方面,包括前端和后端开发以及多种编程语言的应用。通过对JavaScript、Java、Python、C、PHP和Go等语言的介绍,深入探讨了前端和后端开发的基本原理和常用工具。同时,还涵盖了数据库技术在Web开发中的重要性和应用场景。无论你是初学者还是有经验的开发者,本文都能为你提供全面的视角和实用的知识,帮助你在Web开发领域取得更好的成果。
|
6天前
|
前端开发 算法 JavaScript
如何优化前端性能:探索图片压缩与延迟加载技术
本文深入探讨了前端性能优化中的关键问题:图片压缩与延迟加载技术。通过介绍图片压缩的原理和方法,并结合实例说明了如何有效减少图片大小、提升加载速度;同时,详细解析了延迟加载技术的实现原理及其在提高页面加载性能中的作用,为前端开发者提供了实用的优化方案。
|
20天前
|
编解码 前端开发 JavaScript
探索前端开发中的新趋势:WebAssembly 技术应用与展望
本文将深入探讨前端开发中的新趋势——WebAssembly 技术,介绍其在前端领域的应用场景和优势,并展望未来在前端开发中的潜在影响。通过对 WebAssembly 技术的原理解析和实际案例分析,帮助读者更好地了解并应用这一新兴技术。
|
28天前
|
前端开发 JavaScript NoSQL
从前端到后端:构建全栈开发的技术生态
本文将探讨如何在全栈开发中构建完整的技术生态,从前端到后端各个层面进行深入剖析,讨论不同技术之间的协作与整合,为开发人员提供全面的指导与启示。
|
1月前
|
前端开发 JavaScript Java
|
1月前
|
机器学习/深度学习 人工智能 前端开发
探索未来的前端开发趋势:WebAssembly 技术的崛起
随着互联网的快速发展,前端开发的需求也日益增长。本文将深入探讨一项引起广泛关注的新兴技术——WebAssembly,探索其在前端开发中的应用以及对未来的影响。
|
1月前
|
Rust 前端开发 vr&ar
未来前端技术发展趋势分析
在数字化时代,前端技术一直处于快速发展的状态。本文将从WebAssembly、PWA、AR/VR等方面探讨未来前端技术的发展趋势,为读者揭示前端技术的新篇章。