jquery - 如何使用 jQuery 和 CSS 调整大小

标签 jquery html css

如何在按下按钮时更改 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">
                &copy 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/

相关文章:

html - Zebra 将带有包装元素的 flexbox 表 strip 化

javascript - 如何找到不比选择器更深的元素?

jquery - 使用 scrollTop() 时,我的页面会创建一个额外的空白 div。我该如何摆脱它?我的代码如下

html - 带方括号的编码 URL。 Chrome/Firefox/IE 中的不同行为

html - "Fluid"CSS 中的悬挂缩进

html - 左对齐两个表格,同时保持第一个(具有流动宽度)居中

javascript - 新的 &lt;style&gt; 元素在 IE 中不起作用

javascript - jQuery - 使用 onClick 停止 anchor <a> 重定向 ="function(this)"

css - 将 Font Awesome 图标垂直居中并对齐到表格的左侧

php - 如何使 bbcode 将 url 标记解析为链接?