[CSS] Logical Properties (逻辑属性)
Brwoser support: https://caniuse.com/?search=Logical%20Properties%20
We want to achieve following effect, the first box, we applied writing-mode: vertical-lr
in order to get second box.
From the code, you can see that we have to change the second box widht & height
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box1 {
border: 1px black solid;
width: 300px;
height: 100px;
}
.box1 div {
border: 1px red solid;
float: left;
margin-left: 30px;
}
.box2 {
border: 1px black solid;
width: 100px;
height: 300px;
writing-mode: vertical-lr;
}
.box2 div {
border: 1px red solid;
float: left;
margin-top: 30px;
}
</style>
</head>
<body>
<h2>Logical Properties (逻辑属性)</h2>
<div class="box1">
<div>hello world</div>
<div>hello world</div>
</div>
<div class="box2">
<div>hello world</div>
<div>hello world</div>
</div>
</body>
</html>
We can use margin-inline-start & block-size, inline-size
to achieve the same effect
block-size
: Y of text
inline-size
: X of text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box3 {
border: 1px black solid;
block-size: 100px;
inline-size: 300px;
}
.box3 div {
border: 1px red solid;
float: left;
margin-inline-start: 30px;
}
.box4 {
border: 1px black solid;
block-size: 100px;
inline-size: 300px;
writing-mode: vertical-lr;
}
.box4 div {
border: 1px red solid;
float: left;
margin-inline-start: 30px;
}
</style>
</head>
<body>
<h2>Logical Properties (逻辑属性)</h2>
<div class="box3">
<div>hello world</div>
<div>hello world</div>
</div>
<div class="box4">
<div>hello world</div>
<div>hello world</div>
</div>
</body>
</html>