Flex-boxes are set inside a fixed-positioned div in this chat web application

I am currently working on a chat web application that has a unique bottom bar layout. The bottom bar consists of a button on the left, a text entry field in the center, and another button on the right:

<div id="bottom-bar">
      <div class="button-left">
        <img src="https://placeholdit.co//i/40x40">
      </div>
      <div class="textentry">
        <input type="text" id="chatmsg" name="chatmsg">
      </div>
      <div class="button-right">
        <img src="https://placeholdit.co//i/40x40">
      </div>
    </div>

    #bottom-bar {
        position: fixed;
        bottom: 0px;
        height: 40px;
        width: 100%;
    }
    

My goal is to (1) align the left button to the far left of the bottom bar, (2) align the right button to the far right of the bottom bar, and (3) have the input field expand in the middle to fill all available space.

I attempted to achieve this by using the following CSS styling:

#bottom-bar {
       ...the css above and also included...
       display: flex;
       flex-direction: row;
       flex-wrap: nowrap;
       justify-content:space-between;
       align-items: center;
    }

    #chatmsg{
      width: auto;
    }
    

Unfortunately, my efforts did not yield the desired result. Any guidance or suggestions would be greatly appreciated.

Answer №1

Make sure the textentry expands to fill all available space:

#bottom-bar {
    position: fixed;
    bottom: 0px;
    height: 40px;
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content:space-between;
    align-items: center;
}
.button-left,
.button-right {
  width: 40px;
}
.textentry{
  flex-grow: 1;
}
#chatmsg {
  width: 100%;
}

Here is an example you can reference: https://jsfiddle.net/43Lqzznt/3/

Answer №2

To ensure that the input field within .textentry takes up the full width except for the space occupied by two images, use calc(100% - 80px); as the width for .textentry. Since this causes the input to overflow its container on the right side, add padding to .textentry to adjust the spacing between elements accordingly, as illustrated in the code snippet below.

html,
body {
  margin: 0;
}

#bottom-bar {
  position: fixed;
  bottom: 0px;
  height: 40px;
  width: 100%;
}

#bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.textentry {
  width: calc(100% - 80px);
  padding: 0 10px 0 2px;
}

input#chatmsg {
  width: 100%;
}
<div id="bottom-bar">
  <div class="button-left">
    <img src="https://placeholdit.co//i/40x40">
  </div>
  <div class="textentry"><input type="text" id="chatmsg" name="chatmsg"></div>
  <div class="button-right">
    <img src="https://placeholdit.co//i/40x40">
  </div>
</div>

Answer №3

To achieve the desired layout, utilize the display:flex property on the container and adjust the input div either with flex:1 or by setting its width to 100%. Be sure to inspect the output in the console for validation.

EXPAND WITH FLEXBOX

Observe how the input box dynamically stretches between the images as the container resizes, demonstrating a fluid design approach.

#bottom-bar {
   display: flex;
   flex-direction: row;
   flex-wrap: nowrap;
   justify-content:space-between;
   align-items: center;
}

#chatmsg{
  width: 100%;
}

.textentry {
  /* width: 100% */
  flex: 1;
}
<div id="bottom-bar">
  <div class="button-left">
    <img src="https://placeholdit.co//i/40x40">
  </div>
  <div class="textentry">
    <input type="text" id="chatmsg" name="chatmsg">
  </div>
  <div class="button-right">
    <img src="https://placeholdit.co//i/40x40">
  </div>
</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

In relation to User Interface: Analyzing target tracking and studying the flow of time

Is there a way to track mouse cursor movements, button clicks, and click times to an external database using only CSS, HTML5, and Javascript? I am curious about the possibility of conducting usability studies in this manner. ...

PHP - Unable to store the input content

I've encountered an issue with my website where I need to create a form for users to submit new information or news. Below is the code snippet that I have: <?php include "0begin.php"; $title=$_POST["title"]; isset($title) or $title=$_GET["tit ...

Activate divs with Bootstrap5 modal toggle functionality

What adjustments must be made to the Bootstrap 5 example below in order to achieve the following two objectives: The "afterAcceptingTerms" division should remain hidden until the user clicks on the Accept Terms modal button, ensuring that only the "before ...

incorporating a rollover menu into the images displayed on the webpage

I have a set of 3 images displayed inline, each enclosed in a span tag with the class imgAvatar. Positioned above them are 3 identical hidden images (delete buttons) stored within spans with the class imgAvatarSelector. The CSS for the delete buttons is a ...

Video is not visible in safari browser initially, but becomes visible only after scrolling for a little while

Having issues with a video not displaying correctly in Safari? The problem is that the video only becomes visible after scrolling the browser window. Want to see an example of this issue in action? Click here and select the red bag. Check out the code sni ...

React component state change in reverse

As I work on a simple login form component, I encountered an issue where clicking on the form should make it disappear and only display my JSON data. However, due to my limited experience with React state management, I seem to be achieving the opposite eff ...

A step-by-step guide on initializing and setting a cookie value with expiration

Below is the code I have added. Can someone please help me locate the bug? Here is the code snippet: $_SESSION['browser'] = session_id(); setcookie($expire, $_SESSION['browser'], time() + (60 * 1000), "/"); echo "Value is: " . $_COO ...

Develop an onclick function with an href attribute

I am interested in transforming links into AJAX versions whenever possible. To achieve this, I plan to implement a function called replaceLinks that will add an onClick handler to each link on the page and trigger ajaxPageWSM(href). This is what I currentl ...

Can PHP retrieve data when the form submit function is overridden with AJAX?

I have customized the .submit function of a form on this webpage. It is being loaded inside the #mainContent in an "index.php" and I want the Submit button to only replace this #mainContent. My goal is to retrieve data from this form and send it to a .php ...

How come the picture extends beyond the borders of its parent container when I expand the width?

Despite my efforts, I haven't been able to figure this out successfully. My goal is to align the text elements next to the image just like in the example picture below. Initially, I achieved this using absolute positioning. absolute positioning Howe ...

floating point for a list item compared to other elements

nav > ul > li { float: left; } #one { float: left; } <nav> <ul> <li> he has a cow </li> <li > he has a dog </li> <li> he has a mouse </li> </ul> & ...

After trying out the demonstration on the website, I am unable to get my submit button to work

Having trouble with my Formsubmit feature. Despite following the example on the website, my submit button doesn't send anything and the verification isn't reaching my email. Currently working with Angular. <form action="https://formsubmi ...

Execute a separate function when clicking on certain buttons without interfering with the buttons' original onclick function (which has already been assigned) - JavaScript

While I am still relatively new to JavaScript and learning, I have developed a webpage with multiple buttons that trigger different functions on click events. However, I would like to additionally call another function when any of these buttons are clicked ...

Having issues with the tailwindcss transformation not functioning properly, but the problem seems to resolve when directly incorporating it into the

Lately, I decided to start utilizing tailwindcss and I have noticed that certain properties do not seem to function at all. However, when I incorporate them into my CSS directly, they work perfectly fine. Allow me to provide an example. const Step = styled ...

Utilize Javascript to generate intricate table headers based on JSON data

I am currently facing a challenge in creating an HTML table header with colspan. I have a JSON object as follows: var metadata = [{ "colIndex": 0, "colType": "String", "colName": "PM" }, { "colIndex": 1, "colType": "String", "colName": "PR ...

The implementation of subnavbars within a navigation bar using HTML and CSS

I am looking to align the Login button with the settings icon on the same line above the links in my navbar. Is there a way to accomplish this? Check out this fiddle that demonstrates my issue: FIDDLE Here is the code I have written: <body> < ...

Center align `div 1` with CSS and right align `div 2`

Take a look at this code snippet: http://jsfiddle.net/zygnz/1/ <div class="container"> <div class="left"> LEFT </div> <div class="right"> RIGHT </div> </div> Is i ...

Pinterest Style Card Layout using React-Semantic-UI

Utilizing semantic-ui-react in React, I am working on displaying cards with varying heights based on the amount of text. I am aiming for a pinterest style layout where each card's height adjusts according to the content it contains. .... <Card.Co ...

Conceal the href element within a designated UL using JavaScript

Is there a way to only hide the href element in a specific UL element, rather than hiding all href elements with the same class name? Let's consider an example HTML code: <ul class="UL_tag"> <li>Text 1</li> <li>Text 2< ...

What is the best way to track down the source of a CSS rule?

A website built on .asp was passed down to me, and I was tasked with reorganizing forms in tables to the sidebar. Most pages were successfully updated, except for one stubborn page that seems to be ignoring my CSS changes and using values from an unknown s ...