Is there a way to specify the width of an element as "fill_parent"?

Initially, I must mention that this question may appear similar to mine, but it is actually different.

My HTML code is as follows:

.parent{
  border: 1px solid gray;
  width: 70%;
}

.title{
  border: 1px solid green;
}

.input {
  /* width: fill_parent; */
}
<div class="parent">
  <span class="title">title: </span>
  <input class="input" name="title" type="text" placeholder="Choose a precise title">
</div>

My objective is to assign a value akin to fill_parent to the input's width. The width of the parent container (.parent) is defined by a percentage, adjusting according to screen size changes. Therefore, using a fixed px value for the .input width is not feasible.

Please note: Simply applying .input{width: 100%;} is not suitable since I want both the title and input elements to stay on the same line.

Any recommendations?

Answer №1

To create a flexible layout, you can apply display:flex; to the parent container and then use flex:1; on the input element.

.parent{
  border: 1px solid gray;
  width: 70%;
  display:flex;
}

.title{
  border: 1px solid green;
}

.input {
  flex:1;
}
<div class="parent">
  <span class="title">title: </span>
  <input class="input" name="title" type="text" placeholder="Enter a precise title">
</div>

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

Utilizing ES6 array methods to convert multidimensional arrays into chart-ready data

Seeking help with converting an array to a specific data format for chart display. The chrart.js library requires data in the following format: dataset = [ { label: 'one', data: []}, {label: 'two', data: []} ]; I ...

A-Frame: Capturing sweeping panoramic images with code

I am exploring panoramic screen shot capabilities and came across some documentation on how to take screenshots in A-Frame using hot keys. However, I am wondering if there is a method to generate a panoramic screenshot automatically without requiring user ...

Supervising the organization of HTML sections for an offline web application

Currently, I am developing an offline HTML5 application that involves a significant amount of DOM manipulation through the creation of HTML strings within JavaScript functions. For example: var html=''; html+='<div class="main">&apos ...

Is it possible to use CSS and HTML to rotate a cube and expand its sides?

I am attempting to rotate the cube and expand its faces. I have experimented with the following code: .wrapper{ position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); } .cube-wrap { width: 40px; height: 40px; ...

Understanding the intricacies of JavaScript function calls often results in unexpected null returns

I currently have a code that is able to run and collect data using an AJAX library. My goal is to allow users to add their own functions to the library and execute them, similar to $.get. It may be a bit difficult to fully explain what I am trying to achie ...

Retrieving data within individual HTML elements

Is there a way to combine and extract data from different HTML tags for validation purposes? I am interested in fetching values from two separate input fields, merging them into one string, and passing this combined string as an argument to a function with ...

Managing multiple sets of radio buttons using the useState hook

Within my renderUpgrades-function, I handle the options of an item by including them in radio-button-groups. Each item has multiple options and each option has its own radio-button-group. Typically, a radio-button-group can be managed using useState, wit ...

Tips for universalizing the code of a file upload web form to accommodate various forms with distinct id attributes

Presently, I have a web form dedicated to uploading a single file using jquery. This elegant solution provides users with a progress bar and a message upon the successful completion of the upload process: <form id="uploadFileForm" method="post" action= ...

Using Python to manipulate HTML for printing purposes

As I develop an application in Python, one of the features requires printing PDF files using a Xerox printer. I am currently considering two options: First option: figuring out a way to communicate with the printer driver and send commands to the printer ...

Error: The request was not successful in creating and populating a list of type Microsoft.AspNetCore.Http.IFormFileCollection

I am encountering a Bad request error when trying to upload a file, convert it into JSON, and pass it to my .NET Core WebAPI controller. Below is an error screenshot that I received along with logging the model. https://i.sstatic.net/grSf4.png Here is m ...

Why are my video files exhibiting inconsistent behavior?

I've encountered an issue with the code on my website where I'm trying to display a 40-second video. The video converter I used seems to have added extra video types, which may be causing the problem. Here's what the HTML code looks like: ...

Minify your Angular code and include background images through URLs specifically for production mode

Trying to create a gradient image background in CSS using Angular 6 with the CLI template. Everything looks great in dev mode, but when I switch to the production version (ng build "--prod"), the CSS code becomes invalid. Here is the SCSS file: .home-con ...

What steps should I take to create a collapsible Bootstrap navbar?

I'm attempting to recreate the scrolling functionality seen here: It seems like they might be using a customized Bootstrap Navbar, so I've taken one from here: and tailored it to my needs. How can I achieve the effect where the navigation bar ...

How can I validate a password input in a form on click and reveal a hidden div on the same page without refreshing?

I've been attempting to create a password-only form that reveals a hidden div on the same page when the correct password is entered. I want to avoid reloading the page, but I'm unsure of how to achieve this. function checkPassword() { var co ...

Attempting to retrieve assets from an incorrect directory in a rush

Within my express project, I have encountered an issue when rendering the product route with a specific id. It seems that the assets are attempting to load from /products in the public folder (even though this directory does not exist). However, when I ren ...

What are the steps to remove text within a list item using jQuery or regular JavaScript in a WordPress theme?

I need to remove the word "previous" from an li element in a wordpress theme. the text to delete <ul class="flex-direction-nav"> <li class="flex-nav-prev"> <a class="flex-prev" href="#">Previous ...

The alignment of the Unicode character is off and is not centered within the button

Upon implementing a unicode character as a button, I've observed that the alignment of the character is not centered properly (both horizontally and vertically) within the button. It's puzzling why this misalignment occurs even after setting padd ...

Adjusting the size of buttons on a webpage using Bootstrap

While working on my website using the pre-compiled Bootstrap v4.1.3 code provided on the Bootstrap page, I encountered an issue with the navigation and buttons functionality. After my meta tags, I have included the CSS links as shown below: <!DOCTYPE ...

Creating a Navigation Bar with a Dropdown Menu in HTML

Apologies if this question has been asked before, but I've searched everywhere and can't find an answer. All my searches just bring up dropdown menus with <nav></nav> Consider this table (serving as a navigation bar): <table cl ...

HTML: arranged <pre> with fixed positioning

I currently have a centered column of text with a fixed width. However, I am looking to break that fixed width for certain tags like <pre> so that they can fill the full screen width while maintaining flow with the rest of the text. My CSS snippet s ...