html - 当浏览器窗口大小改变时,div 绑定(bind)到其他 div

标签 html css

我有以下问题: enter image description here

无论浏览器窗口大小如何,对话泡泡都应始终指向眼睛。

JSFiddle here

到目前为止,我有以下代码:

<div class="container1">
    <div class="container2">
         <button class="eye"></button>
         <div class="speech-bubble">View</div>
    </div>
</div>

在哪里

.container1 {
    text-align: center;
    display: -webkit-box;
    display: -webkit-flex;
    width: 100%; }

.container1 > .container2 {
    -webkit-box-flex: 1;
    -webkit-flex: 1;}

.speech-bubble {
    position: absolute;}

但这不起作用并产生上述输出。 我该怎么做才能让它发挥作用?请不要使用 jQuery 解决方案,因为我使用的是 Angular。

编辑:如果省略text-align: center,代码将达到预期的效果。但不完全是:我想让按钮居中!而且还有上面提到的效果!我该怎么做?

最佳答案

设法做到了,没有太多的技巧。 将 .container2 更改为

.container1 > .container2 {
    margin: 0 auto;
}

参见 this fiddle .

关于html - 当浏览器窗口大小改变时,div 绑定(bind)到其他 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30018286/

相关文章:

html - 垂直居中而不使用表格单元格且高度未知

javascript - jQuery 在当前行的 div 上添加行号作为类

html - 在不影响圆环图的情况下放大饼图

python - 将提取代码添加到 beautifulsoup 循环

css - 使用 ANTLR 解析 CSS - 边缘情况

html - 我在 bootstrap 中使用 select 标签,我使用 css 来改变选择框的背景

jquery - 如何使用 jquery 将 jquery ui 选项卡的位置与另一个 ui 选项卡交换?

javascript - Canva的编辑器使用了哪些技术

html - 为什么向 div 添加文本会改变边距

javascript - Secret 键盘上的隐藏信息 enter