欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > Vue中集中常见的布局方式

Vue中集中常见的布局方式

2024/10/25 10:25:50 来源:https://blog.csdn.net/yu540135101/article/details/142482422  浏览:    关键词:Vue中集中常见的布局方式
  • 布局叠加
    在这里插入图片描述
  • 完整代码
  • 最外层的Container设置为relative,内部的几个box设置为absolute
<template><div class="container"><div class="box box1">Box 1</div><div class="box box2">Box 2</div><div class="box box3">Box 3</div></div>
</template><script>
export default {// 组件逻辑
};
</script><style scoped>
.container {position: relative;width: 300px;height: 300px;background: #888888;
}.box {position: absolute;width: 100px;height: 100px;text-align: center;line-height: 100px;
}.box1 {background-color: red;top: 50px;left: 50px;
}.box2 {background-color: blue;top: 100px;left: 100px;
}.box3 {background-color: green;top: 150px;left: 150px;
}
</style>
  • 如果Container不设置relative则,内部的box则会相对整个页面进行布局
    在这里插入图片描述
  • 使用绝对布局,一个居中,一个居右。
    在这里插入图片描述
  • 其中box1,左上距离父布局50%,然后自身偏移50%,使其居中
.box1 {background-color: red;top: 50%;left: 50%;transform: translate(-50%,-50%);
}
  • 完整代码
<template><div class="container"><div class="box box1">Box 1</div><div class="box box3">Box 3</div></div></template><script>
export default {// 组件逻辑
};
</script><style scoped>
.container {position: relative;width: 300px;height: 300px;background: #888888;
}.box {position: absolute;width: 100px;height: 100px;text-align: center;line-height: 100px;
}.box1 {background-color: red;top: 50%;left: 50%;transform: translate(-50%,-50%);
}.box3 {background-color: green;top: 50%;right: 0;transform: translateY(-50%);
}
</style>
  • 水平方向线性布局
    在这里插入图片描述
  • 设置父布局 display: flex; flex-direction: row;子布局取消position: absolute;即可
.container {display: flex;flex-direction: row;width: 300px;height: 300px;background: #888888;
}.box {//position: absolute;width: 100px;height: 100px;text-align: center;line-height: 100px;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com