CSS positioning one div directly relative below the previous div

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.

LVL 10
stormistAsked:
Who is Participating?
 
GoofyDawgConnect With a Mentor Commented:
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
 
GoofyDawgCommented:
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
 
stormistAuthor Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
GoofyDawgCommented:
>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
 
stormistAuthor Commented:
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
 
stormistAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.