Creating a water vessel design using CSS

Despite going through the JS tutorial, I still struggle with it and need some assistance.

I believe using a jsfiddle would be helpful.

I am attempting to use JS to create a small box that changes color from green to empty based on the fullness of a "water container." When the container is full (1000), the box should be completely green. When it's half-full (500), the box should be half-green. And when it's empty (0), the box should be grey or transparent. The values for this are generated by PHP based on real-life container fullness readings ranging from 0 to 1000.

The challenge lies in translating these PHP values into visual representations on the GUI using JS. How can I draw a box that changes its fill level dynamically as PHP updates the fullness value from 0 to 1000?

Here is an example image illustrating what I'm trying to achieve: https://i.sstatic.net/j6642.png

The goal is to have three divs with varying green backgrounds: http://jsfiddle.net/AAVT4/1/

My approach involves placing these three divs inside a larger container and adjusting their heights based on the PHP-provided values to simulate changing water levels. However, I've been struggling to get the CSS right for this layout.

HTML

</cite>

<div class="hold"><div class="contain">
<div class="mpd1">This is box 1.</div>
<div class="mpd2">This is box 2.</div>
<div class="mpd3">This is box 3.</div></div></div>
<div class="corner"></div>
<div class="mpd"><a href="http://www.myspaceprodesigns.com"><img src="http://www.myspaceprodesigns.com/images/MPD.jpg" alt="myspace div generator" title="myspace div generator"></a></div>
<div class="comments">
<table><tr><td>
<table><tr><td>

CSS

<cite style="display:none">

</cite>

<style type="text/css">
.DivOverlayLayouts.com-div-generator{display:none}
body {
background-color:FFFFFF
}
.contain div {
background-color:76EE00;
color:FFFFFF;
font: 10pt Arial,Helvetica,sans-serif;
overflow:auto
}
a:link, a:active, a:visited, a.navbar:link, a.navbar:active, a.navbar:visited, a.man:link, a.man:active, a.man:visited, a:hover, a.navbar:hover, a.man:hover {
color:000000;
font: 10pt Arial,Helvetica,sans-serif
}
.mpd1{width:225px;height:600px;top:0;left:50px;position:absolute}
.mpd2{width:225px;height:600px;top:0;left:285px;position:absolute}
.mpd3{width:225px;height:600px;top:0;left:520px;position:absolute}.hold{background-color:transparent} 
.contain{left:50%;margin-left:-400px;top:150px;position:absolute;z-index:0;background-color:transparent;visibility:visible}
.corner{left:0;top:0;position:absolute;z-index:9;visibility:visible !important}
.mpd{left:50%;margin-left:-400px;top:0;position:absolute;z-index:9;visibility:visible !important}
.comments{display:none}
.contacttable,.profileinfo,.latestBlogEntry,.interestsAndDetails,.extendedNetwork,.orangetext15{display:none}
.bodyContent div div form{display:inline}
.bodyContent table table table{visibility:hidden}
a img{border:none}
td,form{margin:0;padding:0}
table,tr,td{background:transparent}
DivOverlayLayouts.com-additional-coding{display:none}
</style>

Answer №1

Check out this solution for displaying water in a tank:

Try it out on Fiddle: http://jsfiddle.net/AAVT4/3/

<div class="tank">
    <div class="water" style="height: 30%;"></div>
</div>

<div class="tank">
    <div class="water" style="height: 70%;"></div>
</div>

<div class="tank">
    <div class="water" style="height: 10%;"></div>
</div>

CSS

.tank {
    /* dimensions */
    width: 150px;
    height: 300px;

    /* styling */
    border: 2px solid black;
    background: white;

    position: relative; 
    display: inline-block; 
    margin: 10px; 
}

.tank .water {
    position: absolute;

    /* color of water */
    background: blue;

    /* water positioning */
    width: 100%;
    bottom: 0;
}

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

Is there a way to implement a scrollbar that only scrolls through one specific column in an HTML table?

I need help adding a scrollbar to a specific column in an HTML table. Take a look at this scenario https://jsfiddle.net/6wpdc4tL/: https://i.stack.imgur.com/svzIg.png This table should have two scrollbars, one for the light blue SCROLL column and another ...

Discover the method for retrieving information through AJAX requests and dynamically displaying or hiding content based on the received

Currently, I'm in the process of developing a PHP script that outputs a numerical value indicating the number of unread messages. The snippet below showcases my code that triggers the PHP function every 30 seconds: setInterval(function (){ ...

Receiving a commitment from an Angular Resource

When working with $resource in Angular for CRUD operations, I'm encountering some confusion regarding the usage of different resource methods. From what I've observed, the "regular" methods like save() and get() appear to execute synchronously. ...

Using Node.js to establish communication between HTML and Express for exchanging data

I am faced with a challenge involving two pages, admin.hbs and gallery.hbs. The goal is to display the gallery page upon clicking a button on the admin page. The strategy involves extracting the ID of the div containing the button on the admin page using J ...

Disabling CSS transitions and attempting to alter the style of an HTML element using JavaScript may not consistently work as expected

Currently, I am in the process of creating an animated effect for a website that involves moving two elements' positions over time and resetting them to their original position. Only one element is displayed at a time, and the animation should run smo ...

Node.js C++ addons provide accessors for interacting with Node.js from native

How can I implement setter and getter for a global variable 'X' in a C++ extension for Node.js? I am encountering issues with undefined 'x' while using the getter and setter methods. Currently working on a program involving Accessors ...

Error encountered: Unable to reference Vue as it has not been defined while importing an external JavaScript file

Currently, I am implementing a package called https://github.com/hartwork/vue-tristate-checkbox within my Vue.js component by adding it through the command: yarn add hartwork/vue-tristate-checkbox. In my Vue.js component, the package is imported in the fo ...

Designing a unique customized top navigation bar in Magento 1.9.2

I recently attempted to create a unique top menu in magento 1.9.2 by modifying the Navigation.php file located at app/code/core/Mage/catalog/Block/. I added some custom classes in an effort to customize the menu. In order to achieve this customization, I ...

JavaScript - Toggling checkboxes to either be checked or unchecked with a "check all" option

To create a toggle checkboxes functionality, I am attempting the following: HTML Code: <!-- "Check all" box --> <input type="checkbox" name="check" id="cbx_00_00" onclick="selectbox( this.getAttribute( 'id' ));" /> <!-- the other ...

Problem encountered when transferring JSON data to PHP for file writing

After spending numerous hours researching potential solutions, I still can't seem to fix the issue at hand. Admittedly, I am fairly new to PHP, so it's possible that I am overlooking a small detail. The problem lies in the fact that I have a form ...

PrimeFaces: Achieving Conditional Coloring Based on Status (Passed/Failed)

Attempting to dynamically change the color of a column based on its status value (Passed/Failed/InProgress) using jQuery. I tried copying and pasting the table into jsfiddle, where it worked. However, when implemented in the actual XHTML file, the jQuery ...

Closing WebSocket connection after sending data

I came across an interesting blog post titled Experimenting with Node.js and decided to try setting it up on my own using the author's provided gist. Unfortunately, I encountered some issues. After further investigation, I discovered that even though ...

Updating Angular 5 Views Dynamically Using a While Loop

I am facing an issue in my app where I have a progress bar that updates using a while loop. The problem is that the view only updates after the entire while loop has finished running, even though I am successfully changing the update progress value with ea ...

Ways to transfer JavaScript arguments to CSS style

Currently, I am developing a web service using Angular and Spring Boot. In this project, I have implemented cdkDrag functionality to allow users to place images in specific locations within the workspace. My goal is to maintain the placement of these image ...

Dreamweaver restricts my ability to utilize JavaScript for coding

My JavaScript isn't working in Dreamweaver. I have linked the script file correctly using the given code: <script src="file:///C:/Users/Matthew/Desktop/Untitled-2.js" type="text/script"></script> However, when I try to call it with scrip ...

Dynamic JavaScript Total Calculation

I have been struggling to update the total price for specific options. Even though the code was created by someone else and has worked fine for many users, I can't seem to make it work correctly. Any assistance would be greatly appreciated. Here is t ...

Preview of Live Iframe Display

Currently, I am in the process of developing a node.js website that enables users to create and customize their own page using a dashboard interface. One specific feature I would like to incorporate is a live preview capability, similar to what Shopify o ...

Browser resize affects the overlap of DIVs

I've seen similar posts before, but I believe the issue with my website (***) is unique. At full size, the website looks exactly how I want it to. However, when I resize the browser window, the text ("ABOUT INTERNATIONAL PARK OF COMMERCE.." and below ...

Develop a custom cell editor for ag-Grid and insert it into a designated location within

I am currently working with Angular 16 and AgGrid 30. My goal is to have the cell editor created in a different location than its default position, which is within a div element at the bottom of the body with these classes: ag-theme-material ag-popup. I w ...

Learn the process of extracting data from dynamically generated elements in JavaScript

I am a beginner in Javascript and Jquery and have recently started exploring business rules with Chris Powers. https://github.com/chrisjpowers/business-rules My current project involves adding a range slider for numbers and a number spinner. I attempted us ...