我在Mozilla Firefox中使用flex容器时遇到了一个特定的问题.弹性项没有扩展以适应内容,从而导致文本溢出.

Goal:个 我的目标是创建一个垂直排列的不同长度的书目列表.每个标题都包装在一个锚标签中,我希望文本在这个标签中居中.

The anchor tags are green bg. I have h2 elements, with pink bg to show the overflow

观察到的问题: 在Firefox中,每个flex项的宽度保持不变,导致较长的文本溢出其容器.在其他浏览器中未观察到此行为.

What I've Tried:

使用不同的Flexbox属性进行实验. 判断特定于浏览器的CSS差异.

Relevant Code:

.title {
  writing-mode: vertical-lr;
  background: pink;
  text-align: center;
}
.link {
  display: grid;
  background: green;
  border: black solid 1px;
}
.wrapper {
  display: flex;
  background: blue;
  height: 200px;
}
<div class='wrapper'>
  <a class="link">
    <h2 class='title'>Titler</h2>
  </a>
  <a class="link">
    <h2 class='title'>Shorter Title</h2>
  </a>
  <a class="link">
    <h2 class='title'>This is a much longer title and will wrap into m</h2>
  </a>
  <a class="link">
    <h2 class='title'>This is a really long title that will wrap into multiple lines</h2>
  </a>
  <a class="link">
    <h2 class='title'>This is a really long artist title that will wrap into multiple lines</h2>
  </a>
</div>

如果您在Firefox中打开此代码,您将看到该问题.

Questions:

为什么Firefox中的Flex项在使用WRITING-MODE:VERIAL-LR时不根据内容大小调整其宽度?

有什么可能的解决方案来确保Flex项目与其在Firefox中的垂直内容一起增长?

如果可能的话,我想保留每个flex项目的'grid'属性,因为这可以防止firefox垂直书写模式下一些奇怪的渲染问题.

推荐答案

而是将writing-mode移至链接.这似乎解决了问题(在FF Nighly测试)

.title {
  background: pink;
  text-align: center;
}

.link {
  display: grid;
  writing-mode: vertical-lr;
  background: green;
  border: black solid 1px;
}

.wrapper {
  display: flex;
  background: blue;
  height: 200px;
}
<div class='wrapper'>
  <a class="link">
    <h2 class='title'>Titler</h2>
  </a>
  <a class="link">
    <h2 class='title'>Shorter Title</h2>
  </a>
  <a class="link">
    <h2 class='title'>This is a much longer title and will wrap into m</h2>
  </a>
  <a class="link">
    <h2 class='title'>This is a really long title that will wrap into multiple lines</h2>
  </a>
  <a class="link">
    <h2 class='title'>This is a really long artist title that will wrap into multiple lines</h2>
  </a>
</div>

Html相关问答推荐

如何防止SVG图标出现断行?

如何将grid—template—column应用于元素中的子元素

调整一组IMG的大小以适应容器DIV

仅向上扩展并以最大高度滚动的Div

使用`<;use>;`与`<;img>;`时呈现的SVG大小不同

将精选选项的价格合并为一个价格HTML、PHP和JQuery

SVG';COLOR&39;属性不优先于通用css';COLOR&39;属性

如何在悬停时使用 CSS 更改许多同级元素

是否有语义 HTML 可以澄清含义?

R 中的网页抓取数字?

我真的需要一个容器来让行和列正常工作吗? ( bootstrap 程序 v5)

需要帮助个性化我的 CSS 导航栏:如何在鼠标悬停时突出显示
  • 元素?
  • 从 Vue 应用程序的容器元素渲染 HTML

    两部分问题 - 是什么导致了这个空白?

    如何将图像移动到父容器的右侧?

    如何在滚动行中显示一张图片和下一张图片的一半?

    如何将 2 种不同的 colored颜色 应用于 css 中的复选框?

    有没有办法让 textarea 在调整大小时不显示 CSS 转换?

    为什么图像会影响我的

    使用 bootstrap-icons 的未排序图标堆栈