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>