style property overwrites class
Table of Contents
in HTML, element’s style property is the highest priority
<div class="red" style="background-color: blue"></div>
with
.red{ background-color:red; }
will give blue.
Backlinks
as css class overwrites from left to right and style property overwrites class, it is better to avoid the style property unless dynamic positioning with style.left is necessary, as style property would always overwrite class, it make element.classList.add("class") behaviour not as expected.
clicking button to enlarge its parent in js
in react.js or next.js, this could be done by:
- onClick function gets object
e parent = e.currentTarget.parentNodegets you the parentparent.style.position = absoluteandparent.style.left/right/top/bottomchange size with respect to their distance to closestrelativecontext;parent.style.width/heightchange absolute size- with
parent.classList.add/remove("class")and a class with larger size with the above css properties, the parent would be enlarged
note: