首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >竖排文本,在div中居中垂直对齐

问竖排文本,在div中居中垂直对齐
EN

Stack Overflow用户
提问于 2016-09-10 01:22:55
回答 1查看 404关注 0票数 0

我有一个div,它包含一些垂直方向的文本,如下所示。我想要实现的是,如下图所示:

​

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-10 03:08:49

我不确定您的html/css结构,也不确定您的代码可能是什么样子,但这里有一个我写的示例。

​

代码语言:javascript
复制
* {
  box-sizing: border-box; /* Set the box sizing for easier margins/paddings. */
}

html,
body {
  margin: 0; /* Demo style. */
  background: #95a5a6; /* Demo style. */
}

.container {
  width: 50%; /* Demo style. */
  margin: 50px auto; /* Demo style. */
  background: white; /* Demo style. */
  font-family: arial; /* Demo style. */
  font-size: 16px; /* Demo style. */
}

/* The parent of the rotated text. */
.box {
  position: relative; /* Relative for the absolute childs. */
  background: #c0392b; /* Demo style. */
  color: white; /* Demo style. */
  padding: 10px; /* Demo style. */
  height: 200px; /* Static height is required. */
}

/* The rotated text */
.box span {
  width: 200px; /* Must be the same as the height of the .box div. */
  -webkit-transform-origin: 90px 100px; /* These values will need to be changed depending on your width of this span, and height of it's parent. */
  display: inline-block; /* Set the display of the span to be in the block flow. */
  -webkit-transform: rotate(-90deg); /* Rotate the text span. */
  background: #2980b9; /* Demo style. */
  text-align: center; /* Center the text. */
  padding: 10px; /* Demo style. */
  float: left; /* Make the rotated text be on the left most part of the parent. */
}

/* Other content that can be beside the rotated text */
.content {
  position: absolute; /* So the content is not affected by the rotated text. */
  margin: 0 0 0 30px; /* Push the content from the left so it is not behind the rotated text. */
  top: 0; /* Push the content to the top of the parent. */
  padding: 0 10px; /* Demo style. */
}
代码语言:javascript
复制
<div class="container">
  <div class="box">
    <span>JS</span>
    <div class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis culpa laborum suscipit, laudantium ut recusandae architecto modi natus incidunt, consequuntur ea quas quod nisi nobis possimus nostrum, porro neque saepe.</p>
    </div>
  </div>
</div>

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39416776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档