reactjs - 如果内容为空字符串,则样式组件不显示 ::after 伪类
问题描述
我遇到问题找到解决方案。在样式化的组件中,我使用 after 伪元素。只要我将内容值设置为某些东西,它就可以工作,否则它不会出现。我需要它是空的(就像在纯 CSS 中一样)。这样做的方法是什么?
export default css`
display: flex;
height: 100%;
width: 100%;
&::after {
bottom: 0;
content: "";
position: absolute;
width: calc(100% - 11px);
box-shadow: 0 8px 6px 0px rgba(var(--rgb-black),0.16);
}´
解决方案
:after
我也遇到了这个问题,如果不使用非空内容字符串,我无法让 styled-components 呈现伪元素。但是让文本不可见对我来说是一个可以接受的解决方法:
&::after {
content: "a"; //use non-empty string
color: rgba(0,0,0,0); //make it invisible
display: inline-block; //so width & height can be set
}
这是 CodePen 的完整示例:https ://codepen.io/remyho427/pen/VwMNeaG
推荐阅读
- c# - Json.NET JsonPath 语法“不包含”,还是否定匹配?
- angular - Angular:在 NgModule entryComponents 数组中使用库中的组件时出现问题
- struct - 从结构创建直方图
- oracle - 如何在 JPA 中将 Oracle RAW 数据类型与相应的 Java 类型映射?
- python - 重复轴 matplotlib
- python - 如果python中的字典中有多个键值,如何查找索引?
- javascript - 在 Node.js 中将行附加到文件会导致内容以随机顺序写入
- javascript - 即使条件为假,我的功能也会自动触发
- javascript - 如果在 setInterval 内不透明度 == 1,则将 1 添加到变量
- java - 如何返回第二个值