2

How to repeat a character( let's say a .) such that the width of line drawn using dots is always same as screen width. I am currently drawing the line of dots using the following code:

<label style="color:red">...........................</label>

Clearly, the number of dots are fixed in this case. My goal is to draw a line matching screen width. I am a beginner in web designing; so, any help would be greatly appreciated.

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
Deep Arora
  • 1,900
  • 2
  • 24
  • 40

3 Answers3

4

You are on the wrong track.

<label style="color:red">...........................</label>

this is not how you draw a dotted line.

its done by dotted borders fiddle: http://jsfiddle.net/rrce76r9/

<div class="dotted"></div>

.dotted{
    border-bottom:3px dotted red;
}
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
  • How can I also make sure that their is some space on the left and right side of the dotted line?. I tried adding margin-left and margin-right property in the above css class. Strangely, I was able to have white space on the left of line; but not on the right. This is what I wrote: .dotted{ border-top:2px dotted red; margin-left:50px; margin-right: 50px; } – Deep Arora Nov 06 '14 at 10:22
  • htake a look at this question dep2k http://stackoverflow.com/questions/6250394/how-to-increase-space-between-dotted-border-dots – Naeem Shaikh Nov 06 '14 at 10:31
  • This does not answer the question asked. It is true that it may answer a better question that should have been asked instead, but SO is organized as questions with answers to them. – Jukka K. Korpela Nov 06 '14 at 11:05
1
//Now All the lines is available for you whatever u can choose...

// This is Html Code. Name of this file u can give like Borders.html

    <html>
    <head>
        <title>
            Border Test
        </title>
        <link rel="stylesheet" href="borders.css" type="css/text"/>
    </head>
    <body>
        <h1 id="solid">This is solid Border</h1>
        <h1 id="dotted">This is dotted Border</h1>
        <h1 id="dashed">This is dashed Border</h1>
        <h1 id="double">This is double Border</h1>
        <h1 id="groove">This is groove Border</h1>
        <h1 id="ridge">This is ridge Border</h1>
        <h1 id="outset">This is outset Border</h1>
        <h1 id="inset">This is inset Border</h1>
    </body>

</html>

//This is Css code for the above Html file. You can give the name of this file as Borders.css.

#solid
{
    border-bottom:2px solid black; //here u can use border-top,border-left, border-right also instead of border-bottom.
}
#dotted
{
    border-bottom:2px dotted black;
}
#dashed
{
    border-bottom:2px dashed black;
}
#double
{
    border-bottom:2px double black;
}
#groove
{
    border-bottom:2px groove black;
}
#ridge
{
    border-bottom:2px ridge black;
}
#outset
{
    border-bottom:2px outset black;
}
#inset
{
    border-bottom:2px inset black;
}
1

You cannot make a row of characters exactly the same width as some given width, such as the entire available width, which is what you probably mean by “screen width”. But I think you meant to ask to write as many “.” characters as possible on a single line, within the constraints of available space. The constraint is really the parent element’s width, so we can achieve this by repeatedly appending “.” until we exceed that constraint, then take one step back:

<span id=dots style="color:red"></span>
<script>
var dots = document.getElementById('dots');
dots.style.visibility = 'hidden';
var width, savedContent;
do {
  savedContent = dots.innerHTML;
  dots.innerHTML += '.';
} while(dots.offsetWidth < dots.parentNode.offsetWidth);
dots.innerHTML = savedContent;
dots.style.visibility = 'visible';
</script>

The example uses span instead of label, since such text is hardly suitable for use as a label for a control. However, this choice of element does not affect this issue.

Note that the string, once created, will stay the same, even if the browser window width is changed in a manner that changes the parent element’s width (e.g. when our element is a child of body and we have no width settings in CSS).

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390