Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Generate horizontal lines inside div

    Is it possible to fill a div with horizontal lines using css?



    Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,143
    Thanks
    7
    Thanked 257 Times in 256 Posts
    Sure, use background-image:
    Code:
    #content {background-image:url('lines.png')}
    Dave

  • #3
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,673
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello vishal_ok12,
    I'm not sure what it's intended for, but the lines are easy to put under some sort of content. There is no specific CSS way of generating lines though.

    Look at this example with an empty ul, assuming you have a semantic reason for using a ul...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	background: #fc6;
    }
    #container {
    	width: 400px;
    	margin: 30px auto;
    	padding: 20px;
    	background: #ccc;
    }
    ul { 
    	margin: 0;
    	padding: 0;
    	list-style: none; 
    }
    li {
    	height: 14px;
    	border-bottom: 1px solid #000;
    }
    </style>
    </head>
    <body>
        <div id="container">
        	<ul>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            	<li></li>
            </ul>
        <!--end container--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #4
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts
    Hi vishal_ok12,

    From what I've found, Excavator is correct. There's no simple way to create repeating horizontal lines in css and html. Below, I came up with something that works, but, like Excavator's, it's not a simple line of code; it's several lines of code.

    VIPStephan, an expert coder here at CodingForums, once stated a few weeks ago that simple, empty div tags are not pure coding techniques. My method may fall into that impure concept. I apologize to VIPStephan if I misunderstood his comment. At the time, he was referring to floats. It seems to me that empty div tags are pretty silly. Maybe he will post to this.

    The following code does validate, so it should work without causing conflicts; but, again, a more experienced coder may tell us that this is impractical.

    Tracknut's method would certainly be the easiest and fastest.

    Code:
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <title>Horizontal Line Repeat</title>
        <style type="text/css">
    #container {
         width:450px;
         height:432px;
         border: 1px solid #000;
         background-color:#f1f5fb;
         margin: 70px auto; }
    .repeatline-div {
         width:450px;
         margin-top:18px;
         background-color: #cacaca;
         height:1px; }
    .repeatline-div div {
         position:absolute;
         margin-top:18px;
         width:450px;
         background-color: #cacaca;
         height: 1px; }
        </style>
      </head>
      <body>
    <div id="container">
    <div class="repeatline-div">
    <div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>
    </div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
    </div></div>
      </body>
    </html>
    --Kevin

    .
    Last edited by Kevin_M_Schafer; 01-21-2012 at 07:02 PM. Reason: text clarity
    My keyboard is an IBM from 1993 and I like it that way. | Who is Dan Well? Everyone always says I know Dan Well.Building a web page is like building a birdhouse. Put it up there and watch 'em come. | Maintaining the aspect ratio of an image is more important than having a cold orange pop.

  • #5
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    There are a lot of things you can do with content:after {} and counters, including the <hr />'s for lines, but I don't think I have the patience to figure that out. content: ; and :before & :after don't work in IE6 or IE7 either
    http://nicolasgallagher.com/pure-css-gui-icons/

    Just use an image, it's very, very easy.
    http://www.youtube.com/watch?v=PUWqZvVEtUs

    Basically, you just create a small pattern of squares, then you repeat it. That's all there is to it.
    Last edited by Sammy12; 01-21-2012 at 07:19 PM.

  • #6
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,143
    Thanks
    7
    Thanked 257 Times in 256 Posts
    Boy, you guys sure saw a different question here than I did!

    Dave

  • #7
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts
    Hi Dave,

    Lol! I was almost done creating what I used before I thought of using an image! I think an image would really be easiest way to go.

    Don't forget, though, my and Excavator's way simply shows that you can, indeed, travel east by sailing west.

    --Kevin

    .
    My keyboard is an IBM from 1993 and I like it that way. | Who is Dan Well? Everyone always says I know Dan Well.Building a web page is like building a birdhouse. Put it up there and watch 'em come. | Maintaining the aspect ratio of an image is more important than having a cold orange pop.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •