CSS - creating room where it ought to be

Is there a way to adjust the alert button to eliminate extra space without setting a specific height for the parent element?

Please refer to this fiddle for reference.

Here is the HTML code:

<div class="alert-list">
    <div class="alert-error">Plase update your system with new release</div>
    <div class="alert-notify">New Release are ready for download verify with hash</div>
    <div class="alert-error">System is not actived. Please activce first for full access</div>
    <div class="alert-error">System is not actived. Please activce first for full access</div>
    <button class="bnt-show-alerts">show more</button>
</div>

And the CSS code:

.alert-list {
    width:400px;
    background-color:#E9E9E9;
    padding:3px;
    /*height: auto; automaticly arrange*/
}
.alert-error {
    background-color:rgba(255, 0, 0, 0.2);
    margin:2px;
}
.alert-notify {
    background-color:rgba(0, 255, 0, 0.2);
    margin:2px;
}
.bnt-show-alerts {
    position:relative;
    right:-310px;
    bottom:30px;
    opacity:0.5;
}
.bnt-show-alerts:hover {
    opacity:1.0;
} 

Answer №1

When utilizing the relative position and specifying right/top/bottom/left, the button is shifted from its static location, leaving its original space vacant. To relocate the button without creating empty space where it was originally positioned, consider using absolute positioning to reposition the element. For more details on positioning, refer to the documentation here

Check out the Fiddle for a live example

CSS modifications:

.alert-list {
    position:relative;
}

.bnt-show-alerts {
    position:absolute;
    right:0;
    bottom:5px;
    opacity:0.5;
}

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 elements in HTML emails be repositioned further down the page?

I am currently designing an HTML email, and I have a very basic element (ul) that I need to reposition lower on the page. After consulting Campaign Monitor's guide, it seems that they do not support negative margins or the position: absolute parent / ...

Changing between two images using HTML and CSS

I am currently designing a WordPress theme and I would like to create an effect where two different thumbnail images switch on hover. The code that I have come up with so far looks something like this : <a class="thumb" href="posturl"> <img src= ...

Asp.Net's Interactive Menu Grid

I'm looking to create a dynamic Web page using Asp.Net that will feature a movable menu with icons, similar to a grid menu on Android. I'm not sure where to start - should I use CSS, Javascript, HTML5, or JQuery? All I want is a large icon menu t ...

Guide to filling a dropdown menu by aligning with the text it contains?

I've set up two dropdown select boxes below that are exactly the same: HTML <select id="ddl1" name="ddl1"> <option value="1">TEXT 1</option> <option value="2">TEXT 2</option> <option value="3">TEXT 3&l ...

Tool for Generating HTML Comments

Is there a tool out there that can generate coded comments for HTML? I've noticed some developers use elaborate 'commented out titles' to keep track of their code. These titles are made up of characters that resemble actual text, creating a ...

Is there a way to validate form elements in HTML prior to submitting the form?

In my form, I am utilizing PHP for validation and processing, but I am interested in verifying elements as they are being filled out. Is there a way to check the current value of an element before the form is submitted? ...

Error messages are being generated by Angular CLI due to an unclosed string causing issues with the

After incorporating styles from a Bootstrap theme into my Angular 8 project and updating angular.json, I encountered a compile error displaying the following message: (7733:13) Unclosed string 7731 | } 7732 | .accordion_wrapper .panel .panel-heading ...

What is the best way to ensure a grid remains at 100% width when resizing a browser window?

Within the div element, I have two child divs. One has the class col-md-2 and the other has the class col-md-10.Check out a sample view here In the image provided, the div containing hyperlinks (Database edit, invoice, preview) is not taking up 100% width ...

Animate the background color using Element.animate() method

Experimenting with using Element.animate() to adjust the background-color in order to replicate a refresh effect. Snippet of Code: const changeColorOnPage = (id) => { document.getElementById(id).animate( [ {"background-colo ...

Interactive Map Using HTML5, CSS, and JQuery

As someone venturing into the world of web front end development, I am curious about the process of mapping an image so that specific functions can be triggered by pressing different parts. In this case, the shapes will be irregular (such as a map of Europ ...

Navigating the absence of Prismic's ability to use the <blockquote> element in their rich text editor

My experience with Prismic as a headless CMS has been mostly positive, but I recently encountered an issue that surprised me - the lack of support for a simple blockquote. It's baffling to me that such a basic HTML element is not natively supported by ...

Timing events in javascript based on frames per second

Currently, I am working on a mini-game that requires some animations to be implemented in the form of frames per second. Here is my current approach: var loadCount = 0; var ticks = 15; function loadingLoop() { loadCount++; } switch (loadCount) { ...

PHP code to create a search form with a dropdown menu

I'm currently working on developing a simple advanced search feature where users can input a keyword and select a category from a dropdown menu. The search functionality will then display results that match both the selected category and keyword in th ...

The scroll feature in JavaScript is malfunctioning

After countless hours of troubleshooting, I still can't figure out why the code snippet below is not working properly on my website at : <script> $(window).scroll(function () { if ($(window).scrollTop() > 400) { ...

My website appears distorted when the browser is zoomed out. What could be causing this issue?

Whenever I try to zoom out using Internet Explorer, the page doesn't zoom uniformly and ends up looking messy. Can someone please help me understand why this is happening? Here's how the page looks after zooming out (take a look at the three box ...

Storing information in the concealed and interactive tabs within a tabview system

In my program, users are able to access groups through a left column list, similar to how Google Groups are displayed (seen in the image below). I would like the front-end to cache visited groups as users switch between them, so that when they revisit a g ...

Utilize XML and Javascript to create a captivating donut chart

I am currently experimenting with XML and JavaScript to generate a donut chart. I attempted to implement this JS code. However, I am struggling to create XML that is compatible with the JS. var SCIENCE = 0; var ART = 0; var MATH = 0; $(document).ready ...

Can you explain the function of .modal('dispose') in Bootstrap 4?

As stated in the documentation, the .modal('dispose') method is used to destroy a modal. .modal('dispose') This method destroys the specified modal element. However, after creating an eventListener like this: $('#myModal') ...

The div is not displaying the conditional styling as expected

I need help with mapping an array of cards wrapped in a div. I want the first, second, second-to-last, and last divs to go on a new line or take up the entire row. My project is in Vue3 and I'm using the PrimeVue component library. <div class=" ...

Angular ui-router redirection without altering the ui-view contents

Here's the code snippet from my app.js: // Setting up states using $stateProvider $stateProvider .state('/', { url: "/", views: { "top": { temp ...