What is the best way to design a form like this using CSS and potentially incorporating some JavaScript techniques?

In my current design, I have form labels positioned inline to the left of text fields, with each label varying in width. My goal is to align the right edge of the text fields.

Here is how the fields currently appear, with the right edge misaligned:

Name: _____________

Address: _____________

City: _____________

I am aiming for a layout like this:

Name: _______________

Address: _____________

City: _________________

Is there a way to achieve this without setting a fixed width on each text field?

Answer №1

While it may not be the most efficient method, a potential solution could involve creating a separate table for each field.

HTML

<table>
    <tr>
        <th>Name:</th>
        <td><input type="text"></td>
    </tr>
</table>

<table>
    <tr>
        <th>Address:</th>
        <td><input type="text"></td>
    </tr>
</table>

<table>
    <tr>
        <th>City:</th>
        <td><input type="text"></td>
    </tr>
</table>

CSS

table { width: 300px; }
td { border-bottom: 1px solid black; }
th { width: 1em; }

input { width: 100%; border: none; }
input:focus { outline: none; }

​ ​ JS Fiddle: http://jsfiddle.net/BUy6f/2/

Answer №2

To achieve a borderless look, consider using a table without borders, here's an example: Sample

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to customize a website's content based on the browser by utilizing media queries?

After numerous attempts, I still can't seem to resolve the issue of my website appearing differently on Firefox and Edge browsers; the container seems to be misaligned and shifted. I have spent hours scouring the web for a solution with no luck. My ul ...

How can I make a div blur as I scroll through the page

How can I make each item in my timeline focused one at a time as the user scrolls, instead of having all items in focus simultaneously? Any ideas or suggestions would be appreciated. Here is my fiddle and here is my code $(document).ready(function(){ ...

Has window.document.height become obsolete in the latest version of Chrome, version 17?

After recently upgrading to the most recent version of Chrome (17.0.963.56), I've noticed that the property window.document.height is no longer valid. Has anyone else experienced this issue? I haven't been able to find any information about why i ...

Jquery's .text() and .html() methods seem to be malfunctioning

Utilizing a jQuery function: $("#btn1").click(function(){ $("p").text("") } Each time the button is clicked, the .text() field fails to load. When I modify the value of .text to a shorter string, it functions correctly. ...

Animating a SVG element within a group tag using the path element

I'm struggling to make a slice of a circle rotate using the :hover selector in CSS. Even though my initial attempt at applying CSS transformations works perfectly, the rotation stops when I introduce the :hover selector. Below is the HTML and CSS co ...

The 600 pixel wide page is not completely filling the 640 pixel width screen on a mobile device

Currently, I am conducting a test on a webpage using an iPhone 5s with a screen resolution of 1136 x 640 pixels. The meta tag is set as follows: <meta name="viewport" content="user-scalable=yes, initial-scale=1, width=device-width, shrink-to-fit=no"&g ...

Applying Regular Expressions in Java to "convert" a CSS style into an HTML tag style

In my Java code, I have a String variable that contains HTML code like this: <span style="text-decoration: underline;">test</span> My goal is to convert it to look like this: <u>test</u> If the HTML code is like this: <span ...

Experience a seamless integration of playing videos in the background using HTML5 with responsive design

Looking for a CSS trick to create a video background that spans the full width of the browser and auto resizes with the browser size. It's essential that it plays on Safari, so please specify the supported video file types. ...

Tips for showcasing two cards side by side on mobile screens?

This is my glitch. I have a layout where I see 3 cards in a row for desktops, 2 cards per row on tablets, and 1 card for mobile devices. However, I would like the cards to resize and display 2 cards in a row on mobile. How can I achieve this? Here is the f ...

How to Retrieve Checkbox Values from Multiple Rows Using JavaScript

I have a variety of module rows that allow users to manage access rights by selecting specific options. My goal now is to extract the checked boxes from these checkboxes with the name "config{{$field->id}}". Below is the current functioning code. HTM ...

Creating a mobile-friendly table that remains within a specific width on smaller screens (CSS)

Ensuring consistency across all tables on my website is crucial to me, which is why I am utilizing the same class for all of them. While everything appears perfect on desktop, I'm facing challenges when it comes to mobile responsiveness. The tables fa ...

How to display a PDF file stored in the documents directory of an iOS device with Phonegap

I'm encountering an issue when it comes to displaying a PDF using HTML, PhoneGap, or JavaScript. The web application I'm working on is developed in Sencha Touch 2. Here's exactly what I need: I need to display a PDF file located in the d ...

Tips for resizing a background image horizontally without changing its height

Having a background image that is taller than the page and setting it as the background for the wrapper has caused some issues. Resizing the window results in a large amount of white space under the background image due to the fixed height of the wrapper. ...

What is the best way to link CSS files from libraries that are downloaded using npm?

For instance, let's say I installed a package: npm install --save package and it gets saved in ./node_modules/package/ Inside that folder, there might be a directory named styles and within that directory, you could find style.css. How can I link ...

Styling Angular2 Material Dialog: the perfect fit

The Angular2 material team recently unveiled the MDDialog module at https://github.com/angular/material2/blob/master/src/lib/dialog/README.md I am interested in customizing the appearance of Angular2 material's dialog. Specifically, I want to adjust ...

Are you experiencing empty boxes instead of Glyphicons in Bootstrap 3?

Having some trouble using Glyphicons with Bootstrap 3. I've noticed that a few of them aren't displaying properly. For instance, when trying to use these three glyphicons, the first one doesn't seem to show up correctly (appears as an empty ...

Is it possible to minify HTML in PHP without parsing JavaScript and CSS code?

After finding a solution in this discussion, I successfully managed to 'minify' HTML content. function process_content($buffer) { $search = array( '/\>[^\S ]+/s', // eliminate spaces after tags, except for ...

I am looking to create a line similar to the one shown in the attached image using HTML and CSS

I am trying to create a line similar to the image provided using HTML/CSS. https://i.sstatic.net/skZOd.png I attempted to achieve this using two different divs but did not get the desired result. Any suggestions on how to accomplish this? I have experi ...

Manipulating lines and positions with jQuery

I am looking to implement a feature that allows users to choose a specific region on an image using jQuery. The functionality should be similar to the tagging feature on Facebook, but with the added bonus of being able to rotate and scale the selected area ...

Modify background image upon hovering using AngularJS

I cannot seem to make the background images of my divs change. Despite trying various options, none of them have been successful. Here's an example of my code: <div ng-controller="mainController" class="main"> <div ng-repeat="land in lan ...