Maintain the vertical positioning of absolute elements within a relative container

Is it possible for a relatively positioned element's height to adjust based on the height of its child element?


Check out the Demonstration


HTML:

Items:
<div id="love">
    <textarea id="magic"></textarea>       
</div>
Dung:​​

CSS:

#love{
    position:relative;
    background:#eee;
    width:60px;
}
#magic{
    position:absolute;
    width:20px;
}

Output:

Answer №1

When using absolute positioning, it is essential to provide coordinates for the element.

#wizard{
    position:absolute;
    width:30px;   
}

You need to specify both x and y positions as 0 in order for the outer tag to adjust according to the inner tag. // Unless you set a specific width or height for the outer tag

#wizard{
    position:absolute; 
    left:0; // x pos
    top:0; // y pos
    width:30px;
}

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

How to interact with a button inside a span element without an ID using Selenium

Can anyone help me figure out how to click a button in the browser using Selenium and Python? The button I am trying to click is located within this HTML code: <div id="generate"> <i class="fa fa-bolt"></i> <span>D ...

The delete function is not functioning

I need help with implementing a custom Angular directive that includes a delete button to remove itself. When I click the button removeMe, it is not deleting an item from the array. Any suggestions on what might be causing this issue? HTML: <button t ...

Share and sign with the href link to the PHP webpage for assistance

Here is a problem I am facing: browse_cat.php?cat_gr='Mopeds &amp; Traktors'"> In the browse_cat.php file, I have used this code to retrieve the above "category": $cat=$_GET['cat_gr']; echo $cat; The output of thi ...

The communication between Ajax and PHP is experiencing some technical difficulties

Hi there! I'm currently facing an issue with my Ajax call to a PHP function. My goal is to display the server time on the input field using a PHP script. Despite following an online tutorial step by step, I keep getting the actual text from the PHP fi ...

The mysterious case of the vanishing jQuery traversal box

I'm currently navigating using previous and next buttons, but it seems to be malfunctioning if I click too quickly. My goal is for the navigation to remain smooth without breaking. var $currDiv = $("#start"); $("div").hide(); $currDiv.c ...

Load CSS styles once the HTML content has been generated by the PHP script

One way to dynamically add a section of HTML during page load is by making use of PHP in the index.php file: In your index.php file, you can include a section like this: <html> <head> <link href="css/style.css" rel="stylesheet"> ...

CSS property that determines where a string can be broken into lines based on specific characters

Is it possible to specify characters on which a long string, such as a URL, should break in browsers? For instance: https://www.this-is-my-url.org/upload_dir/2015/01/foo_bar_faq.pdf If the box only allows 40 characters per line, it might break like this ...

Challenge in altering text color upon hovering over it

I'm attempting to change the text color to white upon hovering, but I haven't had any success so far. Here's the code snippet that I've used. How can I ensure that the text color changes to white and also its size increases when hover ...

I have expanded the CSSStyleDeclaration prototype, how do I access the 'parent' property?

I have developed some custom methods for CSSStyleDeclaration and implement them like this: A_OBJECT.style.method() ; The code structure is quite simple: CSSStyleDeclaration.prototype.method = function () { x = this.left; ..... etc } Here's my que ...

Display loader until the document body has finished loading

Many developers have shared solutions for displaying a loader while an element is being loaded. However, my challenge is unique. I want to display a loader before the document body is fully loaded. The issue arises from an AJAX call in my code: var url = ...

Exploring JSON in PHP with AJAX loops

Having trouble with my JSON data retrieval process, looping through it, and using AJAX for the results. The data seems to be alternating instead of being posted properly. Any suggestions? php: <?php $url = "../json/work.json"; $contents = file_get_con ...

How to Implement Snap-Enabled Dragging in a Container Using jQuery UI

Issue Description (Fiddle): I am using the jQuery UI's .draggable() function to make the red element snap inside the blue container. However, it is snapping to one edge only instead of completely fitting inside (both edges). It requires further dragg ...

How can the CSS inside the editor be customized in ng2-ckeditor?

I am looking to customize the functionality of the ENTER key in ng2-ckeditor. I have read about a config option that can help with this on this site. It seems that custom CSS is recommended for making these changes: To adjust paragraph spacing, it is sug ...

The ng-tagsInput feature seems to be malfunctioning

JavaScript var app = angular.module('plunker', ['ngTagsInput']); //'ngTagsInput' app.controller('MainCtrl', function($scope, $http) { $scope.tags = []; $scope.loadTags = function(query) { return $http.get( ...

Adjusting Position for Parallax Effect using Jquery

I am currently experimenting with a basic Scrolldeck Jquery Parallax effect to scroll items at varying speeds. However, I am encountering some difficulties in making items move from top to bottom. In the example provided below, you will see a shoe moving f ...

Incorporating a scroll bar into a horizontal display

In troubleshooting this web interface, I encountered an issue related to the horizontal view. The problem is evident in the image below - when in horizontal view, more vertical space is required, prompting the need for a scrollbar to be added between the ...

Guide on filling MySQL database with audio HTML pages

Looking for some assistance with uploading 4,000 small audio files (approximately 30 seconds each) - they're not ringtones! Additionally, I have 4,000 HTML files to manage too. I've heard that MySQL is the ideal solution for handling large amount ...

Incorporate a lesson featuring jQuery into your curriculum

Just starting out with jQuery and I have a form setup like this: <select name= "menus"> <option value="">--Select--</option> <option value="a">a</option> <option value="b">b</option> <option val ...

Unable to append HTML table row to designated table

I am trying to populate an HTML table with the JSON string data I receive. The object data seems correct, but for some reason, it is not getting appended to the table. Can you help me identify what's wrong with my jQuery append statement? functio ...

JavaScript has the ability to manipulate the width of an element by using methods to both retrieve

I have a unique situation where I need to dynamically adjust the width of a ul list element based on the text content inside it. Specifically, I want the width of the ul list to be equal to the width of the first list item, which can change frequently. My ...