html - ASCII 和 CSS(无 JavaScript)
问题描述
我有个问题。是否可以在不使用 JavaScript 的情况下用“-”和“+”等 ASCII 符号替换标准 CSS 边框?我想在盒子周围画边框并使用 ASCII 符号来设置我的网站的样式。边框应如下所示:
+-----------+
| |
+-----------+
到目前为止,我发现的唯一解决方案是对 HTML 内的边框进行“硬编码”,但我希望它更具动态性。
解决方案
使用after
& before
CSS
.box {
height: 150px;
width: 200px;
border: 2px dashed red;
margin: 0 auto;
position: relative;
}
.box::after {
content: "+";
position: absolute;
left: -6px;
top: -13px;
font-weight: bold;
font-size: 18px;
color: red;
}
.box::before {
content: "+";
position: absolute;
right: -6px;
top: -13px;
font-weight: bold;
font-size: 18px;
color: red;
}
.box .inner::after {
content: "+";
position: absolute;
left: -6px;
bottom: -11px;
font-weight: bold;
font-size: 18px;
color: red;
}
.box .inner::before {
content: "+";
position: absolute;
right: -6px;
bottom: -11px;
font-weight: bold;
font-size: 18px;
color: red;
}
<div class="box">
<div class="inner">
</div>
</div>
推荐阅读
- javascript - 结合 vegalite 中传说的形状和颜色
- python - 使用 Python 从列表中删除多个字典值
- python - anaconda tensorflow ImportError:DLL加载失败
- javascript - 如何在 php 中更新 xml 属性中的 JSON 字符串
- react-native - FCM API 返回成功响应,但推送通知未发送给用户
- d3.js - dc.js TextFilterWidget 未定义
- python - 我应该默认使用原始字符串吗?
- python - 二十一点问题:以下代码不运行 else 语句,而是再次迭代 elif 条件
- swift - RxSwift 在可调试性方面的技术限制是什么?
- javascript - 如何在单击按钮时删除附加的 div?