<template>
<div class="container">
<div class="main-box">
<div class="left-box">左边盒子div>
<div :style="{ flex: fontflag ? 1 : 0 }" class="right-box">
<div class="right-content" v-if="fontflag">
将需要<b>动态展示的内容b>放在该元素中
div>
<i @click="fontclickHandler" class="fontflag el-icon-caret-left">i>
div>
div>
div>
template>
<script>
export default {
data() {
return {
fontflag: true,
};
},
methods: {
fontclickHandler() {
this.fontflag = !this.fontflag;
},
},
};
script>
<style lang="scss" scoped>
.main-box {
display: flex;
padding: 20px;
height: 500px;
.left-box {
background-color: pink;
flex: 5;
margin-right: 20px;
}
.right-box {
position: relative;
background-color: tomato;
transition: all 1s;
.fontflag {
display: inline-block;
width: 15px;
height: 60px;
background-color: lightblue;
text-align: center;
line-height: 60px;
border-radius: 10px 0 0 10px;
position: absolute;
left: -15px;
top: calc(500px / 2);
}
}
}
style>
- :focus-within 当有元素被选中时,被选中的元素及后代元素发生聚焦事件时,css 样式生效。
- :has(表达式) 当选中元素,符合表达式时 css 样式生效 。
- ::selection 当文本被选中时 css 样式生效。
- ::first-letter 只对文本首字母 css 样式生效。
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Documenttitle>
<style>
.label {
text-align: center;
}
input:focus {
outline-color: lightblue;
}
.label:focus-within {
background-color: tomato;
}
.label span:has(+ input[data-required])::after {
content: "*";
color: tomato;
}
.content::selection {
color: tomato;
background-color: pink;
}
.content::first-letter {
color: tomato;
font-weight: bolder;
font-size: 2em;
}
style>
head>
<body>
<div class="label">
<span>姓名span>
<input data-required type="text" />
div>
<div class="label">
<span>姓名span>
<input type="text" />
div>
<div class="label">
<span>姓名span>
<input data-required type="text" />
div>
<p class="content">
噫吁嚱,危乎高哉! 蜀道之难,难于上青天! 蚕丛及鱼凫,开国何茫然!
尔来四万八千岁,不与秦塞通人烟。
p>
body>
html>
.stickyHeaderButton {
position: sticky;
top: 0px;
padding: 10px;
margin-bottom: 10px;
background-color: #fff;
text-align: right;
z-index: 99;
}
实现: 利用元素的
后缀伪元素
实现这一效果.
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>study-practicetitle>
<style>
.box {
border: dashed #ccc 1px;
width: 500px;
height: 500px;
margin: 0 auto;
background-color: tomato;
}
.box::after {
background: hsla(0, 0%, 100%, 0.45);
content: "";
height: calc(100% - 6px);
left: 0;
margin: 3px;
position: absolute;
top: 0;
width: calc(100% - 6px);
z-index: 1999;
}
style>
head>
<body>
<div class="box">div>
body>
html>
关键属性 : 给子元素添加
flex-shrink: 0;
属性.
<template>
<div class="flexdemo">
<div class="item" v-for="item in 10" :key="item">div>
div>
template>
<style lang="scss" scoped>
.flexdemo {
display: flex;
overflow: auto; // 横向滚动条
.item {
width: 300px;
height: 400px;
border-radius: 10px;
background-color: tomato;
margin: 0 10px;
flex-shrink: 0; // 关键属性 ,加了之后就会出现横向滚动条,不会压缩。
// 看对比效果可以把最后一行css注释。
}
}
style>