Ensure the CSS element remains fixed to the right side even while scrolling

I need the checkboxes to stick to the right side of the label.

This is how I want it to look:

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

Currently, when I use

 right: 0; position: absolute !important;

The checkboxes always stay on the right, even when scrolling horizontally, which is the desired behavior.

My problem is that when I scroll down, the checkboxes also move down with the scroll. Instead, I want them to stay aligned with the label and not scroll with the page, as shown in the image above.

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

Here is the CSS code:

.custom-tree-node {
  // flex: 1;
  // display: flex;
  // width: 90%;

  & > .custom-tree-node-buttons {
    right: 0;
    position: absolute !important;
  }

  & > .custom-tree-node-buttons {
    & > .el-button-group {
      & > .el-button {
        padding: 2px 3px !important;
      }
    }
  }

  & > .custom-tree-node-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: pre;
    position: relative;
  }

HTML:

                 <Tree v-if="allStructuresTree.length > 0"
      style="padding:0px;width: 100%;display: flex;"
      class="custom-tree-node"
        filterMode="strict"
        :value="levelDetils"
        :loading="loadingPrime"
        ref="structureTree"
        selectionMode="multiple"
        v-model:selectionKeys="selectedKeys"
        @nodeSelect="onCurrentNodeChanged"
        :expandedKeys="expandedKeys"
         @nodeExpand="onNodeExpand" 
         @nodeUnselect="onNodeUnselect"
      >
        <template #default="slotProps" style="padding:0px">
            <div draggable="true" @dragstart="onDragging" id="123"
             
              v-bind:class="
                getStructureLabelClass(
                  slotProps.node.item.isHighlighted,
                  slotProps.node.item.isUnderlined
                )
              "
              :title="slotProps.node.item.name"
            >
              <i
                v-if="
                  slotProps.node.item.linkedTasks != null &&
                  slotProps.node.item.linkedTasks.length != 0
                "
                class="el-icon-fa-link"
                v-on:click="showLinkedTask(slotProps.node.item.linkedTasks[0])"
              ></i>
              <span
                class="xeokit-context-menu-item noselect"
                @mousedown.right="mousedown($event, slotProps.node)"
                v-on:dblclick="doubleClick($event, slotProps.node)"
                @contextmenu.prevent
                >{{ slotProps.node.item.name }}</span
              >
            </div>
            <div class="custom-tree-node-buttons" v-if="isSceneLoaded">
              <el-button-group
                class="treeBtns"
                v-if="slotProps.node.item.visible"
              >
                <el-button style="padding:0px 5px; margin-right: 5px;"
                  @click="
                    focusOnItem(
                      $event,
                      slotProps.node.item.idOnScene,
                      slotProps.node
                    )
                  "
                >
                  <i class="el-icon-fa-dot-circle-o"></i>
                </el-button>
                <el-button style="padding:0px 5px;">
                  <input
                    @click="toggleShowItem($event, slotProps.node)"
                    type="checkbox"
                    v-show="slotProps.node.item.entity"
                    v-bind:id="slotProps.node.objectId"
                    v-model="slotProps.node.item.entity.checked"
                  />
                </el-button>
              </el-button-group>
            </div>
        </template>
      </Tree>

}

Answer №1

Using the CSS property "position: sticky" successfully fixed the problem I was experiencing.

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

Tips for ensuring that the click event function properly for numerous elements sharing the same class

I'm currently working on adding a flip effect to multiple tiles whenever a user clicks on them as part of building a dashboard-style webpage. I am having trouble making the click event work for all tiles with the same class name. Even though all the ...

Retrieve the value of the second child element in a table cell when clicking on it with Javascript

I have created a table with one row that includes the title of the month and a cell containing an inner table with multiple rows and cells. I want to display the content of the second cell in the second table as a modal box or alert dialog when it is click ...

The image will remain hidden until it is fully loaded and ready to be displayed

I am currently working on a script that involves displaying a loading icon until an image is fully loaded, at which point the loading icon should disappear and the image should be shown. Unfortunately, my current code is not working as intended. Here is a ...

Enhanced browsing experience with personalized search suggestions

As a developer, I am aware that you have the ability to customize the browser's suggestions for various fields. For example, specifying that a field is for email and only suggesting values for email fields in the future. Is this functionality really ...

What is causing the container to overlap with my sidebar-like <nav>?

Why is the fluid-container overlapping in this way, while others are not? Does this look correct to you, or am I overlooking something? It seems incorrect to me. <nav class="nav flex-column float-left"> {links} </nav> <div class="conta ...

Choose a division of an element within an embedded frame

Two different pages on the same website, Home.html and Page2.html. Home.html contains the following code: <html> <iframe id="one" src="page2.html" style="display:none"></iframe> <div id="container"> <h1& ...

Creating visually appealing table designs with CSS

Greetings! I am currently utilizing JQuery fullCalendar within AngularJS and find myself in need of assistance regarding table styling. The fullcalendar has its own CSS file from the plugin, which can be viewed here. The issue arises due to the presence o ...

Choosing from all videos on YouTube

I am currently attempting to extract the watch URLs of all uploaded videos from the video manager on YouTube. How can I go about selecting all videos displayed on the page? From my observation, each video contains a vm-video-title-content yt-uix-sessionlin ...

Enhance <th> elements using CSS classes

I'm encountering some issues with HTML tables. The layout of my table is as follows: <table class="shop_table cart" cellspacing="0"> <thead> <tr> <th class="product-remove">&nbsp;</th> <th clas ...

Tips for customizing the appearance of a specific mat-button component in an Angular project

In my Angular application, I have set up a scenario where users are presented with multiple choices through buttons. When a user clicks on a button, a specific component is displayed based on their choice. I am currently working on enhancing the styling of ...

Execute a function when the button is clicked

Currently in the process of learning HTML and Javascript. I was able to search online for information on how to navigate to a URL and extract a value from returned JSONP. However, the function is executing when I load the HTML page, and I would prefer it t ...

What is the best way to transfer information using PHP?

I'm struggling to pass the player id to the delete and update page, but it's not working. Below is my table body: <tr> <td><img src="<?php echo $readRow['Photo']; ?>" width='64px'></t ...

Ensure the footer DIV remains at the bottom even after loading AJAX content

I've encountered an issue with the footer DIV not moving to the bottom of the page after new content is added to the above DIV using AJAX. Initially, when the page loads, the footer is at the bottom, but after the AJAX call inserts a lot of content, t ...

My code seems to be experiencing issues with the carousel functionality despite incorporating Bootstrap

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <% campground.images.forEach((img,i)=> { %> ...

What HTML element can be used outside of a Bootstrap dropdown item to show a default image when the dropdown is open?

I'm working on my menu where I have two columns - one for submenu text and the other for respective images. Everything is working fine so far. However, I want to set a default image that will display when the user does not hover over any dropdown item ...

JavaScript is failing to match the float and string values

Trying out this code snippet: if(total === balance) { alert("test passed"); } else { alert("test failed"); } In this scenario, total = 10; and balance = 10.00;, yet the output is "test failed". ...

Using Chrome in Application Mode with Shortcuts Disabled

When trying to utilize Chrome in application mode as a host for an HTML5 application, it becomes evident that there are significant limitations. For instance, pressing CTRL+T launches a new Chrome browser window, allowing the user to input text into the a ...

An alternative method for adjusting the width of text input fields in CSS without using

Is there a CSS alternative to the calc function that can be used for older browsers (such as the default Android browser) in order to dynamically set the width of input text fields while leaving space on the right for a submit button? This is my current C ...

Images inside columns are not being properly displayed in a PHP for loop when using Bootstrap

I have created a bootstrap page in which I am attempting to showcase images inside bootstrap columns. Below is the code snippet that I have used: <!DOCTYPE html> <html lang="en"> <head> <title></title> <meta charset ...

Code in PHP for implementing the Caesar cipher algorithm

(check out this example on jsfiddle: Caesar cipher) I have been working on a Caesar cipher, which involves shifting alphabetic characters; for example, with a shift parameter of 3: Original: a => d, b => e, c => f, ... Here is what my code look ...