Tips for positioning elements within an ng-repeat list using absolute positioning?

Here is the HTML code:

<div class = "container">
   <form ng-submit = "createSticky()">
      <input ng-model="formData.data" type="textarea" name="sticky_content" placeholder="add sticky text" required="true"/>
      <input ng-model="formData.end" type="text" name="time_end" placeholder="expiration time (sec)" required="true"/>
      <button type="submit" name="add_sticky" value="add a new stickie!">new sticky</button>
   </form>
   <div id = "stickies_list" class="row">
      <ul id = "stickies">
         <span class="sticky">
            <li ng-repeat="stickie in stickies" ng-click="match(stickie)">
               <button id="delete_checkbox" ng-click="deleteSticky(stickie.id)">X</button>
               <h3>{{stickie.data}}</h3>
               <div id="time_data">
               start: <h10><mydate>{{stickie.start | date:'MM/dd/yyyy @ h:mma'}}</mydate></h10><br>
               stop: <h10><mydate>{{stickie.end | date:'MM/dd/yyyy @ h:mma'}}</mydate></h10> 
               </div>
            </li>
         </span>
      </ul>
   </div>
</div>

and here is the CSS code:

.sticky #time_data {
  postion:absolute;
  top:0;
  left:0;
}

The current issue is that the time_data div appears after the rest of the info in the "sticky" span, causing it to be pushed down if the stickies.data is lengthy. The desired behavior is for the time_data div to overlap with the other information in the "sticky" class, being independent of it. This is achieved by using position:absolute. Following an example at http://jsbin.com/fecego/1/edit, where this works perfectly. How can I implement similar behavior in my code so that the time_data div also overlaps as intended?

Answer №1

It may be a bit unclear what you're inquiring about, but if you wish for your div to overlap the contents of the li, the li element must have a positioning of either relative or absolute. Additionally, the div should be nested within your li (unlike in your jsbin example). Here is an example:

<span class="sticky">
  <ul>
    <li> list 
      <div class="meta"><p> I am meant to overlap with the list, and that's exactly what I'm doing!</p></div>
    </li>
    <li> is 
      <div class="meta"><p> I am meant to overlap with the list, and that's exactly what I'm doing!</p></div>
    </li>
    <li> very 
      <div class="meta"><p> I am meant to overlap with the list, and that's exactly what I'm doing!</p></div>
    </li>
    <li> long 
      <div class="meta"><p> I am meant to overlap with the list, and that's exactly what I'm doing!</p></div>
    </li>
  </ul>
</span>

CSS

.sticky .meta { 
    position:absolute;
    top:0;
    left:0;
}

.sticky li {
  position: relative
}

Visit How to make div's percentage width relative to parent div and not viewport to learn more.

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

Clicking a button in VueJs will trigger the clearing of the displayed text and the subsequent execution of

Hello, I am new to the world of web development and I'm currently learning vue.js. I am working on an app where I input an ID and upon clicking the search button, a method is called. This method utilizes axios to make a request to the controller and ...

Troubleshoot: Issue with Multilevel Dropdown Menu Functionality

Check out the menu at this link: The issue lies with the dropdown functionality, which is a result of WordPress's auto-generated code. Css: .menu-tophorizontalmenu-container { margin: 18px auto 21px; overflow: hidden; width: 1005px; ...

How can I reset the mousemove event in jQuery?

I need to create a mechanism where I can move a div by clicking on it, and then click again to stop the div in that position. However, encountering an issue when trying to move the div again as the mousemove event does not get activated. How can this be ...

Tips on rearranging the location of a div element within a directive

I have created a custom directive that displays two divs, Div1 and Div2, with a splitter in the middle: Splitter Image Now, I am looking for a way to swap the positions of these two divs dynamically using an Angular directive. I thought about using ng-swi ...

Remove the </div> text and replace it with nothing

I'm attempting to substitute the end tag div with an empty string. Here is my code: $('#textDiv').html().replace(/'</div>'/g,'').replace(/<div>/g,'\n') This is the HTML: <div id='tex ...

Enhance jQuery for a dynamic navigation dropdown with multiple sub-menus

Looking for help with a jQuery script as I am a beginner in using jQuery. jQuery(document).ready(function ($) { $(".sub-menu").hide(); $(".current_page_item .sub-menu").slideDown(200);; $("li.menu-item").click(function () { if ($('.sub-menu&apos ...

What is the best way to anchor an image to the bottom right corner while also adjusting its position as

Hey there! I have a challenge where I want to anchor an image at the bottom right corner of a webpage. Initially, it works perfectly using this CSS: .logo img{ position: absolute; bottom: 0; right: 0; } However, when I resize the window, the ...

Switch tab colors when clicked

I'm encountering an issue with two tabs in bootstrap. My goal is for the tab color to change from black to yellow when pressed. I have attached 2 screenshots showing the code and design. Thank you. Second ...

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 ...

Gathering video links from various sections of a site

I am currently using Selenium for web scraping. My goal is to extract all the video URLs from 626 products spread across 25 pages. However, I am facing an issue where it only gives me the href link of the thumbnail image source instead of the actual vide ...

The initial render of Next.js is not properly loading the CSS files

Encountering an issue with the initial load of the mobile app version; it seems that the CSS of my component covering the page is not loading correctly on the first screen load. However, when resizing to desktop and then switching back to mobile view, the ...

AngularJS - A guide on adding a new property to every object within an array

I'm looking to update each item in an array by pushing a scope variable into it. This is my current code: $scope.ProcessExcel = function (data) { //Read the Excel File data. var workbook = XLSX.read(data, { type: 'bin ...

Having issues making div elements with javascript

I am having trouble generating new divs when a specific div is clicked. Despite my efforts, nothing seems to be happening and the console isn't showing any errors. I've searched online for solutions but haven't found anything that addresses ...

Applying CSS to replicate the vintage iPhone app icon design

I've been searching online for days, but I can't seem to find any helpful resources on how to use CSS3 to style the old iPhone app icon. My goal is to apply a CSS3 style to this curved line, with a fallback option in case older browsers don&apos ...

Stop the context menu from popping up when the element is right-clicked

Is there a way to create a custom right-click interaction for an element on my website, <div class="myElement"></div>? I want to avoid the default context menu from popping up when the user right-clicks on this element in order to enhance the u ...

Enhancing the design of a button with whitespace using CSS

Recently, I had a well-designed landing page created using LeadPages. However, due to financial constraints, I am unable to continue paying for their services at the moment. The current landing page has proven to be effective in converting leads. https:// ...

Learn the step-by-step process of cropping and zooming an image using the react-image-crop

I am looking to implement zooming and cropping functionality for an image using react-image-crop instead of react-easy-crop. Currently, the cropping does not take into account the zoom level set by ReactCrop's scale property. I want to be able to zo ...

The images are positioned within the middle of the page, directly beneath the sidebar, rather than at the top. (Vue.Js)

I'm currently working on a Vue.JS photo website and I've hit a roadblock as described in the title. Despite trying various solutions, after spending two hours back and forth with ChatGPT, I've decided to seek help here. Below is the code sn ...

Clicking on the Submit button of the post form simply refreshes the page

Every time I try to submit values from an HTML form, the page reloads without any changes. I've double-checked the routes and controller, but everything seems correct. Solution <div class="panel-body"> @if (session('status')) ...

What could be causing a full-width image render in Firefox when a nested flex item is centered?

My design involves nested containers with the display: flex; property. While Chrome/Edge display the item div correctly, in Firefox 110.0.1 the item div expands to fill the entire horizontal space within the wrapper (100% width). Which CSS properties can ...