基本代码
<template>
<div class="left">www</div>
<div class="right">rer</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.left {
width: 200px;
height: 400px;
background-color: red;
}
.right {
height: 400px;
background-color: skyblue;
}
</style>
初始效果:

<template>
<div class="flex">
<!-- 我这里使用了unoCSS插件,所以 class="flex"等价于display:flex -->
<div class="left">www</div>
<div class="right">rer</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.left {
width: 200px;
height: 400px;
background-color: red;
}
.right {
flex: 1;
height: 400px;
background-color: skyblue;
}
</style>
实现效果

<template>
<div class="father">
<div class="left">www</div>
<div class="right">rer</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--left-width: 200px;
display: grid;
grid-template-columns: var(--left-width) auto;
.left {
height: 400px;
background-color: red;
}
.right {
height: 400px;
background-color: skyblue;
}
}
</style>
.father {
--left-width: 200px;
display: grid;
grid-template-columns: var(--left-width) 1fr;//!!!!!!!
.left {
height: 400px;
background-color: red;
}
.right {
height: 400px;
background-color: skyblue;
}
}
<template>
<div class="father">
<div class="son1">Son111</div>
<div class="son2">Son222</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 150px;
display: table;
width: 100%;
height: 200px;
border: 1px solid red;
.son1 {
display: table-cell;
width: var(--son1-width);
background-color: purple;
}
.son2 {
display: table-cell;
background-color: orange;
}
}
</style>
<template>
<div class="left">wwwdiv>
<div class="right">rerdiv>
template>
<script setup>script>
<style lang="scss" scoped>
.left {
--left-width: 200px;
float: left;
width: var(--left-width);
height: 400px;
background-color: red;
}
.right {
height: 400px;
margin-left: var(--left-width);
background-color: skyblue;
}
style>
<template>
<div class="father">
<div class="left">www</div>
<div class="right">rer</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--left-width: 200px;
.left {
float: left;
width: var(--left-width);
height: 400px;
background-color: red;
}
.right {
float: left;
width: calc(100% - var(--left-width));
height: 400px;
background-color: skyblue;
}
}
</style>
<template>
<div class="father">
<div class="left">www</div>
<div class="right">rer</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--left-width: 200px;
.left {
position: absolute;
width: var(--left-width);
height: 400px;
background-color: red;
}
.right {
height: 400px;
margin-left: var(--left-width);
background-color: skyblue;
}
}
</style>
<template>
<div class="father">
<div class="left">www</div>
<div class="right">rer</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--left-width: 200px;
position: relative;
.left {
position: absolute;
width: var(--left-width);
height: 400px;
background-color: red;
}
.right {
position: absolute;
left: var(--left-width);
width: calc(100% - var(--left-width));
height: 400px;
background-color: skyblue;
}
}
</style>
<template>
<div class="father">
<div class="left">www</div>
<div class="right">rer</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--left-width: 200px;
.left {
position: absolute;
width: var(--left-width);
height: 400px;
background-color: red;
}
.right {
height: 400px;
margin-left: var(--left-width);
background-color: skyblue;
}
}
</style>
<template>
<div class="father">
<div class="son">Son111</div>
<div class="son">Son2222</div>
<div class="son">Son33333</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
display: grid;
grid-template-columns: 50px auto 200px;
// grid-template-columns: 50px 1fr 200px;
height: 400px;
background-color: pink;
border: 1px solid red;
.son {
&:nth-child(1) {
background-color: purple;
}
&:nth-child(2) {
background-color: green;
}
&:nth-child(3) {
background-color: skyblue;
}
}
}
</style>
效果:

<template>
<div class="father">
<div class="son">Son111</div>
<div class="son">Son2222</div>
<div class="son">Son33333</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
display: flex;
--son1-width: 50px;
--son3-width: 200px;
height: 400px;
background-color: pink;
border: 1px solid red;
.son {
&:nth-child(1) {
width: var(--son1-width);
background-color: purple;
}
&:nth-child(2) {
flex: 1;
background-color: green;
}
&:nth-child(3) {
width: var(--son3-width);
background-color: skyblue;
}
}
}
</style>
<template>
<div class="father">
<div class="son">Son111</div>
<div class="son">Son2222</div>
<div class="son">Son33333</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 200px;
display: table;
width: 100%;
height: 400px;
border: 1px solid red;
.son {
&:nth-child(1) {
display: table-cell;
width: var(--son1-width);
background-color: purple;
}
&:nth-child(2) {
display: table-cell;
background-color: green;
}
&:nth-child(3) {
display: table-cell;
width: var(--son3-width);
background-color: skyblue;
}
}
}
</style>
<template>
<div class="father">
<div class="son1">Son111</div>
<div class="son3">Son33333</div>
<div class="son2">Son2222</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 200px;
width: 100%;
height: 400px;
border: 1px solid red;
.son1 {
float: left;
width: var(--son1-width);
background-color: purple;
}
.son2 {
margin-right: var(--son3-width);
margin-left: var(--son1-width);
background-color: green;
}
.son3 {
float: right;
width: var(--son3-width);
background-color: skyblue;
}
}
</style>
<template>
<div class="father">
<div class="son">Son111</div>
<div class="son">Son2222</div>
<div class="son">Son33333</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 200px;
width: 100%;
height: 400px;
border: 1px solid red;
.son {
&:nth-child(1) {
float: left;
width: var(--son1-width);
background-color: purple;
}
&:nth-child(2) {
float: left;
width: calc(100% - var(--son1-width) - var(--son3-width));
background-color: green;
}
&:nth-child(3) {
float: left; // float: right;也可以
width: var(--son3-width);
background-color: skyblue;
}
}
}
</style>
<template>
<div class="father">
<div class="son1">Son111</div>
<div class="son2">Son2222</div>
<div class="son3">Son33333</div>
</div>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 200px;
position: relative;
width: 100%;
height: 400px;
border: 1px solid red;
.son1 {
position: absolute;
width: var(--son1-width);
background-color: purple;
}
.son2 {
position: absolute;
right: 0;
width: var(--son3-width);
background-color: skyblue;
}
.son3 {
margin-right: var(--son3-width);
margin-left: var(--son1-width);
background-color: green;
}
}
</style>
<template>
<div class="father">
<div class="son">son111111</div>
<div class="son">son22222</div>
<div class="son">son33333</div>
</div>
</template>
<script setup>
import { ref, reactive } from 'vue'
</script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 150px;
// position: relative;
.son:nth-child(1) {
position: absolute;
left: 0;
width: var(--son1-width);
background-color: pink;
}
.son:nth-child(2) {
position: absolute;
left: var(--son1-width);
width: calc(100% - var(--son1-width) - var(--son3-width));
background-color: red;
}
.son:nth-child(3) {
position: absolute;
right: 0;
width: var(--son3-width);
background-color: skyblue;
}
}
</style>
同上
<template>
<div class="father">
<div class="son1">Son111</div>
<div class="son3">Son33333</div>
<div class="son2">Son2222</div>
</div>
<p>333333333333333333</p>
<p>asdfasdfasd</p>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 200px;
position: relative;
height: 200px;
border: 1px solid red;
.son1 {
position: fixed;
width: var(--son1-width);
background-color: purple;
}
.son2 {
margin-right: var(--son3-width);
margin-left: var(--son1-width);
background-color: green;
}
.son3 {
position: fixed;
right: 0;
width: var(--son3-width);
background-color: skyblue;
}
}
</style>
<template>
<div class="father">
<div class="son1">Son111</div>
<div class="son2">Son2222</div>
<div class="son3">Son33333</div>
</div>
<p>333333333333333333</p>
<p>asdfasdfasd</p>
</template>
<script setup></script>
<style lang="scss" scoped>
.father {
--son1-width: 50px;
--son3-width: 200px;
position: relative;
height: 20px;
.son1 {
position: fixed;
width: var(--son1-width);
background-color: purple;
}
.son2 {
position: fixed;
width: calc(100% - var(--son1-width) - var(--son3-width));
margin-left: var(--son1-width);
background-color: green;
}
.son3 {
position: fixed;
right: 0;
width: var(--son3-width);
background-color: skyblue;
}
}
</style>