简体   繁体   English

如何使用 JS 更改 CSS 高度?

[英]How can I change CSS height with JS?

I'm trying to adjust the height of the .topnav and its container.我正在尝试调整.topnav及其容器的高度。 How can I do this with javascript onclick when the .icon is clicked?单击 .icon 时,如何使用.icon onclick执行此操作? myFunction() should bee triggered. myFunction()应该被触发。

<div class="topnav" on="myBoi()">
  <img style="width: 380px; height: 300px; position: relative; left: 35%;
            bottom: 40px;" src="mobilfotoğraflar/teknik-soğutma-logo.png" alt="">
  <div id="myLinks">
    <a class="yazı" href="#anasatyfa"></a>
    <a class="yazı" href="#news">News</a>
    <a class="yazı" href="#contact">Contact</a>
    <a class="yazı" href="#about">About</a>
  </div>
  <a href="javascript:void(0);" class="icon" onclick="myFunction()">
    <i class="fa fa-bars"></i>
  </a>
</div>

Try below code试试下面的代码

 function myFunction() { document.getElementById('id1').style.height= '400px'; }
 .topnav{background:#eee;}
 <div class="topnav" on="myBoi()" id="id1"> <img style="width: 380px; height: 300px; position: relative; left: 35%; bottom: 40px;" src="mobilfotoğraflar/teknik-soğutma-logo.png" alt=""> <div id="myLinks"> <a class="yazı" href="#anasatyfa"></a> <a class="yazı" href="#news">News</a> <a class="yazı" href="#contact">Contact</a> <a class="yazı" href="#about">About</a> </div> <a href="javascript:void(0);" class="icon" onclick="myFunction()"> <i class="fa fa-bars"></i> </a> </div><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM