Utilize the text input to occupy the remaining space within a row, flanked by two other elements

In my HTML, I am struggling with the alignment of a 'row' div that contains a label, text input, and hyperlink. The issue arises when I try to make the width of the input always fill the available space between the label and the hyperlink. Despite multiple attempts, I have not been successful in achieving the desired layout. It seems like using some clever margin adjustments could solve the problem by preventing the a tag from being absolute, thus allowing the input to fit neatly between the label and the a. However, I am now uncertain about what else to attempt.

The following is my HTML code:

<fieldset id="ctl00_cph_previousContacts" class="previousContactsArea">
  <legend>Previous Contacts</legend>
  <div class="email-row">
    <label for="ctl00_cph_addressTo">To</label>
    <input name="ctl00$cph$addressTo" type="text" id="ctl00_cph_addressTo" class="email-address text" />
    <a href="#" id="ctl00_cph_addToAddressTo">Add...</a>
    <span id="ctl00_cph_addressToValidator" dynamic="True" style="display:none;"></span>
  </div>      
</fieldset>

Below is the corresponding CSS:

.manualNotification #recipientsTab .email-row {
    margin-top: 5px;
    margin-bottom: 5px;
}

.manualNotification #recipientsTab .email-row label {
    display: inline-block;
    width: 50px;
    text-align: center;
}

.manualNotification #recipientsTab .email-row a {
    position: absolute;
    width: 50px;
    right: 10px;
    margin-left: 10px;
}

Answer №1

Utilizing Flexbox for proficient layouts

.email-row {
  margin-top: 5px;
  margin-bottom: 5px;
  display: flex;
}
.email-row label {
  flex: 0 0 50px;
  text-align: center;
}
.email-row input {
  flex: 1;
}
.email-row a {
  flex: 0 0 50px;
  margin-left: 10px;
}
<fieldset id="ctl00_cph_previousContacts" class="previousContactsArea">
  <legend>Previous Contacts</legend>
  <div class="email-row">
    <label for="ctl00_cph_addressTo">To</label>
    <input name="ctl00$cph$addressTo" type="text" id="ctl00_cph_addressTo" class="email-address text" />
    <a href="#" id="ctl00_cph_addToAddressTo">Add...</a>
    <span id="ctl00_cph_addressToValidator" dynamic="True" style="display:none;"></span>
  </div>
</fieldset>

See Flexbox in action with JSfiddle Demo

Answer №2

To enhance your website styling, ensure to incorporate the following CSS snippet at the end of your existing CSS code:

div.email-row{max-width: 30%; float:left; margin-right:20px}

For a better understanding and visual representation, you can refer to the links provided below:

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

Create a dynamic effect by adding space between two texts on the page

const Button = () => { const options = ['test1', 'test2', 'test3']; return ( <div style={{ position: 'absolute', left: '8px', width: 'auto', flexDirection: 'row' ...

The issue of transform scale not functioning properly in conjunction with background clip and gradients in CSS

Looking to transform a div with the transform: scale(-1,1) property while using background-clip: text on the text within it. However, this causes the text to disappear. Here's what I've attempted: .reverse { transform: scale(-1, 1); } .gr ...

When the field is clicked into for the second time, the month and year picker values will update

I recently implemented a month and year date picker code I found on a website. While I was able to customize the date format (mm/dd/yy) and successfully select values, I encountered an issue where the selected date changes drastically when clicking away fr ...

Issue with spacing between elements in Tailwind/Nuxt - elements appear too close together

There seems to be a spacing issue when using tailwind v3.4.3 on the Tailwind Playground, with extra space added between span elements. <div> <p> <span class="bg-slate-800">TEST</span> <span class="bg-oran ...

Flashing bug in the outFunction of jquery hover()

My friends and I are working on a website for a class project, but we're running into a strange issue with the outFunction part of our hover function. Whenever the mouse hovers over an element, a grey square fades in using .fadeIn(), but then immediat ...

Passing a variable using a button's value attribute in jQuery

My goal is to develop a form in my application where users can input their name and address. Once the user enters the information, I need to validate it and add it to an array before submitting it to the PHP function. Additionally, I want to provide users ...

What are the best practices for incorporating an ASP variable into Javascript code?

Trying to incorporate an ASP variable into JavaScript code, but encountering difficulties. How can this be achieved? Any suggestions? <% dim strMyString strMyString = "hello there" %> <HTML> <body> <%=strMyString%> ...

The scroll bar will be automatically reset once the content inside is updated by using the $selector.html() function

I am looking to create a dynamic scrollable content feature. Initially, I retrieve the data and set the content as follows: $("#sub_menu li").on("click", function () { $("#gallery").html(get_html($(this).attr("id"))); $("#gallery").cs ...

What is the best way to update placeholders in Angular 8+?

I have a collection of items: a = ['apple', 'mango', 'grape', 'papaya', 'banana', 'cucumber']. An input element is present with a placeholder stating select from fruits (the array elements should ...

Hiding components in Angular 4/5 through routing decisions

Just getting started with routing in Angular 4/5, I am currently following the tutorial provided on the official Angular website. I have an Angular application and I want to create two separate pages. Currently, the main page is located at localhost:8870/d ...

How to set a DIV width in CSS to enable scrolling on an iPad 2

Greetings, I have a simple CSS query that I would like assistance with. I am currently grappling with the concept of managing widths in CSS. I have an absolute positioned <div> that contains a relatively wide table. The width of the <div> is s ...

Troubleshooting: jQuery Rain's "Animated Menu Icon" does not respond to click event

Using JQuery Rain to create an animated menu, but encountering difficulty adding onclick functionality to menu items. The effect is visually appealing for both the menu button and sub-menu item. Attempting to add onclick="alert(1);" to one of the sub-menu ...

Proper application of article, aside, and header elements

Can someone help me with my page template setup? I have a sidebar on the left and main content area on the right. I'm wondering if I am using the article, aside, and header tags correctly. Also, should I attach classes/ids to html5 elements or is that ...

What is the name of the syntax highlighting plugin utilized by the Bulma CSS framework?

Does anyone know the name of the code highlighter plugin that is featured on bulma.io? I have tried looking through all sources and scripts, but I can't seem to find the plugin's name. Attached is a screenshot for reference: https://i.sstatic.n ...

Issues arise when using jQuery to manipulate HTML content within an Asp.Net environment

Recently, I found myself in a puzzling situation with a div that has the attribute runat="server". <div id="results" runat="server" class="results"></div> Using jQuery, I added HTML content to this div. $('.results').html('Add ...

How do I use jQuery to animate a height increase where the added height is applied to the top of the element?

I am facing a simple issue that I need help resolving. The problem involves hidden content that, once expanded, needs to have a height of 99px. When collapsed, the container holding this content section#newsletter is set to be 65px in height. If you want ...

What is the process to change the URL?

Currently, I am deep into developing a large-scale web application for a company. The project has been ongoing for about four months now, and we have encountered a harmless yet annoying issue that we haven't had time to address. The problem lies in t ...

`Implementing AJAX data binding in a Flask Python Application`

I am currently laying the groundwork for my first Python Flask web application. While I have the server-side details sorted out, I have some queries regarding the client-side implementation. The application I am working on will be a single-page applicatio ...

Struggling with configuring AngularJS?

I've been working on a simple setup, but I can't figure out why AngularJS isn't displaying the content within the curly brackets. It's got me completely baffled. If you'd like to check it out, here's the link to the plunker: ...

What is causing the initial activation of the <button> within a form?

Within my <form>, I have included 2 submit buttons. The first button looks like this: <button class="regular" id="geocodesubmit" style="height:40px;">Set Location</button> The second button looks like this: <button type="submit" ...