Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sizing and positioning a border property

Tags:

html

css

Is there a css where I could size and position the border-left property? Or a "hack"? Below shows what I'd like to have. The black rectangle represents the column and the red, the border I'd like to have on that column. Possible?

If not, could I add another div inside then give that div the border property?

enter image description here

like image 965
Sylar Avatar asked Oct 23 '16 13:10

Sylar


2 Answers

You can use :before pseudo element with position: absolute

.column {
  position: relative;
  height: 200px;
  width: 100px;
  border: 1px solid black;
  display: flex;
  align-items: center;
  justify-content: center;
}
.column:before {
  content: '';
  height: 50px;
  width: 3px;
  background: red;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}
<div class="column">Column</div>
like image 94
Nenad Vracar Avatar answered Oct 05 '22 22:10

Nenad Vracar


You can also do this with gradients and background-clip.

div {
  width: 100px;
  height: 300px;
  border-width: 2px;
  border-style: solid;
  border-color: black black black transparent;
  background-image: linear-gradient(white, white), linear-gradient(to bottom, black 30%, red 30%, red 60%, black 0);
  background-clip: padding-box, border-box;
}
<div></div>
like image 26
Mr_Green Avatar answered Oct 05 '22 23:10

Mr_Green