CSS - get property of another element

I wonder if it's possible to reference some elements using something like the Javascript DOM, without using Javascript or other programming languages.
This is what I mean. Suppose we have two divs that should be the same height. I would like the first div height to assign this to the second, for example:

#div1 {
    height:400px;
}

#div2 {
    height:#div1.height;
}

As you can see, I am doing exactly the same document.getElementById ("id"). style.height in Javascript.
Is it possible to do this? If not, I was wondering if there was a forum, a website, etc., to discuss CSS improvements or to get an idea of ​​this language development.
Thanks in advance!

+4
4

Internet Explorer " CSS", (?) , . , .

, , " ", W3C. , (HTML) (CSS) (JavaScript).

, "" CSS, script, , :

  • , JS CSS; , JS ..
  • , JavaScript
  • CSS , , , buggier
  • CSS , ( ) , ; , , , ,
  • CSS , Turing- .

IE ( , ). , JS CSS, .

, "" , , Turing-complete. , , "", , "", JS. , CSS ( ) JS .

, : W3C , CSS , , .

ETA

, , (, width:element1.width*2) . CSS-Variable -, . , , ; , JS, , , CSS ..

+1

CSS Variable

index.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="styles.css">
    </head>
    <body>
        <div id="div1">
            <p>This is div1</p>
        </div>
        <div id="div2">
            <p>This is div2</p>
        </div>
    </body>
</html>

styles.css

body{
  --div-height:400px;
}

#div1 {
  height:var(--div-height);
}

#div2 {
  height:var(--div-height);
}

-div-height , css.

+4

It's impossible. You will need to use JS and DOM.

+1
source

Use CSS Flexbox ....

Check out this tutorial  and this demo .

.container {
  align-items: stretch;
}
+1
source

Source: https://habr.com/ru/post/1672867/


All Articles