Author Topic: CSS help... again  (Read 2656 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
CSS help... again
« on: February 16, 2012, 09:49:49 AM »
Ok, so I'm sort of an idiot when it comes to some float type stuff.  What I need to do is display question text and inputs side by side and I don't want to do it with tables, so take this example:

Code: [Select]
<div class="question">
   <div class="questiontext">Date of Birth (DD/MMM/YYYY):</div>
   <div class="questioninput"><input type="text" /></div>
</div>

I'm going to have many 'question' classes and I just want to put the question text and question input side by side in those boxes.  If I float both of those, it ignores both the 'question' div and the div that surrounds all questions... HELP?

EDIT: oh, and the text and input divs must have a % width... 60/40 (roughly).

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: CSS help... again
« Reply #1 on: February 16, 2012, 09:59:24 AM »
How I do it:
Code: [Select]
<fieldset>
<div>
  <label for="dob">Date of Birth (DD/MM/YYYY):</label>
  <input type="text" id="dob" name="dob" />
</div>
</fieldset>
Note that the fieldset can also be a div if you don't like the fieldset graphics.  I don't have the specific CSS but is is something like
Code: [Select]
fieldset label {
  display: block;
  width: 150px;
  /* Other stuff */
}
fieldset input {
  float: left;
  margin-left: 150px;
}

When i get to work in an hour or so I'll try to look up the full CSS.  But using just using label and no inner divs will get you side by side  elements.  The width and float stuff are just to align things nicely.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: CSS help... again
« Reply #2 on: February 16, 2012, 10:11:13 AM »
yeah, what Mike said.  The key is to give the form field a margin-left equal to the width of the label field (plus a little padding)

for example on: http://cwhf.org/get-involved/rose-garden/submit

Code: [Select]
<div class="form_row">
   <div class="form_label">
     <label for="first">First Name:</label></div>
   <div class="form_field">
    <input name="first" type="text" id="first"  value="" size="25" maxlength="255" />
   </div>
 </div>

<style tyle="text/css">
.form_label{
  float: left;
  width: 150px;
  text-align: right;
  }
  .form_row{
clear: both;
margin-bottom: 8px; 
  }
  .form_field{
  margin-left: 155px;
  }
</style>
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #3 on: February 16, 2012, 10:30:59 AM »
OK, so this seems to work (thanks Micah):

Code: [Select]
.questiontext {
    width: 60%;
    float: left;
}

.questioninput {
    margin-left: 60%;
}

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #4 on: February 16, 2012, 04:58:20 PM »
shit.... any ideas how to have 4 columns?

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: CSS help... again
« Reply #5 on: February 16, 2012, 05:08:18 PM »
something like this...

Code: [Select]
<div id="container">
 <div class="column">column 1 content</div>
 <div class="column">column 2 content</div>
 <div class="column">column 3 content</div>
 <div class="column">column 4 content</div>
</div>

<style type="text/css">
*{ padding: 0; margin: 0 }

#container{
 width: 1000px;
}
 .column{
 width: 250px;
 float: left;
}
</style>
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #6 on: February 17, 2012, 09:07:44 AM »
I swear I tried that... grrr... thank you.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #7 on: February 17, 2012, 09:36:26 AM »
OK... I did try that... the problem is that the floated boxes inside the container aren't actually tied to the container.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #8 on: February 17, 2012, 09:38:11 AM »
See the white box?  That is my container (shown on hover).  The question and the input should be inside of that and they're not.

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: CSS help... again
« Reply #9 on: February 17, 2012, 10:06:37 AM »
You need a clearfix to handle that.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #10 on: February 17, 2012, 10:15:15 AM »
Yeah, I just realized that clear: both would fix it at the end of the container... but I wonder if there is an advantage to the clearfix?  He doesn't state a clear advantage in that article.
http://www.webtoolkit.info/css-clearfix.html

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: CSS help... again
« Reply #11 on: February 17, 2012, 10:26:25 AM »
Nevermind... still reading.  Looks like the clearfix has significant advantages.

I'm using this one: http://css-tricks.com/snippets/css/clear-fix/ (the last one)