vue3【实战】语义化首页布局

在这里插入图片描述
技术要点,详见注释

<script setup></script>

<template>
  <div class="page">
    <header>页头</header>
    <nav>导航</nav>
    <!-- 主体内容 -->
    <main class="row">
      <aside>
        左侧边栏
        <section>区域内容</section>
      </aside>
      <article>
        <h2>文章标题</h2>
        <p>文章段落一</p>
        <p>
          文章段落二:文章段落二的内容………………文章段落二的内容………………文章段落二的内容………………文章段落二的内容………………文章段落二的内容………………文章段落二的内容………………文章段落二的内容………………
        </p>
      </article>
      <aside>右侧边栏</aside>
    </main>

    <footer>页脚</footer>
  </div>
</template>

<style lang="scss" scoped>
.page {
  /* 绝对定位撑满全屏(避开的浏览器默认样式 html 和 body 存在 margin 和 pandding 的影响)*/
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  /*  对页面内的元素使用flex布局*/
  display: flex;
  /*  垂直方向使用flex布局*/
  flex-direction: column;
  /*  最小宽度为左右侧栏的宽度+文章的最小宽度*/
  min-width: 600px;
}

header {
  background-color: goldenrod;
  text-align: center;
  padding: 10px;
}

nav {
  background-color: red;
  text-align: center;
  padding: 10px;
}
main {
  display: flex;
  /*  主体内容-垂直方向撑满*/
  flex-grow: 1;
  background-color: yellow;
  padding: 10px;
}
aside {
  background-color: green;
  width: 200px;
  padding: 10px;
  text-align: center;

  section {
    background-color: blue;
    height: 100px;
    text-align: center;
    padding: 10px;
    margin-top: 10px;
  }
}
article {
  background-color: blueviolet;
  padding: 10px;
  /*  文章-水平方向撑满*/
  flex-grow: 1;
  /*  flex-grow: 1;时,需设置 width,其值的效果为最小宽度(否则随文字内容的增加,会挤压左右两侧)*/
  width: 100px;

  h2 {
    text-align: center;
  }
}

footer {
  background-color: gray;
  text-align: center;
  padding: 10px;
}
</style>
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

朝阳39

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值