css常見的各種佈局上(兩列佈局)

来源:https://www.cnblogs.com/czkolve/archive/2019/04/14/10698682.html
-Advertisement-
Play Games

常見的佈局上(兩列佈局) 1.常見的兩列佈局 1.1左邊固定,右邊自適應,左邊寬度已知,右邊預設占滿整行,使用left 左浮動,右邊不浮動,設置margin-left:左側寬度 1.2右側固定,寬度已知,左側自適應,記住固定的區域一定要放自適應區域的右邊, 單列固定都是比較簡單的還有嵌套一層div方 ...


  常見的佈局上(兩列佈局

    1.常見的兩列佈局

      1.1左邊固定,右邊自適應,左邊寬度已知,右邊預設占滿整行,使用left 左浮動,右邊不浮動,設置margin-left:左側寬度

<style>
        .box{
            overflow: hidden;
            height: 500px;
            background-color: bisque;
        }
        .box .box-left {
            margin-left: 10px;
            width: 200px;
            min-height: 100%;
            float: left;
            background-color: pink;
        }
        .box .box-right {
            margin-left: 220px;
            margin-right: 10px;
            height: 100%;
            background-color: green;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>
<div class="box"> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客戶的感慨的沙發電視櫃很多水果和客戶的感慨大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
    </div>

      1.2右側固定,寬度已知,左側自適應,記住固定的區域一定要放自適應區域的右邊,

.box{
            height: 500px;
            background-color: bisque;
            position: relative;
        }
        .box .box-right {
            float: right;
            width: 200px;
            min-height: 100%;
            margin-right: 10px;
            background-color: pink;
        }
        .box .box-left {
            margin-left: 10px;
            margin-right: 220px;
            height: 100%;
            background-color: green;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
<div class="box"> 
        <div class="box-right">
            11
        </div>
        <div class="box-left">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨大蘇打撒郭德綱你只是  
        第三個大概瞭解斯大林經過拉絲幾個垃圾
</div> </div>

    單列固定都是比較簡單的還有嵌套一層div方式,還有彈性佈局方式,還有grid佈局,都能實現單側固定

    1.3 嵌套一層div ,左側固定,右側自適應佈局,使用雙浮動,右側自適應先寫入,左側使用margin-left:-100%

      不嵌套一層div,右側直接使用margin-left:左側寬度也是可以的(這個代碼就不寫了,和第一個差不多)

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
            overflow: hidden;
        }
        .box .box-right {
            float: left;
            margin-left: -100%;
            width: 200px;
            min-height: 100%;
            background-color: pink;
        }
        .box .box-left {
            float: left;
            width: 100%;
            height: 100%;
            background-color: green;
        }
        .box .box-left .son {
            margin-left: 210px;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>

<body>
    <header>

    </header>
    <div class="box"> 
        <div class="box-left">
            <div class="son">
                1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨大蘇打撒郭德綱你只是 
           第三個大概瞭解斯大林經過拉絲幾個垃圾
</div> </div> <div class="box-right"> 11 </div> </div> <footer> </footer> </body>

    1.4 t彈性佈局

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
            display: flex;
        }
        .box .box-left {
            margin-left: 10px;
            flex: 0 0 200px; /* 參數分別是 放大,縮小 初始大小 */
            background-color: pink;
        }
        .box .box-right {
            margin-left: 10px;
            margin-right: 10px;
            height: 100%;
            background-color: green;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>
<body>
    <header>

    </header>
    <div class="box"> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
        大蘇打撒郭德綱你只是 第三個大概瞭解斯大林經過拉絲幾個垃圾
</div> </div> <footer> </footer> </body>

    1.5 grid佈局,grid相對於flex的話屬於二維佈局,可以定義行數,定義列數,定義行高列高,寬度也可以自適應,設置父容器的display:grid。grid 有很大的相容性問題。慎用

      使用grid 相當於設置行數為1,列數為2的grid佈局,使用grid可以很容易實現九宮格佈局

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
            display: grid;
            padding: 0 10px;
            grid-template-rows: 1fr;
            grid-template-columns: 200px auto;
            grid-gap: 10px;
        }
        .box .box-left {
            background-color: pink;
        }
        .box .box-right {
            background-color: green;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>
<body>
    <header>

    </header>
    <div class="box"> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
        大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
    </div>
    <footer>

    </footer>
</body>

    使用grid實現9宮格佈局

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
            display: grid;
            padding: 0 10px;
            grid-template-rows: 1fr 1fr 1fr;
            grid-template-columns: 1fr 1fr 1fr;
            grid-gap: 10px;
        }
        .box .box-left {
            background-color: pink;
        }
        .box .box-right {
            background-color: green;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>
<body>
    <header>

    </header>
    <div class="box"> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
        大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
        大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
        大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
        大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
        <div class="box-left">
            11
        </div>
    </div>
    <footer>

    </footer>
</body>
View Code

    1.6 使用定位實現左側固定右側自適應佈局,

      1.6.1使用相對定位,該佈局,左側固定div 的高度已知,

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
        }
        .box .box-left {
            margin-left: 10px;
            width: 200px;
            height: 400px;
            background-color: pink;
        }
        .box .box-right {
            position: relative;
            top: -100%;
            margin-left: 220px;
            height: 100%;
            background-color: green;
            margin-right: 10px;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>
<body>
    <header>

    </header>
    <div class="box"> 
        <div class="box-left">
            11
        </div>
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
            大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
    </div>
    <footer>

    </footer>
</body>
View Code

      1.6.2 使用相對定位實現左側固定,右側自適應,div高度未知,將自適應的模塊放前面,固定寬度div設置top:-100%

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
        }
        .box .box-left {
            position: relative;
            top: -100%;
            margin-left: 10px;
            width: 200px;
            height: 400px;
            background-color: pink;
        }
        .box .box-right {
            margin-left: 220px;
            height: 100%;
            background-color: green;
            margin-right: 10px;
        }
        header,footer {
            height: 75px;
            background-color: aqua;
        }
    </style>
<body>
    <header>

    </header>
    <div class="box"> 
        <div class="box-right">
            1shishsihsishsihi是不變的沙發電視櫃很多水果和客1111111111111111111111戶的感慨的沙發電視櫃很多水果和客戶的感慨
            大蘇打撒郭德綱你只是  第三個大概瞭解斯大林經過拉絲幾個垃圾
        </div> 
        <div class="box-left">
            11
        </div>
    </div>
    <footer>

    </footer>
</body>
View Code

      1.6.3 使用絕對定位,兩個模塊都使用絕對定位,可以不使用浮動

<style>
        .box{
            height: 500px;
            background-color: bisque;
            position: relative;
        }
        .box .box-left {
            position: absolute;
            margin-left: 10px;
            width: 200px;
            height: 400px;
            background-color: pink;
        }
        .box .box-right {
            position: absolute;
            margin-left:	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 日常項目中,經常遇到一些表情雨/金幣雨/彩帶雨 等下落的動畫,之前做android原生的時候,寫過類似的效果,主要通過自定義view 在 里繪製下落的過程,具體可以看下我的這篇github地址 "android 仿微信表情雨下落" ,現在轉戰 ,同樣可以實現這樣的效果,主要用到的動畫庫 "react ...
  • 這個世界唯一不變的可能就是變化,歷史的車輪滾滾向前,它不會因任何人的消極緩慢而停止。時代拋棄你時,連一聲再見都不會說。 從最開始的Javascrpit、到後來的Jquery、(ExtJs、EasyUI、MiniUI)、Bootstrap、Layui,再到如今的mvvm框架(Vue.js、Angula ...
  • HTML標記語言,網頁製作的第一步。 什麼是HTML呢?查百度 基礎語法 常用標簽 HTML是超文本標記語言,HTML不用編譯,直接在瀏覽器中執行,HTML是一個文本文件。 HTML基本結構,標簽,元素,屬性,註解 標簽屬性格式: 文檔類型聲明: 編碼文件 標題標簽,段落標簽,預格式化標簽,水平線 ...
  • DOM編程 首先,需要明確JavaScript訪問DOM性能的開銷所在。在瀏覽器中。對於DOM和ECMAScript的支持一般是各自獨立實現的,因此通過ECMAScript訪問DOM自然而然就會產生較大的開銷,而且對於DOM的訪問越頻繁,性能的開銷越大。 儘量將運算放在ECMAScript中進行,避 ...
  • 前端通過請求獲取數據流生成文檔文件的方式是一種開發下載文檔的方式,那麼在前端如何將數據流轉成文檔呢?代碼如下 ...
  • 1引言 HTTP是一個屬於應用層的面向對象的協議,由於其簡捷、快速的方式,適用於分散式超媒體信息系統。它於1990年提出,經過幾年的使用與發展,得到不斷地完善和擴展。目前在WWW中使用的是HTTP/1.0的第六版,HTTP/1.1的規範化工作正在進行之中,而且HTTP-NG(Next Generat ...
  • 前端性能優化一直是前端工作中必不可少的一部分,但是我們如何知道哪些部分的性能有優化的空間呢?此時,Chrome 性能監測就派上用場了。 正所謂:知己知彼,百戰百勝,只有確定了性能瓶頸,才能有條不紊地進行前端性能優化工作。 Performance Performance 是 Chrome 開發者工具中 ...
  • vue或element-ui有的時候tab列表裡需要編輯一些東西,使用後臺分頁是需要調介面的,這個時候你編輯的東西翻頁後就不存在了,就需要拿到所有數據後在前端進行分頁,數據就不會丟失了,這個時候就可以把編輯後的數據一起傳給後臺。 this.settlementData這裡是介面拿回來的所有數據, 然 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...