有趣的CSS盒子模型——【牛腩新聞發布系統】,css新聞發布系統

來源:互聯網
上載者:User

有趣的CSS盒子模型——【牛腩新聞發布系統】,css新聞發布系統


前言

  傳統的表格排版是通過大小不一的表格和表格嵌套來定位排版網頁內容,改用css排版後,通過由css定義的大小不一的盒子和盒子嵌套來編排網頁。css盒子模型是div排版的核心。

  說白了就是以前沒用css盒子模型,html中的元素就像一堆散亂的蘋果;用了之後,就變成整箱整箱的蘋果摞到一起。這種方式排版的網頁,代碼簡潔,更新方便,容易相容多種瀏覽器。


    



css盒子模型元素和計算

  通過定義一系列與盒子相關的屬性(內容content、填充padding、邊框border、邊界margin)來控制各個盒子乃至整個HTML文檔的表現效果和布局結構,每個屬性都包括上、右、下、左(順時針)。

  下面的是一個標準盒子模型的詳圖:



  由可知:

盒子實際寬度:margin-left + border-left + padding-left + width + padding-right + border-right + margin-right

盒子實際高度:margin-top + border-top + padding-top + height + padding-bottom + border-bottom + margin-bottom 



執行個體

  下面是我做的一個小DEMO,css代碼和firebug是對上面盒子模型計算的一個驗證。以Firefox為例,F12對應的HTML下的布局就是對盒子模型的可視化應用。


  DEMO.aspx代碼

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DEMO.aspx.cs" Inherits="牛腩新聞發布系統WM.DEMO" %><!DOCTYPE html><!---建立人:王美建立時間:2015-02-25 11:25:35--><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title></title>    <link href="css/common.css" rel="stylesheet" /></head><body>    <form id="form1" runat="server">    <div>        <div class="box">nice to meet you!</div>                             </div>    </form></body></html>


  common.css代碼

/*    建立人:王美    *//*實驗1*/.box{   background:black;   color:white ;   width:100px;   height:100px;   padding :10px;   border:20px solid pink;   margin:30px;   float:right ;}


  、firebug




結語

  有些貌似複雜的東西,會在我們一點一點分析和實踐中,變的生動而有趣。實踐出真知,自古如此。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.