CSS: positioning elements relative to the bottom right corner

The structure of the floating element is as follows:

<a>The_button</a>
<div style="position:absolute">
    <div style="position:relative" class="inner-box">
       Content
       Content
       Content
       Content
       Content
    </div>
</div>

The inner-box controls contain content of variable length, resulting in variable height. I am seeking to define the CSS class .inner-box (without using JavaScript) so that the lower right corner of the inner-box will be positioned relative to the upper-left corner of the link. Is this achievable?

The target browsers include IE8+, Firefox, Chrome, Opera, and Safari.

Links consistently have the same height and width.

Answer №1

I've been exploring a few solutions and here's what I've found so far:

http://jsfiddle.net/fmVz6/ - In this one, you need to define the height and width on the "outer-box", with the inner-box being absolutely positioned as well.

I'm also working on another option currently...

http://jsfiddle.net/fmVz6/1/ - This one doesn't require specific height or width, just something inside the parent div (like a space) to show the background.

If you want it to show up at the top-left of the link, try http://jsfiddle.net/H5G8r/1/ (might need some HTML rearrangement).

This option doesn't need a defined width and keeps the text on a single line: http://jsfiddle.net/H5G8r/2/

Take your pick! :-)

Answer №2

Although your idea is on the right track, the correct approach is actually the opposite. The parent element should have position: relative, while the inner element should have position: absolute. This is because the inner element is positioned absolutely in relation to its parent (specifically, its offsetParent). By specifying position: relative on the parent, it becomes the offsetParent for all of its child elements.

For the top-left corner of the parent element to align with the bottom-right corner of the absolutely positioned child, you should include right: 100%; bottom: 100% in the child's CSS. This will place the child <100% of the parent's width> from the right edge of the parent, and <100% of the parent's height> from the bottom.

HTML

<div class=outer-box>
    The Button
    <div class=inner-box>
    </div>
</div>​

CSS

.outer-box {
    position: relative;
}

.inner-box {
    position: absolute;
    /* align bottom-right with offsetParent's top-left */
    bottom: 100%;
    right: 100%;
    width: 100px; /* fixed width, else contents will shrink */
}

You can also view a jsFiddle demonstration here: http://jsfiddle.net/ryanartecona/g344W/2/

Once you have achieved alignment, you may consider adding another box inside the .inner-box and giving it a position: relative to make any necessary position adjustments, such as sliding it a fixed distance over the button, etc.

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 can I maintain the state of an HTML checkbox in Django even after reloading the page?

In the following sample code, I am looking to maintain the checkbox as checked even after a page reload when the submit button has been pressed. <td><input type="checkbox" value="{{ item }}" name="selectedcheckbox"/ ...

Is it possible to achieve the lower link set in a pure CSS horizontal menu where the horizontal link set is positioned below horizontal text tabs?

I am attempting to design a pure CSS on-hover horizontal menu. I have made some progress on my design, as shown in http://jsfiddle.net/dq8z192L/11/ The goal is to have a menu that expands horizontally when hovered over. Each tab reveals a set of links be ...

Employ the CSS pseudo-element :before within a UL element to generate a vertical line

I'm currently working on a vertical menu with the capability of having submenus. My aim is to include a vertical line using CSS pseudo-element ::before along with border. The challenge I'm encountering is that the CSS is applying to the entire m ...

Distinguishing between client side rendering and server side rendering is the backbone of web development

My goal is to give users the option to request webpages from my website either directly from the server or by clicking on links, which will be managed by Backbone's router. When a user requests a webpage directly from the server, they will receive a ...

jQuery prioritizes enforcing style over using a CSS file

I am facing an issue with a nested div functioning similar to a drop-down menu. The problem arises when I click on the #two div as I want it to disappear. To handle this, I utilized jQuery and tried using both .hide() and .slideUp(). However, upon implem ...

Concealing a column in a printed output on Internet Explorer 9

Our application features a webgrid with a hidden reference column that is concealed using CSS. While this method works seamlessly on most browsers, we encounter an issue when it comes to printing. In our print.css file, where the column is hidden similar t ...

How to apply CSS classes to dynamically injected HTML in Angular 7

One of the challenges I'm currently facing is how to assign a CSS class based on a calculation in my component. Here's a snippet from my component class: @Component({ selector: 'app-render-json', template: `<div [innerHtml ...

Tips for extracting and utilizing a JSON object provided by the parent page:

Sorry in advance if this question has already been addressed. I've spent hours searching on Google, but haven't found a satisfactory answer yet. Below is the code snippet I'm working with: <ion-content> <div class="list"> ...

Concerns arise regarding the implementation of an image slider using HTML and CSS

Hey guys, I've created an image slider, but I'm facing an issue where the first click doesn't trigger a smooth animation. Instead, it jumps to the target without any transition. I want a seamless change of images, but right now it's jus ...

Navigation bar experiencing resizing problem, refreshing resolves the issue

I've been struggling with this problem all day. I'm attempting to create a header that consists of a logo on the left and a list on the right. I want it to resize along with the navigation below the logo. I WAS ABLE TO ACHIEVE THIS but when ...

Using the base tag in Angular HTML5 mode can cause script links to break

Issue Following the configuration of a base tag to enable Angular 1.x in HTML5 mode, encountering an error where the browser (Chrome) sends requests to an incorrect path for scripts when directly accessing the app via localhost:3000/resource/id. Specific ...

Here is a guide on how to ensure that the div elements automatically fill the available space

Looking at this html page: Check out the jsFidlle Demo here I am aiming to have the boxes fill up the space effortlessly, each with equal width but varying heights. This is similar to the layout in Google Keep notes ...

error in jquery when splitting

I encountered an issue while trying to split data for checkboxes. var ukuran = data['model'].ukuran_model; var cek = ukuran.split(",").join('], [value='), $inputs = $('input[name^=ukuran]'); $inputs.filter('[value=&a ...

Using Javascript to Treat an HTML Document as a String

Check out the complete project on GitHub: https://github.com/sosophia10/TimeCapsule (refer to js/experience.js) I'm utilizing JQuery to develop "applications" for my website. I'm encountering a problem where I can't locate the correct synta ...

How come .trim() isn't cooperating with me?

I am encountering an issue with this particular piece of javascript. Every time I attempt to use it, nothing is displayed in my div. Instead, it simply adds ?weight=NumberInputed&measure=lbsOrkgs&submit=Submit to the URL. <h2>What size d ...

Deactivate while maintaining menu options

Currently, I have a Vue.js form that manages adding and updating data for patients. The issue at hand involves a <select> tag which allows for the addition of a relative. This select field is populated by an array called PPrelations, which is sourced ...

eliminating and adding a node

Is there a way to replace the existing span elements inside the div (<div id='foo'>) with newly created nodes? I have been looping through all the children of the div, using removeChild to remove each node, and then appending a new node in ...

Can CSS be utilized to define the dimensions and background of a <div>?

Does applying inline styles like <div style="width: ;height: ;background: "> fall under the realm of CSS? ...

Using Jinja2 to loop through and create Bootstrap accordion items for each element

I have integrated the Bootstrap accordion element into a Jinja template for a loop, with the code looking like this: <div class="accordion" id="accordionExample"> {% for article in articles %} <div class="accor ...

What is causing all webkit browsers to overlook the z-index in my code?

I have removed all unnecessary elements from my webpage to focus on reproducing a specific issue. HTML: <html lang="en-us"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initi ...