0

Trying to simulate a top border that doesn't start at the left edge of the element.

.border-top {
    height: 50px;
    width: 100px;
    box-shadow:  15px -1px 0 0 black;
}

The above css is close, but produces a black 15px wide shadow to the right of the div. How do I contain that?

http://jsfiddle.net/3sjngyk1/

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236

2 Answers2

1

Top border with just a box shadow?

.border-top {
  height: 50px;
  width: 100px;
  box-shadow: 0px -10px 0px 0px red;
  margin-top: 25px;
  background: lightblue;
}
<div class="border-top"></div>

Alternatively, you can use a pseudo-element and calc (if the border isn't going to be full width - it's not clear from your question).

.border-top {
  height: 50px;
  width: 100px;
  background: lightblue;
  position: relative;
  margin-top: 25px;
}
.border-top::after {
  content: '';
  position: absolute;
  height: 5px;
  bottom: 100%;
  left: 15px;
  width: calc(100% - 15px);
  background: red;
}
<div class="border-top"></div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

How about this? http://jsfiddle.net/vleong2332/3sjngyk1/2/

.border-top {
    height: 50px;
    width: 100px;
    box-shadow: 15px 0px 0 0 white, 15px -1px 0 0 black;
}

Put another shadow with the same color as the background on top of the black one.

Vicky Leong
  • 1,208
  • 3
  • 12
  • 30