Ruled paper like background effect using CSS3

Posted in: css by musiitwa joseph 2016-02-01 at 03:17:43

image for Ruled paper like background effect using CSS3

Adding a background image that has lines for a paper is somehow easy but when it comes to making the text fit in between the lines is quite not easy. This is because most elements have default margins and padding and also there is a default line height for the text. We are going to remove the margins and padding of all the elements in the section which has the background image and also adjust the line height so that the words fit.

I have also added two pseudo elements that is before and after just to create a stack of papers and pin image to make the stack of paper appear as if it was attached on something.

<!doctype html>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="paper-like.css"/>
    <div class="paper">
        <img src="images/pin.png" alt=""/>
            <!-- Content goes here-->
               <p>The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart.

Helen Keller</p>



    /*you can change the background color*/
    background:#FFFFCA url(../images/horizontal_lines.png) repeat;
    margin:30px auto;
    padding:30px 15px;
    border:1px solid #DDD;
    box-shadow:0 0 10px #DDD;
/*Turning all the default margin and padding to zero*/
.paper *{
.paper img{

/*Leaving a blank line before the start of every heading*/
/*you can also do it for paragraphs*/
.paper h1, .paper h2, .paper h3, .paper h4, .paper h5, .paper h6{

/*Pseudo elements to create a stack of papers*/
.paper::before, .paper::after{
    background:#F4F4AB url(../images/horizontal_lines.png) repeat;
    box-shadow:0 0 5px #999;