Solved

bargraph behind text lines?

Posted on 2004-03-20
4
264 Views
Last Modified: 2010-04-09
How can I put a colored background behind a line of text with a width that is some number of pixels and not related to the width or character spacing of the text.

So, I have a list of file names and I want to add a sort of a bar graph that shows how big the file is, but I don't want to take up any space in the listing. I have a nice little yellow span with a width that follows the file size, but it shows up after the file name and not behind the file name.

html+=f.Name+"<span style='width:"+f.Size*scale+"px;color:red;background-color:yellow;height:3px;'></span><BR>";

If I do absolute position and the window is resized causeing something above the list to wrap, don't I have to recalculate all the absolute positions? I want the position to be 0,0 relative to the start of each file name.

browser compatibility would be nice but I'll accept an IE only answer.
0
Comment
Question by:JamesNewton
  • 3
4 Comments
 
LVL 31

Accepted Solution

by:
seanpowell earned 500 total points
ID: 10641253
One way to do it:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Vertical Centers</title>
<style>

#back
{
    position:absolute;
    height:20px;
    width:50px;
    background-color:red;
    z-index:-2;
}

#text
{
    position:relative;
    z-index:1;
}

</style>
</head>
<body>

<div id="text">
<div id="back"></div>
This text displays on top of the colored background
</div>

</body>
</html>
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 10641261
>>If I do absolute position and the window is resized causeing something above the list to wrap, don't I have to recalculate all the absolute positions?

In this case, the text div is positioned with relative, so the absolute position is in relation to the parent div - not the browser window...
0
 
LVL 2

Author Comment

by:JamesNewton
ID: 10642244
Cool! The zindex on the text had to be -1 rather than 1 but it works fine, and thank you!
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 10642251
You're welcome - and have a nice weekend :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Html test in IIS 4 23
Multiflying 2 Input Text On a Table 7 31
Angular won't showing my array result in HTML 3 28
Fix Form size HTML 16 15
Find out what you should include to make the best professional email signature for your organization.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question