[英]How to move Top bar to left side in css?
I have this div that shows a top red bar .我有一个显示顶部红色条的 div。 I've been trying to move this bar to the left side and make it look like a border left, but not having any luck.
我一直在尝试将此栏移到左侧并使其看起来像左侧边框,但没有任何运气。 Does anyone know how to make it look like a border lef t using this code?
有谁知道如何使用这段代码让它看起来像一个边框? Thanks in advance!
提前致谢!
.container { position: relative; width: 100%; padding: 18px; margin-bottom: 16px; border-radius: 8px; border: solid 2px #e1e4e8; overflow: hidden; }.container::after { content: ''; position: absolute; display: block; height: 6px; width: 100%; top: 0; left: 0; background-color: red; }
<div class = "container">this is a text</div>
This example adjusted position of ::after
to make the red border appear on the left, hopefully close to the desired result.本例调整了
::after
的position,使红色边框出现在左边,希望能接近想要的结果。
.container { position: relative; width: 100%; padding: 18px; margin-bottom: 16px; border-radius: 8px; border: solid 2px #e1e4e8; overflow: hidden; }.container::after { content: ''; position: absolute; display: block; width: 6px; inset: 0; background-color: red; }
<div class = "container">this is a text</div>
You can set border-left: 6px solid red;
你可以设置
border-left: 6px solid red;
on the container class and remove background-color: red;
在容器 class 上并删除
background-color: red;
from .container::after
来自
.container::after
Additionally, if you want to keep the grey border, just apply that style to each other sides of the container like so:此外,如果您想保留灰色边框,只需将该样式应用到容器的每一侧,如下所示:
border-top: 2px solid #e1e4e8;
border-bottom: 2px solid #e1e4e8;
border-right: 2px solid #e1e4e8;
See snippet below:请看下面的片段:
.container { position: absolute; display: block; width: 100%; padding: 18px; margin-bottom: 16px; border-radius: 8px; border-left: 6px solid red; border-top: 2px solid #e1e4e8; border-bottom: 2px solid #e1e4e8; border-right: 2px solid #e1e4e8; overflow: hidden; }.container::after { content: ''; position: absolute; display: block; height: 6px; width: 100%; top: 0; left: 0; }
<div class = "container">this is a text</div>
Perhaps just simplify it to a border?也许只是将其简化为边框?
.container { position: relative; width: 100%; padding: 18px; margin-bottom: 16px; border-radius: 8px; border: solid 2px #e1e4e8; border-left: solid 8px red; overflow: hidden; }
<div class = "container">this is a text</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.