最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I get height of any element using LESS? - Stack Overflow

programmeradmin0浏览0评论

How can I get height of any element using LESS?

<html>
<head>
<title></title>

<style>

    html, body {
        height: 100%;
    }

    header {
        height: auto;
        text-align: center;
        background: red;
    }

    @windowHeight: `$(window).height()`;
    @headerHeight: `$('header').height()`; /* NOT WORKING */

    @sectionHeight: @windowHeight - @headerHeight;

    section {
        height: ~'@{sectionHeight}px';
        text-align: center;
        background: green;
    }

</style>

</head>
<body>

    <header>TITLE<header>

    <section>TEXT</section>

</body>
</html>

How can I get height of any element using LESS?

Example if I set <header> height = 100px, then this code is working

How can I get height of any element using LESS?

<html>
<head>
<title></title>

<style>

    html, body {
        height: 100%;
    }

    header {
        height: auto;
        text-align: center;
        background: red;
    }

    @windowHeight: `$(window).height()`;
    @headerHeight: `$('header').height()`; /* NOT WORKING */

    @sectionHeight: @windowHeight - @headerHeight;

    section {
        height: ~'@{sectionHeight}px';
        text-align: center;
        background: green;
    }

</style>

</head>
<body>

    <header>TITLE<header>

    <section>TEXT</section>

</body>
</html>

How can I get height of any element using LESS?

Example if I set <header> height = 100px, then this code is working

Share Improve this question edited Aug 5, 2014 at 10:43 4dgaurav 11.5k4 gold badges34 silver badges59 bronze badges asked Aug 5, 2014 at 10:24 RomanRoman 51 silver badge2 bronze badges 1
  • This is not possible in LESS. See this answer. – knuckfubuck Commented Aug 5, 2014 at 10:30
Add a ment  | 

1 Answer 1

Reset to default 7

Since LESS processes your styles BEFORE the CSS gets delivered and interpreted by the browser there is no way you can let it do the math after that. The information needed is rendered way later, so you will have to either include a JS to modify the DOM after loading or make JS build the section in the first place.

发布评论

评论列表(0)

  1. 暂无评论