The SVG Image is not displayed properly. I expect the "::before" to be 18x18px and the SVG to be displayed exactly the way it looks.
enter image description here
If you open the SVG in a new TAB it's exactly 18x18 px.
enter image description here

在本例中,它为什么移动到容器之外? 我做错什么了吗?

.row {
  background-color: red; 
}
.col-12 {
  background-color: green;
}
.bg-white {
  background-color: #fff;
}
.marketing {
    font-weight: 800;
}
.marketing .headline {
    margin: 1rem 0 1rem 10%;
}
.arrow::before {
    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 18 18"><path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"></path></svg>');
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row m-0">
  <div class="col-12 col-md-6 marketing p-0">
    <div class="headline">
      <span class="p-2 bg-white arrow">
        Test
      </span>
    </div>
  </div>
</div>

推荐答案

首先,你图标本身的形状在视图框中向上移动,如果你希望看到它位于正方形的中心,你可能被误导了:

然后,正如@enxaneta在 comments 中建议的那样,将其设置为内联框并设置尺寸应该会有所帮助,只需确保您使用适当的垂直对齐即可.

.row {
  background-color: red; 
}
.col-12 {
  background-color: green;
}
.bg-white {
  background-color: #fff;
}
.marketing {
    font-weight: 800;
}
.marketing .headline {
    margin: 1rem 0 1rem 10%;
}
.arrow::before {
    content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 18 18"><path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"></path></svg>');
    vertical-align: text-bottom;
    display: inline-block;
    height: 18px;
    outline: 1px solid red;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row m-0">
  <div class="col-12 col-md-6 marketing p-0">
    <div class="headline">
      <span class="p-2 bg-white arrow">
        Test
      </span>
    </div>
  </div>
</div>


简化的测试用例不使用ALIGN:

.original::before {
  content: url('data:image/svg+xml,<svg \
  width="18" \
  height="18" \
  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 5 5"><rect width="100%" height="100%" fill="lime" stroke="green" opacity=".7"/></svg>');
}

.fixed::before {
  display: inline-block;
  width: 18px;
  height: 18px;
  content: url('data:image/svg+xml,<svg \
  width="18" \
  height="18" \
  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 5 5"><rect width="100%" height="100%" fill="lime" stroke="green" opacity=".7"/></svg>');
}
/* demonstrative: */
span::before { background-color: red; outline: 1px solid blue; }
span::after { content: ' ' attr(class); }
html { background: dimgrey; color: snow;  }
<span class="original"></span>

<hr>

<span class="fixed"></span>

(我被误导了,因为观察到SVG中的维度会影响它的对齐.)

Html相关问答推荐

CSS位置:固定尊重母公司的保证金属性.""'为什么?

HTML5章节或文章

附加点的列表样式

背景可点击,而不是文本

禁用的文本区域会丢失换行符

希望平稳过渡到悬停状态

如何解决水平塌陷问题?

HTML,CSS-阻止按钮在单击时向上移动

网格布局中的组件

当浏览器宽度减小时字体大小变得太大

MUI 日期 Select 器要包含的日期

如何使用 Flutter 构建 Chrome 扩展?

使用 Thymeleaf 将图像水平居中

如何在CSS伪类函数中使用复合 Select 器:host-context()

Tailwind:父母动态适应子元素的身高

将 HTML 元素粘贴到容器底部,而不剪裁其顶部

如何并排放置
的定义列表,但如果
变长,
会向下移动?

父背景仅在子元素中可见

自定义进度条 Html 和 CSS 布局

如何创建带有偏移边框线的双色边框?