css - 使用 CSS 插入可选的自动换行点
问题描述
我正在尝试格式化最后有参考的报价。我的标记如下所示:
<p class=quotation>
"Your time is limited, so don't waste it living someone else's life.
Don't be trapped by dogma – which is living with the results of
other people's thinking."<span class=reference>Steve Jobs</span>
</p>
span
我在使用 CSS::before
伪元素之前插入了一个破折号。但是,换行符有点难看。我希望引号本身没有换行符,所以我的 CSS 目前看起来像这样:
.quotation .reference::before {
content: '—';
}
.quotation .reference {
white-space: nowrap;
}
不幸的是,这意味着最后一个词(在本例中为“thinking.”)会附加到破折号并换行。
我希望发生两件事:
- 当引用与引用结尾在同一行时,破折号前不应有空格
- 当参考不适合时,包装应在 em-dash 之前完成
我试过用 插入一个零宽度的空格content: '\200B—';
,但这似乎根本没有效果。
有没有办法在纯 CSS 中实现这一点?
在此代码段中,div
可调整大小,因此您可以查看未插入换行符的方式。
.quotation .reference::before {
content: '—';
}
.quotation .reference {
white-space: nowrap;
}
/* make div resizable to see the effect */
div {
resize: both;
overflow: scroll;
border: 1px solid black;
padding: 1em;
}
<div>
<p class=quotation>
"Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking."<span class=reference>Steve Jobs</span>
</p>
</div>
解决方案
只需使其inline-block
避免附加效果:
.quotation .reference::before {
content: '—';
}
.quotation .reference {
white-space: nowrap;
display:inline-block;
}
/* make div resizable to see the effect */
div {
resize: both;
overflow: scroll;
border: 1px solid black;
padding: 1em;
}
<div>
<p class=quotation>
"Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking."<span class=reference>Steve Jobs</span>
</p>
</div>
推荐阅读
- apache-camel - 在主路由上发送聚合结果,而不是输入消息
- r - 使用 testthat 运行唯一文件中子目录中的所有测试
- apache-kafka - 反序列化期间的消费者模式更新
- mysql - 在哪里指定用于 mariaDB 的 cnf 文件?
- java - 消除数组中重复对象的最佳方法
- android - 面临android volley lib错误响应问题
- python-3.x - 如何链接不同图的x轴?(未使用子图)[Python/Plotly-Dash]
- angular - http错误响应后,角度将mat-input设置为错误状态
- mysql - 删除 mysql 查询中的某些行
- swift - 当用户在通知上单击“允许”时,FCM 令牌不会保存在数据库中