Solved

bargraph behind text lines?

Posted on 2004-03-20
4
260 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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
You're welcome - and have a nice weekend :-)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now