Vertically Render content:attr(data-content) in CSS

149 Views Asked by At

I would like to render text vertically one by one using CSS. If using rotation method, we can get like below,

Actual rotation

But I am expected to render the text like below,

Expected output

Could anybody tell me your suggestion on this?

Note: I am setting this text using 'content:attr(data-content)' in CSS and data-content is "HELLO".

3

There are 3 best solutions below

0
On BEST ANSWER

You can break each character of content:attr(data-content) like following way:

.test::after {
    content: attr(data-content);
    font-size: 25px;
}
.test {
    width: 0;
    word-break: break-all;
}
<div class="test" data-content="Hello"></div>

0
On

Try using this with simple HTML instead of with CSS

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Vertical Text</title>
 
<style>
  h1 span { display: block; }
</style>
</head>
<body>
  
  <h1>
   <span> N </span>
   <span> E </span>
   <span> T </span>
   <span> T </span>
   <span> U </span>
   <span> T </span>
   <span> S </span>
  </h1>
   
</body>
</html>

0
On

How about this:

h1 span { display: block; }
<h1>
   <span> H </span>
   <span> E </span>
   <span> L </span>
   <span> L </span>
   <span> O </span>
  </h1>

or you can try like this using word-wrap: break-word;:

h1 {
    width: 50px;
    font-size: 50px;
    word-wrap: break-word;
  }
<h1> HELLO </h1>