我的布局看起来有点像书架,see my jsfiddle example .书架是响应式的,所以没有固定的宽度。我面临的问题是我无法将面板中的文本“水平”置于书本两侧的中心。这是非常棘手的,因为文本被转换为垂直显示。有没有人对如何使这项工作有任何想法?
HTML
<div class="panel">
<a href="#first">
<span>first</span>
</a>
</div>
CSS
.panel {
float: left;
height: 100%;
width: 15%;
margin-right: 5%;
}
.panel a {
text-align: right;
background: green;
padding: 20px 10px;
height: 100%;
display: block;
white-space: nowrap;
color: white;
float: left;
width: 100%;
text-decoration:none;
}
.panel a span {
white-space: nowrap;
color: white;
text-transform: lowercase;
-ms-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
transform-origin: top right;
display: block;
width: 300px;
margin-left: -300px;
letter-spacing: 1px;
font-size: 20px;
}
最佳答案
您有 2 个简单的选项,display
:flex
或 table
:
显示:表格示例:
body,
html,
.panel-wrapper {
height: 100%;
width: 100%;
}
.panel-wrapper {
display: table;
border-collape: collapse;
table-layout: fixed;
background: white;
}
.panel {
display: table-cell;
height: 100%;
width: 20%;/* you have five here*/
}
.panel a {
display: block;
text-align: center;
background: green;
padding: 20px 10px;
box-sizing:border-box;/*includes padding and borders */
height: 100%;
width: 75%;/* each is 15% width */
text-decoration: none;
white-space: nowrap;
}
.panel a:before {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;/*inline content will vertical-align middle aside it */
}
.panel a span {
display: inline-block;/* triggers transform*/
color: white;
text-transform: lowercase;
transform: rotate(-90deg);
letter-spacing: 1px;
font-size: 20px;
vertical-align: middle;
}
<div class="panel-wrapper">
<div class="panel"><a href="#first"><span>first</span></a>
</div>
<div class="panel"><a href="#second"><span>second</span></a>
</div>
<div class="panel"><a href="#third"><span>third</span></a>
</div>
<div class="panel"><a href="#fourth"><span>fourth</span></a>
</div>
<div class="panel"><a href="#fifth"><span>fifth</span></a>
</div>
</div>
http://codepen.io/gc-nomade/pen/JGEbLX
或 flex :
body,
html,
.panel-wrapper {
height: 100%;
width: 100%;
margin: 0;
}
.panel {
float: left;
height: 100%;
width: 15%;
margin-right: 5%;
}
.panel a {
text-align: right;
background: green;
padding: 20px 10px;
height: 100%;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
;
white-space: nowrap;
color: white;
text-decoration: none;
}
.panel a span {
white-space: nowrap;
color: white;
transform: rotate(-90deg);
letter-spacing: 1px;
font-size: 20px;
}
<div class="panel-wrapper">
<div class="panel"><a href="#first"><span>first</span></a>
</div>
<div class="panel"><a href="#second"><span>second</span></a>
</div>
<div class="panel"><a href="#third"><span>third</span></a>
</div>
<div class="panel"><a href="#fourth"><span>fourth</span></a>
</div>
<div class="panel"><a href="#fifth"><span>fifth</span></a>
</div>
</div>
关于html - 在 a 元素中居中垂直跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34566553/