views:

44

answers:

2

I started the source from this progressbar example, and it works fine. My only change was to set the width of the progressbar to "20%".

<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt;

  <script>
  $(document).ready(function() {
    $("#progressbar").progressbar({ value: 37 }).css({ width : "20%"});
  });
  </script>
</head>
<body style="font-size:62.5%;">

<div id="progressbar"></div>

</body>
</html>

I then put the progressbar inside another div, and used css to fix that div in the upper-right-hand corner.

<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <style type="text/css">
    #testContainer {
      position : fixed;
      top : 6;
      right : 6;
    }
  </style>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt;

  <script>
  $(document).ready(function() {
    $("#progressbar").progressbar({ value: 37 }).css({ width : "20%"});
  });
  </script>
</head>
<body style="font-size:62.5%;">

<div id="testContainer">
    <div id="progressbar"></div>
</div>

</body>
</html>

The progressbar becomes a slim vertical line on the left side of the screen. What am I doing wrong? I'm new to web development in general, and jquery in particular, so please forgive me if this is a stupid question.

A: 

You need to define a width for div#testcontainer.

marapet
I added "width : 20%" to the style for #testContainer, but it didn't seem to have any effect.
Matthew
I tested with FF and IE8, it worked. What browser are you using?
marapet
Oops, I was just missing a semicolon. Now the progress bar shows up, but it is displayed on the left side of the page, rather than the right.
Matthew
I edited your css and used top : 6px;right : 6px; (with "px"), and it worked
marapet
+1  A: 

The width property is setting the element's width to 20% of the width of its containing block, which is body in the first example but the div with the id "testContainer" in the second example.

Because testContainer has a fixed position and no other content, it will not have any width. Give it an explicit width and it should do what you want.

Syntactic
Thanks! This makes the progressbar visible, but it still appears on the left side of the page, rather than being fixed in the upper-right-hand corner. Any idea why?
Matthew
Give your `top` and `right` properties a unit. The value `6` on its own won't work; it needs to be something like `6px`.
Syntactic
Ah, simple. Thanks for your help!
Matthew