Is there a way to shift this div to the bottom and incorporate some quirky pop-up squares?

I am struggling to figure out how to move this div to the bottom. Additionally, I want to create temporary pop-up squares (simple divs) in random directions that will disappear after 50ms.

My attempt to float this box to the bottom did not yield the desired result.

$("#button").click(function() {
  $('.transform').toggleClass('transform-active');
});
.field {
  height: 340px;
  width: 200px;
}

.box {
  background-color: #218D9B;
  height: 320px;
  width: 160px;
  float: bottom;
  background-image: url("img/tree.png");
  background-size: 100%;
}

.transform {
  -webkit-transition: all 300ms ease;
  -moz-transition: all 300ms ease;
  -o-transition: all 300ms ease;
  -ms-transition: all 300ms ease;
  transition: all 300ms ease;
}

.transform-active {
  height: 0px;
  width: 160px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="field">
  <div class="box transform"></div>
</div>

<input type="button" id="button" value="Click Me" />

I hope to achieve an effect where the wood appears to be hiding in the ground.

Answer №1

To adjust the height of the div to align with the bottom, you can utilize positioning. Simply add position: relative to the parent element, and then customize the box element with position: absolute along with bottom: 20px.

.field {
    height: 340px;
    width: 200px;
    position: relative;
}
.box {
    background-color: #218D9B;
    height: 320px;
    background-image: url(img/tree.png);
    background-size: 100%;
    bottom: 20px;
    position: absolute;
}

Alternatively, in certain scenarios, you could consider utilizing transform: scale() for resizing instead of adjusting the height property.
By scaling vertically only and setting transform-origin: bottom, you achieve the desired effect.

.box {
    background-color: #218D9B;
    height: 320px;
    width: 160px;
    background-image: url(img/tree.png);
    background-size: 100%;
    transform-origin: bottom;
}
.transform-active {
    transform: scale(1, 0);
    width: 160px;
}

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

Preventing default events and continuing with jQuery

Currently, I am working on a Django project and have integrated the Django admin along with jQuery to insert a modal dialog between the submission button and the actual form submission process. To accomplish this, I have included the following code snippe ...

Change the space character ' ' to '-' when a key is lifted

Hey, I need some help with a coding problem. I have two input fields and I want to automatically mirror the text from the first input into the second input field using a keyup jquery function. However, my current setup adds a space whenever I hit the spac ...

Steps to capture cell click events in a Kendo grid

My grid is displaying information about students. I want to show a popup when the user clicks on the "StudentId" or "SubjectId" cell in those columns. How can I get the cell click event and verify that it is the right column? @(Html.kendo().Grid<St ...

implementing a SetTimeOut function following the clicking of a button

Hey there, I've been working on a code snippet that switches the display state from block to none with an onClick function. However, I'm looking to add a delay before the state change happens so that there's time for an animation effect to ...

Employing ajax with dynamically created buttons in PHP

I'm struggling to figure out what to search for in this situation. I've tried piecing together code from others, but it's just not working for me. My ajax function successfully retrieves data from a database through a php page and displays ...

TabContainer - streamline your selection process with inline tabs

I am currently working on a GUI that includes a TabContainer with two tabs, each containing a different datagrid. I initially created the tabcontainer divs and datagrids declaratively in HTML for simplicity, but I am open to changing this approach if it wo ...

Alter the class following modifications to the list

https://i.stack.imgur.com/QZob0.pngIn my dual list, the data is displayed in a ul li format fetched from a JSON file. Users can move items between the two lists. However, I am facing an issue where I want to apply a property that only displays content with ...

What is the best way to stop Quasar dropdown list from moving along with the page scroll?

I am facing an issue with my code while using Quasar (Vue 3.0). The code snippet in question is: <q-select filled v-model="model" :options="options" label="Filled" /> When the drop-down menu is open and I scroll the pag ...

The absence of underlines for <a href> and <u> is causing an issue

Below is a snippet of code that I am working with: echo "<form> <div id=\"error\"align=\"center\">"; echo "You've either entered the incorrect <b>username</b> or incorrect <b>passwor ...

Using the comma separated values as the final parameter in the ng-repeat loop

In my select element, I am utilizing ng-repeat to generate options. My goal is to include a final option labeled All, which should display the comma-separated values of all the other options. <select ng-model="facilityIdForEquipment" ng-change="loadFa ...

Tips for adjusting the color of a <a> tag upon clicking, which remains unchanged until the URL is modified

My goal is to maintain the color of a link when it is clicked. Currently, hovering over the navbar link changes it to greyish, but I want it to remain a different color after clicking on it. I am implementing this using the react-router-dom library for the ...

The initial return value of $(document).height may be inaccurate, but is accurate upon recalculation

I am working on implementing a pop-up screen and I would like to darken the background when it opens. Below is the Javascript code: $(document).on('click', '.item', function(){ $("#popUp").css("display" , "block"); ...

Alignment of a div at the bottom inside a jumbotron using Bootstrap 4

Searching for answers on how to vertically align a div within a jumbotron, I have come across plenty of solutions for middle alignment but none for bottom alignment. <section id="profileHero"> <div class="container"> <d ...

Get rid of the border surrounding a main call-to-action button

While trying to override Bootstrap styles, I encountered a problem. Whenever the user presses a primary button <button class="btn btn-primary">Test</button> An annoying blue outline appears and I can't seem to remove it. I attempted to o ...

Use CSS specifically for codeigniter viewpage

I am unsure if it is possible, but I would like to load CSS and JavaScript within a view page instead of on include.php. Currently, the CSS file is loading on include.php and it is working correctly. What I want to achieve now is to load it directly inside ...

Clicking on an element will remove a class and unselect an input using JQuery

Trying to achieve a functionality where clicking on a list item with a radio button input selects it, but clicking again deselects it. The issue is despite various attempts, nothing seems to work properly. function setupToptions() { if ($('ul.top ...

Extracting data from JSON response

The JSON output is as follows: [{"Post":{"name":"Name1","text":"Text1"}}, {"Post":{"name":"Name2","text":"Text2"}}] In attempting to retrieve the values, I used the following code: var data = $.parseJSON(result) // converting JSON to object I tried acc ...

python conducting automation tests with Selenium WebDriver on a mouse

Hello, I'm having trouble with opening the Mouser website and using the search bar to send some data. Below is a sample of the code I've been working on, but I can't seem to find the correct CSS selector. Any help would be greatly appreciate ...

Tips for emphasizing a chosen hyperlink within a jQuery Mobile panel

I am currently working on a jquery mobile page that includes a navigation menu in a sliding panel. While the functionality is good, I am looking to enhance the user experience by highlighting the selected link in the navigation. Typically, I would utilize ...

Which is the better choice: jQuery or AJAX?

After careful consideration, I have chosen to utilize jQuery for all of my client-side AJAX requirements. However, I find that there are numerous functions in jQuery that can accomplish the same task, such as $.post, $.get, $.ajax, and $.getJSON. What woul ...