如何在保持垂直文本居中的同时用省略号保持截断?

问题描述 投票:0回答:1

我正在尝试显示

book-spine
在视觉上居中于
shelf
内部的内容。它应该看起来像一本书的书脊。当
book-spine
太长时,应该用省略号截断。

  • book-spineFlex
    其中
    display:flex;
    的情况下,文本居中但不被截断。
  • book-spineBlock
    其中
    display:block;
    的情况下,文本被截断但不居中。

如何让

book-spine
居中 并在 shelf
 内部截断?

html, body { height: 100%; margin: 0; padding: 0; font-family: 'Cambria', serif; } .wrapper { display: flex; flex-direction: column; min-height: 100vh; } .container { width: 80%; margin: auto; } @media (max-width: 768px) { .container { width: 90%; } } @media (max-width: 480px) { .container { width: 95%; } } .shelf { display: flex; justify-content: space-between; margin: auto; max-width: 500px; } .book-spineFlex { width: 45px; height: 150px; margin-right: 1px; background-color: #a0522d; color: white; display: flex; align-items: center; justify-content: center; writing-mode: vertical-lr; transform: rotate(180deg); text-overflow: ellipsis; white-space: nowrap; overflow: hidden; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); } .book-spineBlock { width: 45px; height: 150px; margin-right: 1px; background-color: #a0522d; color: white; display: block; align-items: center; justify-content: center; writing-mode: vertical-lr; transform: rotate(180deg); text-overflow: ellipsis; white-space: nowrap; overflow: hidden; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
<div class="wrapper">
  <div class="container">
    <div class="shelf">
      <div class="book-spineFlex">Sample title 1 w/ truncation</div>
      <div class="book-spineBlock">Sample title 1 w/truncation</div>
    </div>
  </div>
</div>

除了上述之外,我尝试使用

flexbox

无济于事(居中但没有截断)。实现 
position: relative
position: absolute
 恢复了截断,但取消了居中。

html css centering truncate
1个回答
0
投票

align-items

 换成 
align-content

html, body { height: 100%; margin: 0; padding: 0; font-family: 'Cambria', serif; } .wrapper { display: flex; flex-direction: column; min-height: 100vh; } .container { width: 80%; margin: auto; } @media (max-width: 768px) { .container { width: 90%; } } @media (max-width: 480px) { .container { width: 95%; } } .shelf { display: flex; justify-content: space-between; margin: auto; max-width: 500px; } .book-spineFlex { width: 45px; height: 150px; margin-right: 1px; background-color: #a0522d; color: white; display: flex; align-items: center; justify-content: center; writing-mode: vertical-lr; transform: rotate(180deg); text-overflow: ellipsis; white-space: nowrap; overflow: hidden; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); } .book-spineBlock { width: 45px; height: 150px; margin-right: 1px; background-color: #a0522d; color: white; display: block; align-content: center; justify-content: center; writing-mode: vertical-lr; transform: rotate(180deg); text-overflow: ellipsis; white-space: nowrap; overflow: hidden; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
<div class="wrapper">
  <div class="container">
    <div class="shelf">
      <div class="book-spineFlex">Sample title 1 w/ truncation</div>
      <div class="book-spineBlock">Sample title 1 w/truncation</div>
    </div>
  </div>
</div>

© www.soinside.com 2019 - 2024. All rights reserved.