美文网首页
前端笔记--HTML-2

前端笔记--HTML-2

作者: 吃饱喝足搬代码丶 | 来源:发表于2018-04-22 17:09 被阅读0次
    html类:

    对 HTML 进行分类(设置类),使我们能够为元素的类定义 CSS 样式。
    为相同的类设置相同的样式,或者为不同的类设置不同的样式。
    分类块级元素
    HTML <div> 元素是块级元素。它能够用作其他 HTML 元素的容器。
    设置 <div> 元素的类,使我们能够为相同的 <div> 元素设置相同的类:

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .cities {
        background-color:black;
        color:white;
        margin:20px;
        padding:20px;
    } 
    </style>
    </head>
    
    <body>
    
    <div class="cities">
    <h2>London</h2>
    <p>London is the capital city of England. 
    It is the most populous city in the United Kingdom, 
    with a metropolitan area of over 13 million inhabitants.</p>
    </div>
    
    <div class="cities">
    <h2>Paris</h2>
    <p>Paris is the capital and most populous city of France.</p>
    </div>
    
    <div class="cities">
    <h2>Tokyo</h2>
    <p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
    and the most populous metropolitan area in the world.</p>
    </div>
    
    </body>
    </html>
    
    运行:

    分类行内元素
    HTML <span> 元素是行内元素,能够用作文本的容器。
    设置 <span> 元素的类,能够为相同的 <span> 元素设置相同的样式。

    <!DOCTYPE html>
    <html>
    <head>
    <style>
      span.red {color:red;}
    </style>
    </head>
    <body>
    
    <h1>My <span class="red">Important</span> Heading</h1>
    
    </body>
    </html>
    
    运行:
    html布局

    使用div进行布局:

    <!DOCTYPE html>
    <html>
    
    <head>
    <style>
    #header {
        background-color:black;
        color:white;
        text-align:center;
        padding:5px;
    }
    #nav {
        line-height:30px;
        background-color:#eeeeee;
        height:300px;
        width:100px;
        float:left;
        padding:5px;          
    }
    #section {
        width:350px;
        float:left;
        padding:10px;        
    }
    #footer {
        background-color:black;
        color:white;
        clear:both;
        text-align:center;
       padding:5px;      
    }
    </style>
    </head>
    
    <body>
    
    <div id="header">
    <h1>City Gallery</h1>
    </div>
    
    <div id="nav">
    London<br>
    Paris<br>
    Tokyo<br>
    </div>
    
    <div id="section">
    <h2>London</h2>
    <p>
    London is the capital city of England. It is the most populous city in the United Kingdom,
    with a metropolitan area of over 13 million inhabitants.
    </p>
    <p>
    Standing on the River Thames, London has been a major settlement for two millennia,
    its history going back to its founding by the Romans, who named it Londinium.
    </p>
    </div>
    
    <div id="footer">
    Copyright ? W3Schools.com
    </div>
    
    </body>
    </html>
    
    运行:

    使用html5的网站布局:
    header 定义文档或节的页眉
    nav 定义导航链接的容器
    section 定义文档中的节
    article 定义独立的自包含文章
    aside 定义内容之外的内容(比如侧栏)
    footer 定义文档或节的页脚
    details 定义额外的细节
    summary 定义 details 元素的标题

    <!DOCTYPE html>
    <html>
    
    <head>
    <style>
    header {
        background-color:black;
        color:white;
        text-align:center;
        padding:5px;     
    }
    nav {
        line-height:30px;
        background-color:#eeeeee;
        height:300px;
        width:100px;
        float:left;
        padding:5px;          
    }
    section {
        width:350px;
        float:left;
        padding:10px;        
    }
    footer {
        background-color:black;
        color:white;
        clear:both;
        text-align:center;
        padding:5px;         
    }
    </style>
    </head>
    
    <body>
    
    <header>
    <h1>City Gallery</h1>
    </header>
    
    <nav>
    London<br>
    Paris<br>
    Tokyo<br>
    </nav>
    
    <section>
    <h1>London</h1>
    <p>
    London is the capital city of England. It is the most populous city in the United Kingdom,
    with a metropolitan area of over 13 million inhabitants.
    </p>
    <p>
    Standing on the River Thames, London has been a major settlement for two millennia,
    its history going back to its founding by the Romans, who named it Londinium.
    </p>
    </section>
    
    <footer>
    Copyright W3Schools.com
    </footer>
    
    </body>
    </html>
    

    运行效果同上。
    使用表格的html布局:
    <table> 元素不是作为布局工具而设计的。
    <table> 元素的作用是显示表格化的数据。
    使用 <table> 元素能够取得布局效果,因为能够通过 CSS 设置表格元素的样式:

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    table.lamp {
        width:100%;
        border:1px solid #d4d4d4;
    }
    table.lamp th, td { 
        padding:10px;
    }
    table.lamp th {
        width:40px;
    }
    
    </style>
    </head>
    
    <body>
     
    <table class="lamp">
    <tr>
      <th>
        <img src="/images/lamp.jpg" alt="Note" style="height:32px;width:32px">
      </th>
      <td>
        The table element was not designed to be a layout tool.
      </td>
    </tr>
    </table>
    
    </body>
    </html>
    
    html内联框架

    iframe 用于在网页内显示网页,定义内联的子窗口(框架)。

    <html>
    <body>
    
    <iframe src="/example/html/demo_iframe.html" width="200" height="200" frameborder="0" name="iframe_a"></iframe>
    
    <p><a href="http://www.w3school.com.cn" target="iframe_a">W3School.com.cn</a></p>
    
    <p><b>注释:</b>由于链接的目标匹配 iframe 的名称,所以链接会在 iframe 中打开。</p>
    <p>某些老式的浏览器不支持内联框架。</p>
    <p>如果不支持,则 iframe 是不可见的。</p>
    
    </body>
    
    运行:
    html脚本

    <script> 标签用于定义客户端脚本,比如 JavaScript。script 元素既可包含脚本语句,也可通过 src 属性指向外部脚本文件。必需的 type 属性规定脚本的 MIME 类型。JavaScript 最常用于图片操作、表单验证以及内容动态更新。

    <noscript> 标签提供无法使用脚本时的替代内容,比方在浏览器禁用脚本时,或浏览器不支持客户端脚本时。noscript 元素可包含普通 HTML 页面的 body 元素中能够找到的所有元素。

    <body>
    
    <script type="text/javascript">
    document.write("Hello World!")
    </script>
    <noscript>Sorry, your browser does not support JavaScript!</noscript>
    
    <p>不支持 JavaScript 的浏览器将显示 noscript 元素中的文本。</p>
     
    </body>
    
    运行:
    html头部

    元数据(metadata)是关于数据的信息。
    <meta> 标签提供关于 HTML 文档的元数据。元数据不会显示在页面上,但是对于机器是可读的。
    典型的情况是,meta 元素被用于规定页面的描述、关键词、文档的作者、最后修改时间以及其他元数据。<meta> 标签始终位于 head 元素中。元数据可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 web 服务。

    一些搜索引擎会利用 meta 元素的 name 和 content 属性来索引您的页面。
    定义页面的描述:<meta name="description" content="Free Web tutorials on HTML, CSS, XML" />
    定义页面的关键词:<meta name="keywords" content="HTML, CSS, XML" />

    <base> 标签为页面上的所有链接规定默认地址或默认目标(target):

    <head>
    <base href="http://www.w3school.com.cn/images/" />
    <base target="_blank" />
    </head>
    
    <head>  定义关于文档的信息。
    <title> 定义文档标题。
    <base>  定义页面上所有链接的默认地址或默认目标。
    <link>  定义文档与外部资源之间的关系。
    <meta>  定义关于 HTML 文档的元数据。
    <script>    定义客户端脚本。
    <style> 定义文档的样式信息。
    

    html字符实体:


    html URL
    当您点击 HTML 页面中的某个链接时,对应的 <a> 标签指向万维网上的一个地址。
    统一资源定位器(URL)用于定位万维网上的文档(或其他数据)。
    网址遵守以下的语法规则:scheme://host.domain:port/path/filename

    解释:
    scheme - 定义因特网服务的类型。最常见的类型是 http
    host - 定义域主机(http 的默认主机是 www)
    domain - 定义因特网域名,比如 w3school.com.cn
    :port - 定义主机上的端口号(http 的默认端口号是 80)
    path - 定义服务器上的路径(如果省略,则文档必须位于网站的根目录中)。
    filename - 定义文档/资源的名称

    以下是其中一些最流行的 scheme:
    http 超文本传输协议 以 http:// 开头的普通网页。不加密。
    https 安全超文本传输协议 安全网页。加密所有信息交换。
    ftp 文件传输协议 用于将文件下载或上传至网站。
    file 您计算机上的文件。

    相关文章

      网友评论

          本文标题:前端笔记--HTML-2

          本文链接:https://www.haomeiwen.com/subject/gdcflftx.html