Home > Web Front-end > CSS Tutorial > How Do I Debug CSS `calc()` Values?

How Do I Debug CSS `calc()` Values?

Linda Hamilton
Release: 2024-12-14 02:15:09
Original
485 people have browsed it

How Do I Debug CSS `calc()` Values?

How to debug CSS calc() values?

Problem

I have a relatively complex formula, for example: transform: scale(var(--image-scale)) translateY( calc((1px var(--element-height) (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y)))

How to debug the calculated value?
Also, is there a way to verify/highlight formula errors?

I tried this

 position: fixed;</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">display: block;
left:0;
right: 0;
background: yellow;
padding: 5px;
z-index: 100;
content: calc((1px * var(--element-height) * (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y));
Copy after login

Didn’t work

The only way I found was to Part of the calculation is placed in an unused numeric attribute, for example in the gif below background-position-x so it will display the calculated value on the calculation tab - useful but not very convenient (notice background-position-x changes as the page scrolls):

enter image description here
<div>


<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">cssProps: true
Copy after login

})
const results = Splitting ();

var parallaxedElements = document.querySelectorAll('.section');

document.addEventListener('scroll', function(e) {

parallaxedElements
Array.from(parallaxedElements).forEach((el) => {
  var bcr = el.getBoundingClientRect();
  if (bcr.y < 0 &amp;&amp; Math.abs(bcr.y) <= bcr.height) {
    el.style.setProperty("--scrolled-out-y", Math.round(Math.abs(bcr.y) * 10000 / bcr.height) / 10000);
  }
});
</p>
<p>})

< pre>html {

scroll-behavior: smooth;
Copy after login

}

body {

font-family: "Roboto";
font-size: 14px;
line-height: 1.4;
scroll-behavior: smooth;
Copy after login

}

.section {

position: relative;
background-attachment: fixed;
z-index: 1;
--image-scale: 1.2;
--scrolled-out-y: 0;
Copy after login

}

.section__background {

position: -webkit-sticky;
position: sticky;
top: 0;
width: 100%;
height: 100vh;
overflow: hidden;
Copy after login

}

.section__background:after {

content: "";
position: absolute;
bottom: 0;
left: 0;
right: 0;
top: 0;
z-index: 1;
background: linear-gradient(to bottom, black, 100% white);
background: rgba(0, 0, 0, 0.4);
opacity: calc(1 + ((var(--viewport-y) * 1.5)));
Copy after login

}

.section__background>img {

height: 150vh;
width: 100%;
object-fit: cover;
position: absolute;
left: 0;
top: 0px;
user-select: none;
transform: scale(var(--image-scale)) translateY(calc((-1px * var(--element-height) * (var(--image-scale) - 1)) * var(--scrolled-out-y)));
Copy after login

}
/* .indicator:after {

    position: fixed;
    display: block;
    left: 0;
    right: 0;
    background: pink;
    padding: 5px;
    z-index: 100;
    content: calc((1px * var(--element-height) * (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y));
} */
Copy after login

.section__container {

padding-bottom: 50vh;
overflow: hidden;
align-items: flex-start;
position: relative;
z-index: 4;
Copy after login

}

.section__heading {

color: #fff;
text-transform: uppercase;
font-size: 45px;
line-height: 1.2;
font-weight: 800;
letter-spacing: 8px;
margin: 0;
overflow: hidden;
position: relative;
padding-bottom: 50px;
margin-bottom: 50px;
Copy after login

}

.section__heading :after {

content: "";
position: absolute;
top: 200px;
left: 0;
right: 0;
height: 2px;
transform: translateX(calc(var(--scrolled-out-y) * 100% - 70%));
background: #b38c6b;
Copy after login

}

.section__content {

display: flex;
color: white;
flex-direction: column;
Copy after login

}

.section__content p p {

margin-top: 20px;
Copy after login

}

.splitting {

--char-percent: calc(var(--char-index) / var(--char-total));
Copy after login

}

.splitting .char {

display: inline-block;
opacity: calc(1 + ((var(--viewport-y) * 1.5) - var(--char-percent)));
Copy after login

}

<link rel=' stylesheet' href='https://unpkg.com/splitting/dist/splitting.css'></p>
<p><section data-scroll> <div class="section__background"></p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><div>
Copy after login
Copy after login


<div>
<div>
Copy after login
Copy after login


The above is the detailed content of How Do I Debug CSS `calc()` Values?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Previous article:Why Doesn't Margin-Top Work on Span Elements in CSS? Next article:How to Create a Two-Row Bootstrap 4 Navbar?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template