【问题标题】:vertical text in flexbox layoutflexbox布局中的垂直文本
【发布时间】:2018-01-28 22:22:54
【问题描述】:

我的作品集有一个首页布局,我试图在上面实现一些垂直文本。右侧部分(蓝色)是我的名字将被垂直书写的地方。当我尝试通过 css 转换旋转文本时,它会在滚动时搞砸布局。所以我难住了。您必须将大小增加到整页才能正确查看布局。名称应延伸到蓝色容器的全长。 https://codepen.io/marti2221/pen/BdrdZJ

<div class="container">
 <div class="left">
<div class="svg-container">
  <div class="svg-logo"></div>
</div>
<div class="question-container">
  <p>WHO AM I?</p>
  <p>WHAT DO I DO?</p>
</div>
</div>
<div class="middle">
<div class="top">
  <nav>
    <a>Link1</a>
    <a>Link2</a>
    <a>Link3</a>
    <a>Link4</a>
  </nav>
</div>
<div class="bottom">
  <h1>Im an extremely</br> passionate User</br> Interface Design</br> + 
Developer</h1>
</div>
</div>
<div class="right">
<h1></h1>
</div>
</div>



.container{
display: flex;
height: 100vh;
background: black;
}



.left{
display: flex;
flex: 1;
background: gray;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
.svg-container{
display: flex;
flex-grow: 1;
background: yellow;
width: 100%;
 justify-content: center;
 }
.svg-logo{
height: 100px;
width: 200px;
background: orange;
}
.question-container{
display: flex;
flex-grow: 1;
background: green;
width: 100%;
flex-direction: column;
justify-content: flex-end;
align-items: flex-end;
}
p{
display: flex;
margin-right: 10px;
}



.middle{
display: flex;
flex: 3;
background: red;
flex-direction: column;
}
.top{
display: flex;
flex: 1;
background: aqua;
}
nav{
display: flex;
flex-direction: column;
margin: 65px 0 0 65px;
}

a:before {
content: '\2014';
position: absolute;
margin-left: -40px;
} 
a{
margin: 10px 0 10px 0;
font-size: 24px;
}


.bottom{
display: inline-flex;
flex: 1;
background: brown;
align-items: flex-start;
}
h1{
 margin-left: 25px;
font-size: 55px;
}


.right{
display: flex;
flex: .5;
background: blue;
}

.name{
transform: rotate(90deg);
}

【问题讨论】:

  • 好的,我现在旋转了文本,但现在它占用了两行。我希望它被拉伸到蓝色容器的大小。有什么建议吗??

标签: css text flexbox vertical-alignment


【解决方案1】:

sideways-lr 单独(没有transform)将解决它,尽管截至今天只有 Firefox 支持它。

writing-mode: vertical-lr;transform: rotate 结合使用,它的行为会更符合您的预期

Updated codepen

堆栈sn-p

.container{
  display: flex;
  height: 100vh;
  background: black;
}



.left{
  display: flex;
  flex: 1;
  background: gray;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.svg-container{
  display: flex;
  flex-grow: 1;
  background: yellow;
  width: 100%;
  justify-content: center;
}
.svg-logo{
  height: 100px;
  width: 200px;
  background: orange;
}
.question-container{
  display: flex;
  flex-grow: 1;
  background: green;
  width: 100%;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
}
p{
  display: flex;
  margin-right: 10px;
}



.middle{
  display: flex;
  flex: 3;
  background: red;
  flex-direction: column;
}
.top{
  display: flex;
  flex: 1;
  background: aqua;
}
nav{
  display: flex;
  flex-direction: column;
  margin: 65px 0 0 65px;
}

a:before {
  content: '\2014';
  position: absolute;
  margin-left: -40px;
}
a{
  margin: 10px 0 10px 0;
  font-size: 24px;
}


.bottom{
  display: inline-flex;
  flex: 1;
  background: brown;
  align-items: flex-start;
}
h1{
  margin-left: 25px;
  font-size: 55px;
}


.right{
  display: flex;
  flex: .2;
  background: blue;
  flex-direction: column;
  justify-content: center;
}

.name{
  display: flex;
  transform: rotate(-180deg);            /*  changed  */
  background: pink;
  writing-mode: tb-lr;                   /*  for IE  */
  writing-mode: vertical-lr;             /*  added  */
}
<div class="container">
  <div class="left">
    <div class="svg-container">
      <div class="svg-logo"></div>
    </div>
    <div class="question-container">
      <p>WHO AM I?</p>
      <p>WHAT DO I DO?</p>
    </div>
  </div>
  <div class="middle">
    <div class="top">
      <nav>
        <a>Link1</a>
        <a>Link2</a>
        <a>Link3</a>
        <a>Link4</a>
      </nav>
    </div>
    <div class="bottom">
      <h1>Im an extremely</br> passionate User</br> Interface Design</br> + Developer</h1>
    </div>
  </div>
  <div class="right">
    <h2 class="name">Travis Martin</h2>
  </div>
</div>

【讨论】:

  • 谢谢,就是这样,但是当我尝试将名称大写/增加字体(以占用更多蓝色容器)时,它会增加蓝色容器的大小。有什么方法可以在不增加蓝色容器大小的情况下将文本大写并增加其字体?
  • @TravisMartin 将min-width: 0; 添加到.right ... codepen.io/anon/pen/xLjbGN
  • 我这样做了,但是我认为发生的事情是随着我增加字体大小,中间容器被推小了。这不起作用,因为我需要文本占据右侧容器中所有可用空间的附近。
  • @TravisMartin 好吧,它不适合我。如果您觉得这个有用,请点赞,如果没有,请告诉我,我会删除我的答案
  • 我接近了,但是我的解决方法是完全摆脱右侧容器,并将文本放在右侧和中间容器左侧的空白处。然而,当我实现这个布局时,我会有一个背景图像,所以会显示在中间部分,但应该有半透明的左右部分。如果名称文本实际上不在容器中,我将无法完成此操作。因此,我将无法在名称文本后面放置半透明层。蓝色是最终将成为背景图像的颜色(中间灰色部分也将成为背景图像)
猜你喜欢
  • 2017-04-24
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 2017-06-21
  • 1970-01-01
  • 2012-02-15
相关资源
最近更新 更多