Solved

CSS positioning one div directly relative below the previous div

Posted on 2006-06-27
6
401 Views
Last Modified: 2010-05-18
Say I have my sheets like this:
#questionone
{
 font-family: "Times New Roman";
 font-size: large;
 float: left;
      padding: 10px;
      margin: 20px;
      background: #ccc;
      border: 5px solid #666;
      width: 400px;
      voice-family: "\"}\"";
      voice-family:inherit;
      width: 370px;
}

this forms a nice little box, and I have about 5 of these in the page. I'd like to make a div #sidebar that positions icons directly below the previous box. It has to be in a different div though because I change the contents of the questionone div with AJAX. Thanks for any help and please let me know if need to eloborate.

0
Comment
Question by:stormist
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 16997399
Are you saying each box has a set of icons directly below it? Then I'd do something like this:

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

<style type="text/css">
.mainBox
{
 font-family: "Times New Roman";
 font-size: large;
 float: left;
     padding: 10px;
     margin: 20px;
     background: #ccc;
     border: 5px solid #666;
     width: 400px;
     voice-family: "\"}\"";
     voice-family:inherit;
     width: 370px;
}
.qBox {background:#FFF;}
.icons {border-top:2px solid red;}
</style>

</head>
<body>
  <div class="mainBox">
    <div id="question1" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question2" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question3" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question4" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question5" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
</body>
</html>

Basically, you set up a box to handle your positioning - or floating. Then within that box are your AJAX containers and directly below are your icon boxes. Should be pretty straight-forward. But not being entirely familiar with what you want to do, let me ask this: Is this what you're after in the first place?

GoofyDawg
0
 
LVL 10

Author Comment

by:stormist
ID: 17003045
That seems to work really neat except I like the box expanding or contracting based upon the size of the question. Is there a way to do that? Also, might you know how to expand the box into a textarea with the question still on top and the icons still on bottom upon click ? Thanks very much for your reply.

0
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 17003323
>That seems to work really neat except I like the box expanding or contracting based upon the size of the question. Is there a way to do that?

Hmmm... that's a tough one because floating with a div usually entails assigning it a width. But I guess the question I have on a higher level is this: What are you trying to accomplish in your application?

On another note, you could assign a percentage width to your boxes, and define .mainBox like so:
.mainBox
{
 font-family: "Times New Roman";
 font-size: large;
 float: left;
     padding: 10px;
     margin: 20px;
     background: #ccc;
     border: 5px solid #666;
     width: 20%;
}

>Also, might you know how to expand the box into a textarea with the question still on top and the icons still on bottom upon click ? Thanks very much for your reply.

Are you asking if you could put an answer box in the div and have it expand? Building on the class example above, you could add a textarea and give it a width of 100% - just make sure you don't assign a "col" value. Here's an example building on the code in the previous example:

  <div class="mainBox">
    <div id="question1" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <textarea rows="10" style="width:100%;"></textarea>
    <div class="icons">ICONS GO HERE</div>  
  </div>

See how that works for you. With respect to the expanding boxes based upon the "size" of the question, I don't think it's possible except with Javascript, and then the solution starts getting pretty hairy.

GoofyDawg
0
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.

 
LVL 10

Author Comment

by:stormist
ID: 17012100
Hello GoofyDawg,

What I'm trying to accomplish is five question boxes that the user answers. The boxes can be changed with a click of an icon below the box by an Ajax request. Some questions are only a few words while some are whole paragraphs, so the altering the box based upon the size is more visually appealing. Might there be a way to put the icons below the box rather than inside it? Thanks so much for your replies, and sorry for my responses taking so long I always tinker with the awesome examples you've been giving me.


0
 
LVL 12

Accepted Solution

by:
GoofyDawg earned 500 total points
ID: 17012340
The whole idea behind my first example was to have the "qBox" class be the content container, and "icons" class to control the icons. Then wrapping both with the mainBox handles the positioning on the page. Note that qBox should be visually styled like your original question box. "mainBox" on the other hand has no visual styling. It's just a container. The effect then is that the icons will appear as if they're outside the question box. Here's some code with the modified CSS:

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

<style type="text/css">
.mainBox {float:left;width: 20%;margin:20px;}
.qBox {
 font-family: "Times New Roman";
 font-size: large;
 padding: 10px;
 background: #ccc;
 border: 5px solid #666;
}
.icons {border:2px solid red;}
</style>

</head>
<body>
  <div class="mainBox">
    <div id="question1" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question2" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question3" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question4" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
  <div class="mainBox">
    <div id="question5" class="qBox"><br><br><br><br>AJAX BOX<br><br><br><br></div>
    <div class="icons">ICONS GO HERE</div>  
  </div>
</body>
</html>

It all boils down to how you want to style your containers...

GoofyDawg
0
 
LVL 10

Author Comment

by:stormist
ID: 17012389
I really like how that looks, is it possible to have the first 2 boxes on the left side, the 3rd one in the middle, and the last 2 on the right side? Like a visually appealing X with the boxes.. Forgive me for my CSS noobiness :)

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

860 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