473,698 Members | 2,972 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 5093
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
3088
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
4045
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
2331
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
1678
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
1387
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
1541
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
3579
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
4165
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
2513
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
44078
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
8611
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
9031
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...
0
8876
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
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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
4372
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...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.