I need all the text written in i a div to be vertical, like one character per line and centered.
The only way i've achieved is giving the div a fixed width of width: 7%; and a word-break: break-all;
Is there any way using CSS to achieve this with no fixed width?
.flex-container {
display: flex;
border: 1px solid #000000;
}
.flex-container > div {
width: 400px;
height: 300px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
.flex-container > div:nth-child(odd) {
background-color : #62d962;
}
.flex-container > div:last-child {
display: flex;
justify-content: flex-end;
}
.flex-container > div:last-child div {
width: 7%;
}
.flex-container div:last-child div:nth-child(odd){
background-color: #65e9e3;
word-break: break-all;
line-height: 1em;
padding: 1em 0;
}
<div >
<div></div>
<div></div>
<div>
<div>Box</div>
<div></div>
<div>Box</div>
<div></div>
<div>Box</div>
</div>
</div>
CodePudding user response:
You can use writing-mode and text-orientation CSS properties, to achieve the
desired output.
.flex-container {
display: flex;
border: 1px solid #000000;
}
.flex-container > div {
width: 400px;
height: 300px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
.flex-container > div:nth-child(odd) {
background-color : #62d962;
}
.flex-container > div:last-child {
display: flex;
justify-content: flex-end;
}
.flex-container > div:last-child div {
writing-mode: vertical-rl;
text-orientation: upright;
}
.flex-container div:last-child div:nth-child(odd){
background-color: #65e9e3;
line-height: 1em;
padding: 1em 0;
}
<div >
<div></div>
<div></div>
<div>
<div>Box</div>
<div></div>
<div>Box</div>
<div></div>
<div>Box</div>
</div>
</div>
CodePudding user response:
css
#onechar {
width: min-content;
word-break: break-all;
}
html
<!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>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="onechar">box</div>
</body>
</html>
Hope this helped :)
