This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Aligning form elements vertically

 
Ranch Hand
Posts: 195
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to align 3 rows of 3 element vertically without using a table. What I am trying to accomplish is something like this

label [.........]  label [.....]      label [.....]
label [.....]      label [.........]  label [.....]
label [.....]      label [......]     label [.........]

Any suggestions with just HTML and CSS?
 
Ranch Hand
Posts: 91
Netbeans IDE Java
 
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CSS grid is great for these kinds of layouts. Also flex for within cells.

But, if you need to support legacy browsers (don't if you don't have to), the easiest path would be to adopt either Bootstrap, or if all you need is a grid, some lighter weight CSS frameworks that provide just grid styling.
 
John Morgan
Ranch Hand
Posts: 195
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for that information. Now I just need to figure out how to align on the left side of the input field and right align the labels.
 
Rancher
Posts: 89
13
Scala Eclipse IDE MySQL Database Tomcat Server Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This guide is what I always used when having trouble aligning

you might also want to try out flexbox froggy here
 
John Morgan
Ranch Hand
Posts: 195
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those work for aligning a full element but I am trying to align based on the left side of the input box with the labels being variable lengths.

label: [.....]
  lbl: [..........]
  id: [......]

(this is hard to do with this but ultimately it needs to align on the [ for each row)
 
Bear Bibeault
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give the labels a display value of inline-block, then use width and text-align.
 
Mano Ag
Ranch Hand
Posts: 91
Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can use a cell for each label itself, and a cell for each of the "[...]"s
 
Bear Bibeault
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be difficult to achieve and still keep the HTML semantic and to properly structure the form elements. Not impossible, just not the easiest path.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use CSS grid for this type of layout.


 
His brain is the size of a cherry pit! About the size of this ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!