8

The image:

enter image description here

I want to code this image!

A simple code: (with problem)

.hr{
  position:relative;
  height:100px;
  background : #ddd;
  clear both;
  margin-top: 100px ;
}
.vr{
  position:absolute;
  width:100px;
  height:900px;
  background : #000;
  top:-300px;
  z-index:-1
}


<div class='hr' style=''><div class='vr' style='left:100px;'></div><div class='vr' style='right:100px;z-index:0'></div></div>
<div class='hr' style=''></div>

..............

7
  • 2
    Not possible with this HTML structure, you'll need to cut a horizontal element in two pieces with separate z-index. Commented Jul 31, 2015 at 10:50
  • Or you can make use of pseudo selectors? Commented Jul 31, 2015 at 11:08
  • pseudo selectors ? do you mean after , before ? Commented Jul 31, 2015 at 11:09
  • @danialdezfooli css-tricks.com/almanac/selectors/a/after-and-before Commented Jul 31, 2015 at 11:11
  • @danialdezfooli I'm late but I answered too. :) Commented Jul 31, 2015 at 11:25

2 Answers 2

2

You can do a hack using pseudo elements this way -

.hr{
  position:relative;
  height:100px;
  background : #ddd;
  clear both;
  margin-top: 100px ;
}
.vr{
  position:absolute;
  width:100px;
  height:900px;
  background : #000;
  top:-300px;
  z-index:-1
}

.bottom:after {
    content: '';
    position: absolute;
    top: 0px;
    left: 100px;
    width: 100px;
    height: 100px;
    background-color: black;
}
<div class='hr' style=''>
  <div class='vr' style='left:100px;'></div>
  <div class='vr' style='right:100px;z-index:0'></div>
</div>
<div class='hr bottom' style=''></div>

Sign up to request clarification or add additional context in comments.

1 Comment

There is no such thing as a "pseudo-selector". I guess you mean "pseudo-element".
1

This is my approach: http://codepen.io/anon/pen/vOvNdK

I created 4 div elements in the LBRT order: the first element (the left vertical bar) overlaps the last one (the top horizontal bar) in the top-left cross thanks to a :before pseudoelement applied to the left vertical bar.

All the sizes and offsets are in relative units, so you could easily scale up (or down) the whole draw simply changing the size of the parent element.

Markup

<div class="draw">
  <div class="v1"></div>
  <div class="h2"></div>
  <div class="v2"></div>
  <div class="h1"></div>
</div>

CSS

.draw { 
  position: relative; 
  width: 400px;
  height: 400px;
  border: 1px #ccc dashed;
}

.draw div { position: absolute; }

.draw div[class^="h"] {
  height: 20%;
  width: 100%;
  left: 0;
  background: #d8d8d8;
}

.draw div[class^="v"] {
  height: 100%;
  width: 20%;
  top: 0;
  background: #212121;
}

.draw .h1 { top : 20%; }
.draw .h2 { top : 60%; }
.draw .v1 { left : 20%; }
.draw .v2 { left : 60%; }

.draw .v1:before { 
  position: inherit;
  z-index: 2;
  top: 20%;
  left: 0;
  width: 100%;
  height: 20%;
  content: "";
  background: inherit;
}

Result

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.