<div class="wrapper">
<div class="control">
<label for="flexBasis">flex-basis:</label>
<select name="flexBasis" id="flexBasis">
<option value="auto">auto</option>
<option value="12vw">12vw</option>
<option value="20%">20%</option>
<option value="border-box">border-box</option>
<option value="content-box">content-box</option>
<option value="fill">fill</option>
<option value="max-content">max-content</option>
<option value="min-content">min-content</option>
<option value="available">available</option>
<option value="fit-content">fit-content</option>
</select>
</div>
<div class="container">
<div class="item">CSS</div>
<div class="item">CSS is awesome!</div>
<div class="item">I love CSS!</div>
<div class="item">CSS is simple, but not easy!</div>
</div>
<p>建议使用Firefox Nightly查看,效果更佳!</p>
</div>
@import 'https://fonts.googleapis.com/css?family=Share+Tech+Mono';
@import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1376484/jess-harding-lqT6NAmTaiY-unsplash.jpg'),radial-gradient(#28a3dd, #0d7751);
background-size: cover;
background-position: center;
font-family: "Share Tech Mono", monospace;
font-size: 2rem;
background-blend-mode: multiply,screen, overlay;
padding: 2vh;
}
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.container {
position: relative;
background-size: cover;
background-position: center;
backdrop-filter: blur(20px);
background-color: rgba(255, 255, 255, 0.5);
border-radius: 5px;
box-sizing: border-box;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
transition: .3s ease;
margin: 2vw;
display: flex;
min-width: 80vw;
min-height: 60vh;
}
.control {
padding-bottom: 5vh;
margin-bottom: 6vh;
border-bottom: 3px double currentColor;
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,.5);
font-size: 6vh;
}
.item {
min-height: 40vh;
border: 2px solid currentColor;
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,.5);
box-shadow: 1px 1px 2px rgba(0,0,0,.5);
font-size: 6vh;
position: relative;
}
:root {
--flex-basis: auto;
}
.item:nth-child(1){
background-color: #f89;
}
.item:nth-child(2){
background-color: #90f;
}
.item:nth-child(3){
background-color: #20c0a9;
}
.item:nth-child(4){
background-color: #8ac020;
}
.item {
width: 15vw;
flex-basis: var(--flex-basis);
}
p {
font-size: 5vh;
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,.5);
}
View Compiled
let selectEle = document.getElementById("flexBasis");
let root = document.documentElement;
selectEle.addEventListener("change", (evt) => {
root.style.setProperty('--flex-basis', evt.target.value);
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.