繁体   English   中英

如何使这个div可调整大小

[英]how to make this div resizable

我有这两个div:

<div class="bubble">
   blablablabla
 <div class="arrow-left"></div>
</div>

.bubble{
    background-color:#156ac6; 
    padding: 15px 10px 10px 10px; 
    color: white;
    font-family:Georgia;
}
.arrow-left {
    position:relative;
    top:42px;
    right:0;
    border-left: 42px solid transparent;
    border-right: 0px solid transparent;
    border-top: 42px solid #156ac6;
    margin: 10px;
}

http://jsfiddle.net/jgWmM/

我希望这是灵活的,例如,如果我调整浏览器的大小,它也应该根据浏览器的宽度缩小。 我不想要媒体查询。 只是css。 这怎么可能?

由于您没有在这些div上设置宽度,因此默认情况下应根据浏览器调整大小。 但是,您可以设置以百分比表示的宽度:

.bubble { width: 100%; }
.arrow-left { width: 100%; }

此外,您不需要媒体查询来执行此操作,但媒体查询是css。

如果在气泡上设置相对位置。 然后在箭头和右边的0px上以-42px的底部位置绝对。 箭头将始终位于右下方。 然后,您可以使用百分比作为宽度,气泡将是容器的大小。

HTML

        <div class="bubble">
               blablablabla
             <div class="arrow-left"></div>
        </div>      

CSS

.bubble{
    background-color:#156ac6; 
    padding: 15px 10px 10px 10px; 
    color: white;
    font-family:Georgia;

    position:relative;
    width:60%;
}
.arrow-left {
    position:absolute;
    bottom:-42px;
    right:0;
    border-left: 42px solid transparent;
    border-right: 0px solid transparent;
    border-top: 42px solid #156ac6;
    margin: 10px;
}

http://jsfiddle.net/ySn36/

使用它可能会有所帮助

.bubble {
    resize: none;
}
.arrow-left {
    resize: none;
}

尝试在您的高度和/或宽度使用百分比。 你也可以在顶部使用它们:

top: 10%;

暂无
暂无

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

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