Solved

CSS positioning one div directly relative below the previous div

Posted on 2006-06-27
6
399 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
(URGENT) Help HTML and CSS Resizing Images 2 40
bootstrap table auto width input box 1 37
text on slider doesn't resize nicely 5 38
Synchronizing CSS load 3 29
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

24 Experts available now in Live!

Get 1:1 Help Now