<!DOCTYPE html> <html> <style> #myProgress { position: relative; width: 50px; /* Lebar progress bar vertikal */ height: 200px; /* Tinggi progress bar vertikal */ background-color: #ddd; border-radius: 5px; /*display: flex;*/ /*flex-direction: column;*/ /*align-items: center;*/ /*justify-content: flex-end; /* Letakkan label di tengah vertikal */ } #myBar { position: absolute; bottom: 0; /* Letakkan progress bar di bagian bawah */ /*top: 0;*/ width: 100%; height: 0; background-color: #1E90FF; border-radius: 5px; transition: height 0.2s; /* Efek transisi ketinggian */ /*display: flex;*/ /*flex-direction: column-reverse; /* Pindahkan label ke atas */ /*align-items: center; */ display: flex; flex-direction: column; /*flex-direction: var(--bar-direction, column); /* Menggunakan variabel CSS */ justify-content: center; /* Letakkan label di tengah secara horizontal */ align-items: center; /* Letakkan label di tengah secara vertikal */ } #label { text-align: center; color: black; font-size: 16px; } </style> <body> <h1>JavaScript Vertical Progress Bar</h1> <div id="myProgress"> <div id="myBar"> <div id="label">0%</div> </div> </div> <br> <button onclick="setWaterLevel()">Set Water Level</button> <script> // Inisialisasi waterLevel ke 0 saat program dimulai var waterLevel = 0; var percentage = 0; // Fungsi untuk mengatur tinggi progress bar function updateProgressBar() { const elem = document.getElementById("myBar"); var percentage = (waterLevel / 160 * 100).toFixed(1); elem.style.height = percentage + "%"; document.getElementById("label").innerHTML = percentage + "%"; // Mengubah flex-direction berdasarkan tinggi progress bar if (percentage == 0) { elem.style.flexDirection = "column-reverse"; elem.style.justifyContent = "unset"; } else if (percentage > 0){ elem.style.justifyContent = "center"; } } // Jalankan updateProgressBar() saat halaman dimuat pertama kali document.addEventListener("DOMContentLoaded", function() { updateProgressBar(); }); function setWaterLevel() { var inputValue = prompt("Masukkan tinggi air dalam persentase (0-160):"); var newWaterLevel = parseFloat(inputValue); // Mengatasi input yang tidak valid if (isNaN(newWaterLevel) || newWaterLevel < 0 || newWaterLevel > 160) { alert("Masukkan angka antara 0 dan 160."); return; // Keluar dari fungsi jika input tidak valid } // Mengubah nilai waterLevel hanya jika input valid waterLevel = newWaterLevel; // Memanggil fungsi untuk memperbarui tampilan progress bar updateProgressBar(); } </script> </body> </html>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>