473,748 Members | 7,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to align form controls

72 New Member
Hi,

Can anyone tell me how to use css to line up different types of form controls? Different types seem to behave differently.

I have a textbox, dropdownbox and a button along 1 line across the page. I want to make all of them the same height and vertically align them. Here is my code

Expand|Select|Wrap|Line Numbers
  1. <div>
  2.   <input name="SearchText" type="text" id="tbxSearchText" style="width:50px;font-size:12px;line-height:19px;" />
  3.   <select name="SearchBy" id="ddlSearchBy" style="width:110px;height:19px;font-size:12px;position:relative;bottom:1px;">
  4.   <option value="0">Family Name</option>
  5.   <option value="1">Given Names</option>
  6.   </select>
  7.   <input type="submit" name="btnSearch" value="Search" onclick="return checkForm();" id="btnSearch" class="button" style="height:20px;position:relative;line-height:1.1em;"/>
  8. </div>
  9.  
Thanks
Sep 21 '11 #1
6 5095
drhowarddrfine
7,435 Recognized Expert Expert
'vertical-align' should be working for you. 'height' should work on the text box but won't affect the other input elements since they're part of the browser.
Sep 21 '11 #2
hellodipak
26 New Member
For input text and button you can add height and for select(combobox ) line-height and padding should help to get the same height.
Sep 21 '11 #3
dragon52
72 New Member
It is not perfect but it looks good enough but the code looks really messy.

To make the textbox and button the same I have to use "height:25p x" and "height:15p x" which is not logical.

Thanks guys


Expand|Select|Wrap|Line Numbers
  1. <div>
  2.   <input name="SearchText" type="text" id="tbxSearchText" style="width:50px;height:15px;line-height:5px;position: relative; top: 50%;" />
  3.   <select name="SearchBy" id="ddlSearchBy" style="width:110px;line-height:3px;padding:2px;position: relative; top: 50%;">
  4.   <option value="0">Family Name</option>
  5.   <option value="1">Given Names</option>
  6.   </select>
  7. <input type="submit" name="btnSearch" value="Search" onclick="return checkForm();" id="btnSearch" class="button" style="height:25px;padding-top:3px;padding-bottom:3px;line-height:6px;position: relative; top: 50%;"/>
  8. </div>
  9.  
Sep 21 '11 #4
John Mollman
2 New Member
Hi,

I know this is one week later, but I'll try to help you out here. It seems you already found a solution, but as you said it looks messy. Maybe I can give it a try. I think you're trying to have a clean row of controls, correct?

Try this:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Title</title>
  4.     </head>
  5.  
  6.     <body>
  7.         <div>
  8.             <input type="text" name="SearchText" size="20" />
  9.             <select name="SearchBy">
  10.                 <option value="0">Family Name</option>
  11.                 <option value="1">Given Names</option>
  12.             </select>
  13.             <input type="submit" name="btnSearch" value="Search" onclick="return checkForm();" />
  14.         </div>
  15.     </body>
  16. </html>
  17.  

You could even have them within a table. This is what I normally do when placing form controls on a page. (Although it basically has the same output, it comes in handy when you have a lot of stuff going on, such as text boxes, drop-downs, buttons, etc.)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Title</title>
  4.     </head>
  5.  
  6.     <body>
  7.         <table border="0">
  8.             <tr>
  9.                 <td><input type="text" name="SearchText" size="20" /></td>
  10.                 <td>
  11.                     <select name="SearchBy">
  12.                         <option value="0">Family Name</option>
  13.                         <option value="1">Given Names</option>
  14.                     </select>
  15.                 </td>
  16.                 <td><input type="submit" name="btnSearch" value="Search" onclick="return checkForm();" /></td>
  17.             </tr>
  18.         </table>
  19.     </body>
  20. </html>
  21.  
Oct 3 '11 #5
dragon52
72 New Member
John,

Thanks for your reply.

I have moved on to another part of my project now. I am glad to have received your suggestions though because I will come back to it later. Happy to have a better alternative to my messy code.
Oct 4 '11 #6
drhowarddrfine
7,435 Recognized Expert Expert
First, never use tables for layout.
Second, how does that work without the form element?
Oct 4 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3093
by: Lauren Quantrell | last post by:
In terms of resources, wondering if it makes a difference in adopting one of the three options below for resizing controls on a form and controls on a subform at the same time. option a.) Put the code all in the main form and refer to the controls on the subform in the main form's OnResize event. option b.) Put the code for the main form controls in the main form's OnResize event and put the code for the subform controls in the...
7
4047
by: J L | last post by:
I need to loop through a form's controls collection and delete some based on type and location. I have tried For..Each and For i = 0 to form.controls.count - 1 but when I delete any it messes up the loop. What is the correct way to go about this. I thought this was answered before but can not find it. TIA, John
4
2338
by: Dries De Rudder | last post by:
Hi, I am trying to bind an object to form controls. I've got an object MyObject which has some properties e.g. ID. I've got a form, Form1, that contains a textbox ,TextBox1, now I want to bind the value of the ID-property of a MyObject-object to the TextBox1. I've tried doing this:
2
1680
by: Adam Right | last post by:
Hi, I want to get the controls of the windows form. I know that form.Controls give me the list of controls but i have a problem. For example, the toolstripmenu control cannot be reached with that way. My goal is to list the items of the toolstripmenuitem on the form. I have only the typename of the windows form so i am invoking the form with its typename, and i can reach the controls like buttons,labels etc. But i cannot get the...
1
1395
by: Adam Right | last post by:
Hi, I want to get the controls of the windows form. I know that form.Controls give me the list of controls but i have a problem. For example, the toolstripmenu control cannot be reached with that way. My goal is to list the items of the toolstripmenuitem on the form. I have only the typename of the windows form so i am invoking the form with its typename, and i can reach the controls like buttons,labels etc. But i cannot get the...
7
1548
by: jmp | last post by:
(I hope this isn't considered too far off-topic.) I work as a developer on a browser product found on handheld devices, and I'm trying to specify behavior for the browser to make it "as compatible as possible" with reference browsers (IE, Firefox, Opera, NS, etc??) when presented with HTML content containing form controls (input, textarea, select/option) in the absence of enclosing form element tags. Obviously in the absence of...
8
3586
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
16
4173
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and therefore being able to modify its properties?
9
2519
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett -- comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
10
44085
by: =?Utf-8?B?UmljaA==?= | last post by:
A lot of users at my workplace use different screen resolutions, and I build apps to use 1680 x 1050 pixels res by default. But some users are using 800 x 600, and the apps are too large for their screen. I used to write code in Java a few years ago (2005), and you could stretch a form with the mouse and all the controls and fonts would resize to larger or smaller size. Does .Net framework 3.5 support this kind of functionality? Or -...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.