html - CSS div溢出隐藏和 float

标签 html css

我正在尝试一些非常简单的事情:

创建一个左侧带有文本的正文,并为从最大到最小的 px 量占用所有可用空间,它可以 float 。在该 div 的右侧,我想添加一个新的 div,它的末尾将包含一个菜单。

我看了一下这个论坛并尝试了很多东西,但我无法实现我想要的。

我希望我的#rightcolumn 在可能的时候在右边,而在不可能的时候,它应该被隐藏。

我成功地找到了我想要的一切,但从来没有同时找到。

我在相关位置工作,使用 inline 而不是 float,没有 float 它不在同一行。

这是我的实际代码:

    <!DOCTYPE html>
<html>
<head>
<style>
html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    b, u, i, center,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td,
    article, aside, canvas, details, embed,
    figure, figcaption, footer, header, hgroup,
    menu, nav, output, ruby, section, summary,
    time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
    }
    /* HTML5 display-role reset for older browsers */
    article, aside, details, figcaption, figure,
    footer, header, hgroup, menu, nav, section {
    display: block;
    }
    body {
    line-height: 1;
    }
    ol, ul {
    list-style: none;
    }
    blockquote, q {
    quotes: none;
    }
    blockquote:before, blockquote:after,
    q:before, q:after {
    content: '';
    content: none;
    }
    table {
    border-collapse: collapse;
    border-spacing: 0;
    }



img 
{
float:bottom;

border:1px dotted black;
margin:0px 0px 15px 20px;
}
p {
    padding: 10px;
}

#rightcolumn{
    margin-left: -150px;
    width: 150px;
    height: 100px;
/*  float:left;*/
    background: #CC33FF;
float:left;
overflow:hidden;
    }

#wrapper {
    width: 100%;
    min-width: 1000px;
    max-width: 1000px;
    margin: 0 auto;
white-space:nowrap;

}


#contentliquid {
    float: left;
    width: 100%;
    min-width: 1000px;
float:left;
}

#content {

    background: #FFFFFF;
    margin-left: 0px;
    min-width: 1000px;
float:left;
}

</style>
</head>

<body>
<div id="wrapper">

    <div id="contentliquid">
        <div id="content">
            Test coucou
            </div>
    </div>

<div id="rightcolumn">
            <p>This is right</p>
        </div>

</div>
</body>

</html>

最佳答案

如果我理解你的问题是正确的。 我会说使用 JavaScript 会很容易

$(文档).ready(函数(){ var length_of_content = $('#content').width();

if((length_of_content+$('#rightcolumn').width()) >= 500) {
    $('#rightcolumn').css('display', 'none');
}

});

只需检查当前内容的长度并添加要显示的菜单的宽度,如果宽度 >= 500 或容器的最大尺寸应该是什么,则只需使用 #rightmenue 隐藏菜单,否则显示它.

关于html - CSS div溢出隐藏和 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23627527/

相关文章:

javascript - 打印网页时提供 PDF 文件

javascript - 删除 React 中内联 block 元素之间的空格

css - 伪类嵌套/SCSS Linter 警告

jquery - 元素的引导轮播 slider ID 出现在 URL 中

javascript - 如何使用 JQuery 从按钮单击中获取 Extreme DIV 的 ID、名称和类?

php - html文本区域的白名单

javascript - 使用 javascript href 链接附加一次

html - 制作一个头部,左右各有2个选择,中间有一个logo

html - 百分比高度在 Chrome 中的嵌套 flexbox 布局中不起作用

html - 添加 URL 重定向到按钮组按钮