Reputation: 2385
Hey guyz, I guess you got my concept by seeing the above picture. I'm unable to place diagonal line behind the text and it should get masked by the content placed on it. I wanted it in pure css. Background should be visible through the text.
Upvotes: 5
Views: 1642
Reputation: 103790
You can use a rotated pseudo element. Make it 1px wide and make the lines with top/bottom borders :
body {
padding: 0;
margin: 0;
background-image: url('https://farm7.staticflickr.com/6083/6055581292_d94c2d90e3.jpg');
background-size: cover;
}
div {
position: relative;
width: 150px;
margin: 130px auto;
padding: 10px 0;
}
div:before {
content: '';
position: absolute;
top: -120px;
left: 50%;
width: 1px;
height: 100%;
border-top: 120px solid #000;
border-bottom: 120px solid #000;
-webkit-transform: rotate(8deg);
-ms-transform: rotate(8deg);
transform: rotate(8deg);
}
<div>
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec luctus condimentum mi sit amet iaculis. Aliquam erat volutpat. Maecenas eleifend commodo rutrum.</p>
</div>
Upvotes: 4
Reputation: 7122
I think you are looking for this-
body{background: url('http://i.imgur.com/Kv22GCi.png');}
div {
position: relative;
width: 120px;
margin: 100px auto;
padding: 5px 0;
}
div:before {
content: '';
position: absolute;
top: -100px; left: 45%;
width: 1px; height: 100%;
border-top: 120px solid #000;
border-bottom: 120px solid #000;
-webkit-transform: rotate(8deg);
-ms-transform: rotate(8deg);
transform: rotate(8deg);
}
<div>
<h2>dsfsd jf fkljdsfjdsj</h2>
<p>Loream ipsum dolor shit amet</p>
</div>
I hope this will help you.
Upvotes: 1
Reputation: 18228
You can do using pseudo selectors :after or :before
Download this png image for background https://i.sstatic.net/iBjE4.png
.container {
position: relative;
width: 300px;
height: 548px;
border: 1px solid #ccc;
background-image: url(https://i.sstatic.net/iBjE4.png);
padding: 50px;
-moz-box-sizing: border-box;
box-sizing: border-box;
font-family: sans-serif
}
/*For the diagonal line*/
.container:after {
content: "";
position: absolute;
height: 100%;
border: 1px solid #000;
top: 0;
left: 70px;
z-index: -1;
-moz-transform: rotate(10deg);
-ms-transform: rotate(10deg);
-o-transform: rotate(10deg);
-webkit-transform: rotate(10deg);
transform: rotate(10deg)
}
h1 {
font-size: 50px
}
p {
font-size: 22px
}
<div class="container">
<h1>About Us.</h1>
<p>"Lorem ipsum sit amet.Lorem ipsum sit amet.Lorem ipsum sit amet.Lorem ipsum sit amet.Lorem ipsum sit amet.Lorem ipsum sit amet.Lorem ipsum sit amet."
<p/>
</div>
Upvotes: 1