如何在按下按钮时更改 div 的大小。到目前为止,当您按下按钮时,侧面菜单会消失,但我如何让内容填满容器的其余部分?
代码在哪里:
<?php
include 'lang/language.php';
?>
<html>
<head>
<title>Home | Gmod </title>
<link rel="stylesheet" href="styles/buttons.css">
<link rel="stylesheet" href="styles/main.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("#navbar").hide(1500);
});
$("#show").click(function(){
$("#navbar").show();
});
});
</script>
</head>
<body>
<div id="container">
<div id="navbar">
<div class="logonav">
<font size="6"><a href="index.php">Gmod Tools</a></font>
</div>
<div id="divider">
Main Menu
</div>
<a href="http://testingwebsite.comuv.com/" class="contentmenubutton"><div id="hoverbar"></div><div class="textnav"><?php echo "$gmod_home"; ?></div></a>
<a href="http://testingwebsite.comuv.com/about.php" class="contentmenubutton"><div id="hoverbar"></div><div class="textnav"><?php echo "$gmod_about"; ?></div></a>
<a href="http://testingwebsite.comuv.com/tools.php" class="contentmenubutton"><div id="hoverbar"></div><div class="textnav"><?php echo "$gmod_tools"; ?></div></a>
<a href="http://testingwebsite.comuv.com/tools/index.php" class="contentmenubutton"><div id="hoverbar"></div><div class="textnav"><?php echo "$gmod_testing"; ?></div></a>
<button id="hide">Hide</button>
<button id="show">Show</button>
</div>
<div id="content">
<div id="footer">
<div class="copyrightnotice">
© gmodtools.com, 2015. All right reserved.
</div>
</div>
</div>
</div>
</body>
</html>
最佳答案
使用 document.getElementById 函数获取对 div 内容的访问权限,然后使用 javascript 编辑其样式信息。像这样的东西:
divContent=document.getElementById("content");
divContent.style.width=the-width-you-want;
divContent.style.height=the-height-you-want;
除此之外,如果您只想根据内容调整 div 的大小,除非您的 div 是绝对的,否则它会自行执行。看看另一篇文章:How to make a parent div grow with its children?
还有另一篇文章,内容类似,展示了跨浏览器解决方案的示例:Setting DIV width and height in JavaScript
关于jquery - 如何使用 jQuery 和 CSS 调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32131139/