css - anchor 标签不占用 safari 上的文本宽度

标签 css flexbox anchor

enter image description here

有一段时间,我试图在一个具有 flex-wrap: nowrapoverflow:auto 的 flex box 容器内实现这个,现在这个工作在 google chrome 中,但它在 safari 中不适用于较小的屏幕尺寸以及 Iphone。以下是代码

<html>
<head>
</head>
    <style>
        .flex-div {
            display: -webkit-box;
            display: -webkit-flex;
            display: -ms-flexbox;
            display: flex;
            -webkit-box-orient: horizontal;
            -webkit-box-direction: normal;
            -webkit-flex-direction: row;
            -ms-flex-direction: row;
            flex-direction: row;
            -webkit-flex-wrap: nowrap;
            -ms-flex-wrap: nowrap;
            flex-wrap: nowrap;
            overflow-x: auto;
        }
        .flex-div a {
            display: inline-block;
            white-space: nowrap;
            margin-left: 10px;
            margin-right: 10px;
        }
    </style>
<body>
    <div class="flex-div">
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>
        <a>Modern & contemporary</a>

    </div>
</body>

最佳答案

试试这个。我还删除了未使用的 css。

.flex-div {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  overflow-x: auto;
}
.flex-div a {
  white-space: nowrap;
  margin-left: 10px;
  margin-right: 10px;
  -ms-flex: none;
  -webkit-flex: none;
  flex: none;
}
<div class="flex-div">
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
  <a>Modern & contemporary</a>
</div>

关于css - anchor 标签不占用 safari 上的文本宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38414955/

相关文章:

可以故意更改 CSS 文件

javascript - 如何在 Angular ngRepeat 中翻转卡片

html - 为 flex 元素设置特定高度

html - 在 flexbox 布局中,交叉轴是否有 `flex-shrink: 0` 声明?

html - 如何在 Pandoc Markdown 中添加 anchor 标记到 HTML 转换以避免 URI 编码?

css - 2 Bootstrap 网站不是背景图片没有响应

css - 表格、表格单元格、百分比高度和溢出滚动问题

css - css中的正向和负向灵活性有什么区别

php - 使用 php 动态创建的页面滚动到 anchor 标记

css - 汉堡菜单可点击区域太小