Tips for shifting nested div containers to the left as the content expands

I have a div containing a dropdown menu, label, and button as shown below:

<div class="container ">
  <div id="User">
    <div id="BtnUser">
      <div id="dropMe">
        <div class="dropdown">
          <a onclick="UserdropDownDetails()">
            <div class="triangle"></div>
          </a>
          <div id="myDropdown" class="dropdown-content ">
            <ul>
              <span class="dropDownMenu">hello <span class="ColonGreen">:</span>&nbsp;hi</span>
              <span class="dropDownMenu Availability">Availablility <span class="ColonGreen">:</span></span>
              <span class="dropDownMenu">helloooo <span class="ColonGreen">:</span></span>

            </ul>

          </div>
        </div>
      </div>
      <div id=UserDetails><label>tessssttt&nbsp;tessssssssssst</label></div>
      <div id="logoutDiv"><button id="btnLogout" name="btnLogout">Log out</button></div>
    </div>
  </div>
</div>

https://jsfiddle.net/g9tdcrxh/2/

Currently, when the text tessssst grows in length, it moves to the left and blocks the dropdown triangle. How can I expand the BtnUser div so that the triangle shifts accordingly when the text grows?

This is the current layout:

https://i.sstatic.net/Wtlxz.png

I want the triangle's position to remain fixed, only shifting when the text extends. The logout button should stay in place.

The desired expansion should look like this:

https://i.sstatic.net/TFT89.png

How can I achieve this functionality? Any help or guidance using jQuery would be highly appreciated.

Answer №1

I have implemented several modifications. To inspect the elements on your browser, simply right-click and choose "inspect element". By hovering over the list that appears, you can view their sizes, margins, and paddings.

<div class="container">
    <button id="btnLogout" name="btnLogout">Log out</button>
    <div class="user">
        <div class="userDetails">teshrthrtrthrthtrhtrhabcdefghijklteshrthrtrthrthtrhtrhabcdefghijklteshrthrtrthrthtrhtrhabcdefghijklteshrthrtrthrthtrhtrhabcdefghijkl</div>
        <div class="dropMe">
            <div class="dropdown">
                <a onclick="UserdropDownDetails()">
                    <div class="triangle"></div>
                </a>
                <div class="myDropdown" class="dropdown-content ">
                    <ul>
                        <span class="dropDownMenu">hello <span class="ColonGreen">:</span>&nbsp;hi</span>
                        <span class="dropDownMenu Availability">Availablility <span class="ColonGreen">:</span></span>
                        <span class="dropDownMenu">helloooo <span class="ColonGreen">:</span></span>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

body {
    margin: 5px;
}

.container {
    overflow: hidden;
}

.user {
    overflow: hidden;

    margin-right: 95px;

    min-width: 500px;
    max-width: calc(100% - 100px);
    float: right;

    height: 30px;
    background-color: rgba(0,0,0,.75);
    text-align: center;
    color: #fff !important;
    cursor: pointer;
    right: 0;
    border-bottom-left-radius: .5em;
    display: block;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
    padding-top: 0;
    border-radius: 1px;
    background-color: #1c1c1c;
    box-shadow: inset 0 10px 20px #333;
}

#btnLogout {
    width: 90px;
    background: linear-gradient(to bottom, #74be43 0%,#3a953e 64%,#3a953e 64%,#0f773b 100%);
    border: 1px solid #BFE1A7;
    box-shadow: none;
    border-radius: 4px;
    color: #FFF;
    border-left: 1px solid #ECF5EC;
    border-right: 1px solid #ECF5EC;
    line-height: 20px;

    position: absolute;
    top: 9px;
    right: 5px;
}

.dropMe {
    width: 10px;
    /*margin-top: -26px;*/
    /*margin-left: 110px;*/
    float:right;
    margin-left:10px;
}

.userDetails {
    /*margin-top: -20px;*/
    /*margin-left: -220px;*/
    text-transform: uppercase;
    font-size: 10px;
    color: #cecece;

    text-align: left;
    height: 22px;
    line-height: 22px;
    float:right;
    min-width: 376px; /* 600px - 110px (left margin) - 20px (arrow) - 90px (button) - 4px (button margin) */
    max-width: calc(100% - 20px); /* 20px (arrow) */
    overflow: hidden;
}

https://jsfiddle.net/g9tdcrxh/9/

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

The function responsiveTable does not exist

I recently added the following code to my aspx page: <script src="../Scripts/jquery.responsivetable.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#grdStudent').responsiveTable( ...

Is there a way for me to retrieve the data inputted into this form using JavaScript?

Having some trouble with this code. Can someone help me figure out what's going wrong? function displayData() { var userInput; userInput = document.getElementById(userInputs.firstInput); alert ("You entered: " + userInput); } <form ...

How to retrieve the user ID of the selected user using JqueryUI autocomplete?

Hey there, I'm currently delving into the world of jQuery UI autocomplete. My setup involves using autocomplete with ajax, where PHP helps me fetch a list of users. autocompleteajax.js $(function() { $( "#ranksearch" ).autocomplete({ sou ...

Location of chat icon in Dialogflow messenger

After successfully embedding the Dialogflow messenger in my website, I noticed that in mobile view, the chat icon is blocking the bottom navigation bar. You can refer to the screenshot here. Is there a way to reposition the chat icon higher on the page? I ...

PHP - Unexpected behavior while using a switch statement for auto-incrementing variable inside a while loop

Can anyone assist me with this problem? I am currently testing a switch statement inside a while loop that compares values. The loop should end once a specific value reaches the limit $numRow, stopping the execution of the remaining code. Here is my code ...

Tips for enabling background scrolling when Popover is displayed: (React, React Native, Native-Base)

I'm utilizing the Popover component from NativeBase to design my popover: const SettingsButton: React.FC<Props> = () => { return ( <Popover trigger={(triggerProps) => { return ( ...

Assistance needed for jQuery functions running too early

Within my click function, I am setting certain flags and then calling two functions. However, I want these two functions to execute sequentially in order after the flags have been set. jQuery("#element").click(function(e){ var op = jQuery("#box" ...

Adding a certain number of days to a date within an existing ng-module in AngularJS

Hey everyone, I'm new to using AngularJS and I am currently attempting to incorporate one ng-module value into another ng-module date input within AngularJS. For example: if the date is 17-08-2016 and we add 20 days, the expected result should be 03-0 ...

Change the color of the first element when hovering over any of its siblings using only CSS

I am looking for a solution using only CSS We have 3 circles here. When I hover over circles with the class name "Mycircle", the circle with the class name "BigCircle" should change to red color HTML <div class="BigCircle"></div> <div cl ...

Display a particular div upon clicking a specific link, while concealing the other divs

As a beginner in the world of jQuery and coding, I'm encountering some difficulties that I need help with. My goal is to have the 'Vlogging' link activated and show 'Details 1' when the page loads. Then, upon clicking on either &a ...

Perform CSS transitions simultaneously

Hey there! I'm currently working on a button that includes a Font Awesome icon at the end of it. To display the icon, I'm using the :after pseudo-element on the button, which is working fine so far. The issue I'm facing is with the CSS tran ...

An error occurs when attempting to echo empty values from an array due to the "undefined index" issue being

Answering this question seems quite straightforward. Let me outline what needs to be done. I possess an array $polarity_array The array holds values in the form of HTML tags that present images. However, there are some empty values in the array because ...

After a brief pause of x seconds, continue forward without the AJAX response

I have a jQuery Ajax snippet that calls a CHAT functionality. I would like to introduce a 2-second delay before displaying the output when response.available is not equal to 1 in the Ajax response. How can I achieve this using a setTimeout function? See ...

Using AngularJS ng-repeat with jQuery find yields a single element result

I'm in the process of developing my very first AngularJS application, and I've run into an issue with the jQuery find function. Essentially, what I'm attempting to do is utilize a custom HTML component that contains a list of buttons generat ...

The client continues to request the file through the REST API

I have noticed a behavior with an audio file stored on the server that clients can request via a REST API. It seems that every time the audio is played again, a new request is sent to the server for the file. Is there a way to prevent this or cache the dat ...

Contrast between the structure of asp.net button and hyperlinks

I want to transfer the styles of a hyperlink in regular html to an Asp.net button. However, I encountered a strange background issue that is disrupting the appearance of the buttons. Hyperlink: Asp.net Button How can I remove the outline that appears o ...

Step-by-step guide on dynamically fetching additional images from a directory using php, jquery, and ajax

I have a scenario where I have multiple folders, each containing up to 20 images. On my HTML page, I want to display the first 5 images and provide a "click to view more" option to show the remaining 15 images when clicked. Currently, the issue I am facin ...

What type of programming language is utilized in creating this online interactive calculator?

I have a strong interest in creating an interactive calculator like the one found on keto-calculator, but I am unsure of where to begin my research on how to develop it. Can you provide insights on the coding language typically used for such calcula ...

Display a div using Jquery depending on the visibility and checked value of another div

Trying to toggle the visibility of a div based on another div's input has proven to be quite challenging in this scenario. Here is the HTML setup: <div id="main-question"> <div class="form-group"> <div class="form-radios"> ...

Tips for deleting extraneous cells in a table without altering the placement of the other cells and refraining from employing CSS

I'm struggling with understanding how to merge cells in a table. Can someone explain the rules for merging table cells to me? I want to remove certain cells from the table without using CSS, I just want to make it look clean. <table border="1" ...