Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions css-progress/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@ body {
display: flex;
justify-content: center;
align-items: center;
--custom-minwidth: 320px;
--custom-maxwidth: 1200px;
}

article {
min-width: var(--custom-minwidth);
max-width: var(--custom-maxwidth);
position: relative;
min-width: 320px;
max-width: 1200px;
width: 70%;
height: 600px;
border: 3px solid black;
}

.progress {
width: calc((progress(var(--container-width), 320, 1200)) * 100%);
width: calc(
progress(
var(--container-width),
var(--custom-minwidth),
var(--custom-maxwidth)
) * 100%
);
height: 4px;
background-color: red;
position: absolute;
Expand All @@ -37,7 +45,11 @@ article {
inset: 0;
background-image: url(https://mdn.github.io/shared-assets/images/examples/wide-background.jpg);
background-position-x: calc(
progress(var(--container-width), 320, 1200) * 100%
progress(
var(--container-width),
var(--custom-minwidth),
var(--custom-maxwidth)
) * 100%
);
}

Expand All @@ -46,13 +58,33 @@ article {
inset: 0;
padding: 20px;
background-color: rgb(
calc(255 * progress(var(--container-width), 320, 1200))
calc(255 * progress(var(--container-width), 320, 1200)) 255 / 0.5
calc(
255 *
progress(
var(--container-width),
var(--custom-minwidth),
var(--custom-maxwidth)
)
)
calc(
255 *
progress(
var(--container-width),
var(--custom-minwidth),
var(--custom-maxwidth)
)
)
255 / 0.5
);
opacity: calc(
(
progress(
var(--container-width),
var(--custom-minwidth),
var(--custom-maxwidth)
) / 2
) + 0.5
);
opacity: calc((progress(var(--container-width), 320, 1200) / 2) + 0.5);

/* Works without calc */
/* opacity: progress(var(--container-width), 320, 1200); */
}

.content h1,
Expand Down
4 changes: 2 additions & 2 deletions css-progress/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const articleElem = document.querySelector("article");

function setContainerWidth() {
const clientRect = articleElem.getBoundingClientRect();
const clientWidth = articleElem.getBoundingClientRect().width;
articleElem.style.setProperty(
"--container-width",
Math.floor(clientRect.width)
`${Math.floor(clientWidth)}px`
);
}

Expand Down