I’m trying to make a button that contains a rectangular progress bar at the bottom of it, but still within it. The bar should be 100% the width of the button. I’ve tried a bunch of different methods including absolute position, grid, flex, table, and for whatever reason, they either hide the progress bar or display it too high (just below the label). I’m losing my mind trying figure this out. Thanks!
.rect {
padding: 8px;
border-radius: 3px;
border: 1px solid #1d3557;
background: #faf5ff;
width: 208px;
text-align: center;
position: relative;
}
.rect:hover {
background: #f5f6ff;
}
.rect:active {
background: #eff1ff;
}
.progressBar {
height: 2px;
margin-left: -8px;
margin-right: -8px;
position: absolute;
bottom: 0px;
background-color: rgb(23, 56, 165);
}
.label {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="rect" on:click>
<div class="label">I'm a button</div>
<div class="progressBar"></div>
</div>
3
Answers
I was playing around with you code on https://www.tutorialspoint.com/online_html_editor.php, and after I added
width: 100%;
inside the.progressBar
, I saw a small bar appear at the bottom of the button. Does that solve your problem?Do you mean something like this?
HTML:
CSS:
Codepen Link
As per my understanding you can try.
HTML
CSS
Codepen Example