Connecting Tech Pros Worldwide Help | Site Map

Aligning logo, icon, text, and selection box. Should be extremely easy, but..?

Newbie
 
Join Date: Nov 2008
Posts: 6
#1: Dec 31 '08
Sorry if this sounds like a dumbass newbie question. I'm getting crazy or something, but somehow I can't get this simple thing to work:

1. In general, how do I center text and/or images vertically?

2. How would I do a top bar with a logo on the left, and an icon + text + combobox (small form with one select item) on the right, all vertically centered to eachother?
Like this:



And with "how", I mean: how with proper html/css :)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Dec 31 '08

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


one possibility (maybe not the best, but working):
Expand|Select|Wrap|Line Numbers
  1. <div style="border: 1px solid black;">
  2.     <img src="img1.png" alt="large img" width="50" height="100">
  3.     <span style="line-height: 100px; float: right;">
  4.         <img src="img2.png" alt="small img" width="20" height="20" style="vertical-align: middle;">
  5.         some text
  6.         <input type="radio"  style="vertical-align: middle;">
  7.     </span>
  8. </div>
  9.  
the basic trick is to to apply vertical-align to an inline element that determins the height of the container

note:
inline style only for demo, proper CSS belongs in a css file. (where you can simplify it a bit)

regards
Newbie
 
Join Date: Nov 2008
Posts: 6
#3: Dec 31 '08

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


Thanks, that seems to be somewhat in the right direction!
But two problems arise:

1. The radiobutton thing appears below (outside) the container
(tested with Firefox and IE7, in Opera it looks OK)

2. When putting actual <form> and </form> tags around the input thing, it gets messed up even more :(
(it seems to enforce a linebreak before form or something, but I really need form tags to have that input thing actually do something)

Any suggestions how to overcome that?
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#4: Dec 31 '08

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


vertical alignment is different with input elements because there is no padding and only the margin matters.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#5: Dec 31 '08

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


it depends on the actual code.

- <form> is not allowed inside <span>
- float the big image left and the <span> right should render OK (tried FF)

regards
Newbie
 
Join Date: Nov 2008
Posts: 6
#6: Jan 2 '09

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


Quote:

Originally Posted by Dormilich View Post

it depends on the actual code.

- <form> is not allowed inside <span>

Ah thanks, never knew that :)
But I really need <form> tags to get the selection thing actually working. So do you know any other way (other than form inside span, I mean) to get that working?

Quote:
- float the big image left and the <span> right should render OK (tried FF)
Are you sure? I just tried it here and although the span part and logo are no at the same height, it seems they're now *both* below the div... What used to be a black border is now a single black line above everything.

When I change the background color of body and the div, the div seems completely empty, and the images and stuff appear below it...?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#7: Jan 2 '09

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


Quote:

Originally Posted by Bram2 View Post

Ah thanks, never knew that :)

it's always good to know where to look that up (I use SELFHTML: HTML/XHTML / Referenz /HTML-Elementreferenz (german only, but you might get the info though (english version suspended))
Quote:

Originally Posted by Bram2 View Post

But I really need <form> tags to get the selection thing actually working. So do you know any other way (other than form inside span, I mean) to get that working?

put the <form> tags before and after the span.
Quote:

Originally Posted by Bram2 View Post

Are you sure? I just tried it here and although the span part and logo are no at the same height, it seems they're now *both* below the div... What used to be a black border is now a single black line above everything.

yea, there's practically no content in the <div>. apply a height to the <div> (if you don't need the border or the background you may also omit the <div>).
Expand|Select|Wrap|Line Numbers
  1. // CSS
  2. #top {
  3.     border: 1px solid black; 
  4.     height: 150px;
  5. // add padding, margin to your liking
  6. }
  7. #left {
  8.     float: left; 
  9.     line-height: 150px;
  10. }
  11. #right {
  12.     float:right; 
  13.     line-height:150px;
  14. }
  15. #left *, #right * {
  16.     vertical-align: middle;
  17. }
  18.  
  19. // HTML
  20. maybe some text
  21. <form>
  22. <div id="top">
  23. <span id="left">
  24.     <img width="100" height="100">&nbsp; 
  25. // you need a character to align the image in FF
  26. </span>
  27. <span id="right">
  28.     <img width="50" height="50">
  29.     text
  30.     <input type="radio"> // might need small corrections
  31. </span>
  32. </div>
  33. and some more text
  34. </form>
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#8: Jan 6 '09

re: Aligning logo, icon, text, and selection box. Should be extremely easy, but..?


found an article about clearing floats with CSS (so the height property on div is not necessary): Clearing a float container without source markup
Reply

Tags
align vertically, form, image, text


Similar HTML / CSS bytes