Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: grid template rows Date: Mon, 19 Aug 2019 12:24:44 +0200 Lines: 56 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net nsk98a7JuJUU1iQlxnCcbADA8DbChWErTlqXS1Oao8lC5H2Kcv Cancel-Lock: sha1:KeuHOYkqsY3CaNAcWUz82NcmWAQ= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.javascript:37150 On 19.08.19 04:52, Andrew Poulos wrote: > With this HTML > >
> > console.log(container.style.gridTemplateRows); > > gives "64px 32px 1fr 32px;" Yes, this is the literal style attribute of the element. > But with this > > #container { > grid-template-rows: 64px 32px 1fr 32px; > } > >
> > let con = document.getElementById('container'); > console.log( window.getComputedStyle(con, > null).getPropertyValue("grid-template-rows") ); > > gives "64px 32px 497px 32px;" > > That is, the third value is a pixel value instead of 1fr. Since you use window.getComputedStyle() you will get the *computed* style and not the CSS rule behind it. "1fr" is *not* an absolute size, it is a "fraction" which has to be computed to an actual value before the browser can display the element. > How can I get the actual value as set in the CSS and not the pixel values? You can't. If you need to get the CSS rule itself, you have to iterate through the rules until you find the one which maches the assigned class property. Also see . > I need to manipulate the value for grid-template-rows and the moment I > get the value, any fr unit is lost and the layout breaks. If you set the values anyway - why don't you do the calculation for the "1fr" column as well? Also see . -- Arno Welzel https://arnowelzel.de