简体   繁体   English

如何在 css 中将顶部栏移到左侧?

[英]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>

You can also use a mixed border style and use hidden for the top, bottom, and right.您还可以使用混合边框样式,并在顶部、底部和右侧使用隐藏。 usage is described at W3Schools W3Schools描述了用法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM