html – 将元素中的垂直范围居中

前端之家收集整理的这篇文章主要介绍了html – 将元素中的垂直范围居中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个看起来有点像书架的布局,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个简单的选择,显示:flex或table:

display: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,.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>

http://codepen.io/gc-nomade/pen/obBYyY

原文链接:https://www.f2er.com/html/226933.html

猜你在找的HTML相关文章