vue頁面經(jīng)典布局

一、 上中下

<template>
    <div class="layout" id="layout" ref="layout" :style="`width:${width}px;height:${height}px`">
        <div class="layout-header" :style="`width:${width}px;height:${headerHeight}px`"></div>
        <div class="layout-main" :style="`width:${width}px;height:${mainHeight}px`">
            <div class="layout-main-content">
                <div v-for="i in 100" :key="i">{{i}}</div>
            </div>
        </div>
        <div class="layout-footer" :style="`width:${width}px;height:${footerHeight}px`"></div>
    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component({
    components: {}
})
export default class Layout extends Vue {
    height = 0

    width = 0

    headerHeight = 60

    mainHeight = 0

    footerHeight = 10

    mounted() {
        this.$nextTick(() => {
            this.width = window.innerWidth
            this.height = window.innerHeight
            this.mainHeight =
                this.height - this.headerHeight - this.footerHeight
        })

        window.onresize = () => {
            return (() => {
                this.width = window.innerWidth
                this.height = window.innerHeight
                this.mainHeight =
                    this.height - this.headerHeight - this.footerHeight
            })()
        }
    }
}
</script>

<style lang="scss" scoped>
.layout {
    background: darkcyan;

    .layout-header {
        background: darkgoldenrod;
    }

    .layout-main {
        background: darkorchid;

        overflow-y: auto;
        white-space: nowrap;

        .layout-main-content {
            width: 100%;
            white-space: nowrap;
            // justify-content: flex-start;
            // display: flex;
            // align-items: center;
        }
    }

    .layout-footer {
        background: darkseagreen;
    }
}
</style>

  1. 可以直接設(shè)置header的高度
  2. 可以直接設(shè)置footer的高度
  3. main里面的內(nèi)容寫到content里面坝撑,進(jìn)行滾動條滾動

二、 左 右(上中下)

<template>
    <div class="layout" id="layout" ref="layout" :style="`width:${width}px;height:${height}px`">
        <div class="layout-left" :style="`width:${leftWidth}px;height:${height}px`">
            <div class="layout-left-logo" :style="`width:${leftWidth}px;height:${headerHeight}px`"></div>
            <div class="layout-left-menu" :style="`width:${leftWidth}px;height:${mainHeight+footerHeight}px`"></div>
        </div>

        <div class="layout-right" :style="`width:${rightWidth}px;height:${height}px`">
            <div class="layout-header" :style="`width:${rightWidth}px;height:${headerHeight}px`"></div>
            <div class="layout-main" :style="`width:${rightWidth}px;height:${mainHeight}px`">
                <div class="layout-main-content">
                    <div v-for="i in 100" :key="i">{{i}}</div>
                </div>
            </div>
            <div class="layout-footer" :style="`width:${rightWidth}px;height:${footerHeight}px`"></div>
        </div>

    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'

@Component({
    components: { }
})
export default class Layout extends Vue {
    height = 0

    width = 0

    leftWidth = 100

    rightWidth = 0

    headerHeight = 100

    mainHeight = 0

    footerHeight = 0

    mounted() {
        this.$nextTick(() => {
            this.width = window.innerWidth
            this.height = window.innerHeight
            this.mainHeight =
                this.height - this.headerHeight - this.footerHeight
            this.rightWidth = this.width - this.leftWidth
        })

        window.onresize = () => {
            return (() => {
                this.width = window.innerWidth
                this.height = window.innerHeight
                this.mainHeight =
                    this.height - this.headerHeight - this.footerHeight
                this.rightWidth = this.width - this.leftWidth
            })()
        }
    }
}
</script>

<style lang="scss" scoped>
.layout {
    background: darkcyan;
    display: flex;

    .layout-left {
        background: rgb(224, 123, 123);

        .layout-left-logo {
            background: rgb(107, 202, 150);
        }

        .layout-left-menu {
            background: rgb(107, 145, 202);
        }
    }

    .layout-right {
        background: rgb(200, 247, 114);

        .layout-header {
            background: darkgoldenrod;
        }

        .layout-main {
            background: darkorchid;

            overflow-y: auto;
            white-space: nowrap;

            .layout-main-content {
                width: 100%;
                white-space: nowrap;
                // justify-content: flex-start;
                // display: flex;
                // align-items: center;
            }
        }

        .layout-footer {
            background: darkseagreen;
        }
    }
}
</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末粮揉,一起剝皮案震驚了整個濱河市巡李,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌扶认,老刑警劉巖侨拦,帶你破解...
    沈念sama閱讀 222,104評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異辐宾,居然都是意外死亡狱从,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,816評論 3 399
  • 文/潘曉璐 我一進(jìn)店門叠纹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來矫夯,“玉大人,你說我怎么就攤上這事吊洼。” “怎么了制肮?”我有些...
    開封第一講書人閱讀 168,697評論 0 360
  • 文/不壞的土叔 我叫張陵冒窍,是天一觀的道長递沪。 經(jīng)常有香客問我,道長综液,這世上最難降的妖魔是什么款慨? 我笑而不...
    開封第一講書人閱讀 59,836評論 1 298
  • 正文 為了忘掉前任,我火速辦了婚禮谬莹,結(jié)果婚禮上檩奠,老公的妹妹穿的比我還像新娘。我一直安慰自己附帽,他們只是感情好埠戳,可當(dāng)我...
    茶點故事閱讀 68,851評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蕉扮,像睡著了一般整胃。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上喳钟,一...
    開封第一講書人閱讀 52,441評論 1 310
  • 那天屁使,我揣著相機(jī)與錄音,去河邊找鬼奔则。 笑死蛮寂,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的易茬。 我是一名探鬼主播酬蹋,決...
    沈念sama閱讀 40,992評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼疾呻!你這毒婦竟也來了除嘹?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,899評論 0 276
  • 序言:老撾萬榮一對情侶失蹤岸蜗,失蹤者是張志新(化名)和其女友劉穎尉咕,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體璃岳,經(jīng)...
    沈念sama閱讀 46,457評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡年缎,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,529評論 3 341
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了铃慷。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片单芜。...
    茶點故事閱讀 40,664評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖犁柜,靈堂內(nèi)的尸體忽然破棺而出洲鸠,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 36,346評論 5 350
  • 正文 年R本政府宣布扒腕,位于F島的核電站绢淀,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏瘾腰。R本人自食惡果不足惜皆的,卻給世界環(huán)境...
    茶點故事閱讀 42,025評論 3 334
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望蹋盆。 院中可真熱鬧费薄,春花似錦、人聲如沸栖雾。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,511評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽岩灭。三九已至拌倍,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間噪径,已是汗流浹背柱恤。 一陣腳步聲響...
    開封第一講書人閱讀 33,611評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留找爱,地道東北人梗顺。 一個月前我還...
    沈念sama閱讀 49,081評論 3 377
  • 正文 我出身青樓,卻偏偏與公主長得像车摄,于是被迫代替她去往敵國和親寺谤。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,675評論 2 359

推薦閱讀更多精彩內(nèi)容

  • 本文主要講述頁面布局樣式方面涉及的知識點吮播,更全面的對CSS相應(yīng)的技術(shù)進(jìn)行歸類变屁、整理、說明意狠,沒有特別詳細(xì)的技術(shù)要點說...
    Joel_zh閱讀 869評論 0 1
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5粟关? 答:HTML5是最新的HTML標(biāo)準(zhǔn)。 注意:講述HT...
    kismetajun閱讀 27,518評論 1 45
  • 為了提高工作效率环戈,不在CSS布局上多次耗費時間闷板,故記錄此練習(xí)筆記。借鑒了大神【浪里行舟】的博客院塞,文末有鏈接遮晚。 CS...
    月上秦少閱讀 1,118評論 2 13
  • 前言 面試題是永遠(yuǎn)都準(zhǔn)備不完的O厍病!!R樟帷括蝠! 前端常見的一些問題 1.前端性能優(yōu)化手段? 1. 盡可能使用雪碧圖 2....
    六月_7300閱讀 481評論 0 1
  • 前言 面試題是永遠(yuǎn)都準(zhǔn)備不完的8樽尽C胧帷!;佟酪碘! 前端常見的一些問題 1.前端性能優(yōu)化手段? 1. 盡可能使用雪碧圖2. ...
    ZJ懶得寫簡書閱讀 10,517評論 22 266