我有一个心的图像,这是正方形的图像,我希望文本环绕在一个心形/图案,使它紧紧拥抱图像中的心.我认为问题是心形的(我希望文本在一侧环绕),图像本身是正方形的,所以当我使用border-radius: 35%;shape-outside: margin-box;时,文本围绕图像绕成一个圆圈,而不是图像中的心或心形图案.(很难解释,但基本上我希望它看起来很专业,文字勾勒出内心,而不是图像.)

可能的解决方案:修改图像,使其更像心形,但我经常使用这个图像,所以我不想这样做,因为它可能会搞砸其他一些东西.

这是它现在在这个网站顶部的样子:confluenceinfinite.org.不可怕,但对我来说不够专业,文字在右边勾勒出一个圆圈,而不是一个心形.我想如果它紧一点的话看起来会酷很多.

我遗漏了什么?

* {
  padding: 0;
  box-sizing: border-box;
  box-sizing: border-box;
  font-family: Arial;
  text-align: left;
  font-size: 14px;
}

p {
  margin: 30px 30px 30px 30px;
}

#black_heart_globe_top {
  border-radius: 35%;
  max-width: 15vw;
  min-width: 100px;
  margin: 0px 30px 30px 30px;
  float: left; /* this keeps the text wrapping around the heart as a cirlce */
  shape-outside: margin-box;
}
<img id="black_heart_globe_top" src="https://confluenceinfinite.org/images/Color_globe_trans_on_black_upright_heart_small.png" />

<p>sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
  sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
  sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
  sample text </p>

编辑:我根本不是一个css/html/markup专家.

推荐答案

使用shape-outside: polygon(...)`可为您的文本设置一个可环绕的自定义形状.

EC:

* {
  padding: 0;
  box-sizing: border-box;
  font-family: Arial;
  text-align: left;
  font-size: 14px;
}

p {
  margin: 30px 30px 30px 30px;
}

#black_heart_globe_top {
  max-width: 15vw;
  min-width: 100px;
  margin: 0px 10px 5px 10px;
  float: left; /* this keeps the text wrapping around the heart as a cirlce */
  shape-outside: polygon(50% 100%, 0% 35%, 10% 10%, 40% 0%, 60% 0%, 90% 10%, 100% 35%);
}
<img id="black_heart_globe_top" src="https://confluenceinfinite.org/images/Color_globe_trans_on_black_upright_heart_small.png" />

<p>sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
  sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
  sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
  sample text </p>

Tip:个基本形状+一个用于创建您自己的多边形的工具:https://bennettfeely.com/clippy/

或者,您可以使用shape-outside: url(...);将图像本身的Alpha通道用作路径.由于CORS的原因,它在此演示中不起作用,但您需要的代码是

shape-outside: url("https://confluenceinfinite.org/images/Color_globe_trans_on_black_upright_heart_small.png");

shape-outside:polygon()shape-outside:<image>supported in all modern browsers和许多旧的.

Html相关问答推荐

卸载伪元素 destruct 了CSS

获得一个css框,以便在页面太小时不再粘在页面的角落.

如何防止可见的滑动抽屉,同时转移HTML方向?

如何在元素的三条边中间换行边框?

背景可点击,而不是文本

如何设置弹性盒子容器的具体大小?

如何在排序上重用参数?

防止position:relative的child在出界时收缩

Vutify中看不见的V行

如何将多个类名组合到CSS中的一个关键帧

如何在r中提取明显非标准html标签的值

使用简单的 HTML 设计公司徽标和文本

带有数据 URI 的音频在 Chrome 中失败

当悬停时,同时影响相邻的两侧div

如何调整底部有 SVG 的元素的高度,使其在所有宽度上看起来都不错?

如何制作一个空的网格模板行来填充剩余空间?

本地 css 样式表未链接

如何使用 css 将图像变成黑色并使文本出现在悬停时?

如何突出显示 .qmd html 文件中的特定代码行

Angular Material Hide Password 在输入时切换