从上到下垂直对齐文本 HTML5 CSS3

Aligning text vertically from top to bottom HTML5 CSS3

我有一个多语言网页。要求将页面上按钮上的标签倒置显示。我正在使用以下 CSS:

HTML:

<button class="btn btn-primary topdown-button">
    <div>お客様</div>
</button>
<button class="btn btn-primary topdown-button">
    <div>Basic 2</div>
</button>

CSS:

.topdown-button{    
    max-height: 150px;
    min-height: 150px;
    width: 60px;
    border: 3px solid navy;
    vertical-align: top;
    display:block;
}
.topdown-button div{  
    text-transform: uppercase;
    vertical-align:top;
    font-size:18px;
    min-height: 148px;
    position:relative;
    text-align:left;
    -ms-writing-mode: tb-rl;   
    -webkit-writing-mode: vertical-rl; 
    -o-writing-mode: vertical-rl;        
    writing-mode: vertical-rl;
    text-transform:uppercase;    
    font-size-adjust:0.5;
}

所以输出是这样的:

日文字符可以完美显示,但字母和数字不是,我希望BASIC2像日文字符一样

B
A
S
I
C
2

我怎样才能做到这一点?

编辑解释: 我正在使用相同的逻辑来转换我的文本,但是如果你看一下日文字符,它们会顺利转换,而普通字母字符往往 "ROTATE" 我不希望英文字符旋转,为什么不能' t 它们的显示与日文字符相同。

已更新

下面的示例跨浏览器工作,text-orientation 还没有。

最简单的就是这样,使用<br>,手动添加或使用脚本。

var elems = document.querySelectorAll('.test div');
for (var i = 0; i < elems.length; i++) {
  elems[i].innerHTML = elems[i].textContent.split('').join('<br>')
}
.topdown-button{    
    max-height: 150px;
    min-height: 150px;
    width: 60px;
    border: 3px solid navy;
    vertical-align: top;
    display: inline-block;
}
.topdown-button div{  
    text-transform: uppercase;
    vertical-align:top;
    font-size:18px;
    min-height: 148px;
    position:relative;
    text-align:center;
    text-transform:uppercase;    
    font-size-adjust:0.5;
}

.divider{
    border-top: 1px solid;
    padding: 10px 0;
    margin-top: 10px;
}
<button class="btn btn-primary topdown-button">
  <div>お<br>客<br>様</div>
</button>
<button class="btn btn-primary topdown-button">
  <div>B<br>a<br>s<br>i<br>c<br>2</div>
</button>

<div class="divider">Sample using script</div>

<button class="btn btn-primary topdown-button test">
  <div>お客様</div>
</button>
<button class="btn btn-primary topdown-button test">
  <div>Basic2</div>
</button>  

2:第二个替代方案,使用 word-break

.topdown-button{    
    max-height: 150px;
    min-height: 150px;
    width: 60px;
    border: 3px solid navy;
    vertical-align: top;
    display:block;
    text-align: center;
}
.topdown-button div{  
    text-transform: uppercase;
    font-size:18px;
    min-height: 148px;
    position:relative;
    text-align:center;
    margin: 0 auto;
    word-break: break-all;
    width: 12px;
}
<button class="btn btn-primary topdown-button">
    <div>お客様</div>
</button>
<button class="btn btn-primary topdown-button">
    <div>Basic2</div>
</button>

使用text-orientation: upright;这将解决问题。

.topdown-button{    
    max-height: 150px;
    min-height: 150px;
    width: 60px;
    border: 3px solid navy;
    vertical-align: top;
    display:block;
}
.topdown-button div{  
    text-transform: uppercase;
    vertical-align:top;
    font-size:18px;
    min-height: 148px;
    position:relative;
    text-align:left;
    -ms-writing-mode: tb-rl;   
    -webkit-writing-mode: vertical-rl; 
    -o-writing-mode: vertical-rl;        
    writing-mode: vertical-rl;
    text-transform:uppercase;    
    font-size-adjust:0.5;
    text-orientation: upright;
}
<button class="btn btn-primary topdown-button">
    <div>お客様</div>
</button>
<button class="btn btn-primary topdown-button">
    <div>Basic 2</div>
</button>

你可以利用 flexbox 让你 css 看起来更干净。看这个pen

HTML

<button class="btn btn-primary topdown-button">
    <div>お</div>
    <div>客</div>
    <div>様</div>
</button>
<button class="btn btn-primary topdown-button">
    <div>B</div>
    <div>A</div>
    <div>S</div>
    <div>I</div>
    <div>C</div>
    <br>
    <div>2</div>
</button>

CSS

.topdown-button{    
    max-height: 150px;
    min-height: 150px;
    width: 60px;
    border: 3px solid navy;
    display:flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.topdown-button div{  
    text-transform: uppercase;
    font-size:18px;
 }