css - 垂直自动时如何使用CSS保持水平可见?

标签 css html overflow

一共有三个div,d1,d2,d3,我希望d1可以垂直包裹内容,水平可见。

如果 d2 和 d3 没有 float 属性,d1 会给我我想要的结果。

但 d2 和 d2 具有 float 属性,我需要添加 overflow-y:auto 使其垂直环绕。

我添加了 overflow-x:visible,但它仍然有一个滚动条。

那么如何保持水平可见呢?

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
#d1
{
    background-color:red;
    padding:10px;
    width:100px;

    overflow-x:visible;
    overflow-y:auto;
}
#d2
{
    background-color:blue;
    float:left;

    width:150px;
    height:30px;
}
#d3
{
    background-color:green;
    float:left;

    width:50px;
    height:230px;
}
</style>
</head>
<body>
<div id="d1">
    <div id="d2">in</div>
    <div id="d3">
        out
    </div>
</div>
</body>
</html>

最佳答案

如果我理解你的问题,你可以使用“清晰”的 DIV 来解决这个问题。编辑代码:

CSS

<style>
#d1
{
    background-color:red;
    padding:10px;
    width:100px;

    overflow-x:visible;

}
#d2
{
    background-color:blue;
    float:left;

    width:150px;
    height:30px;
}
#d3
{
    background-color:green;
    float:left;

    width:50px;
    height:230px;
}

.clear{
    clear:both;
}
</style>

HTML

<div id="d1">
    <div id="d2">in</div>
    <div id="d3">out</div>
    <div class="clear"></div>
</div>

关于css - 垂直自动时如何使用CSS保持水平可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11218688/

相关文章:

javascript - 根据 Web 浏览器的大小调整对象的大小

html - 仅CSS的砌体布局

css - firefox 49,边界半径+溢出:hidden not working

javascript - 将框架集与页面中的其他 HTML 元素一起使用

html - 适本地包含有边距和填充的 child

scroll - -webkit溢出滚动: touch; breaks in Apple's iOS8

java - 文本小部件是否可以显示溢出,并在文本中间而不是末尾显示 "..."?

javascript - 动态创建嵌套 CSS

html - 使用导航栏 Bootstrap 全屏谷歌地图

html - 如何填充SVG图像