Solved

CSS positioning one div directly relative below the previous div

Posted on 2006-06-27
6
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…

751 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