css - HTML Canvas 在右下角对齐 DIV

标签 css position css-position

我有一个 Canvas,想在相对于 Canvas 的右下角添加一个 Div/Button。我当前的代码如下所示:

#container {
    margin-top: 5px;
    width: 96%;
    margin: auto;
    background-color: blue;
    height: 300px;
}

#viewer {
    width: 40%;
    background-color: red;
    height: 100%;
}

#button {
    height: 40px;
    width: 40px;
    background-color: green;
    position: absolute;
    bottom: 0;
    right: 0;
}

canvas {
    border: 3px solid black; 
    width: 100%;
    height: 100%;
}
<div id="container">
    <div id="viewer">
        <canvas></canvas>
        <div id="button" onclick="myFunction();"></div>
    </div>
</div>

但到目前为止,我无法为此找到合适的解决方案。如果有人可以帮助我,那就太好了。

最佳答案

这是你要找的吗?
我建议您查看这篇文章:CSS Layout - The position Property

#container{
    margin-top: 5px;
    width: 96%;
    margin: auto;
    background-color: blue;
    height: 300px;
}

#viewer{
    width: 40%;
    background-color: red;
    height: 100%;
    position:relative;
}

#button{
    height: 40px;
    width: 40px;
    background-color: green;
    position: absolute;
    bottom: 0;
    right: 0;
}

canvas{
    border: 3px solid black; 
    width: 100%;
    height: 100%;
}
<div id="container">
    <div id="viewer">
       <canvas></canvas>
       <div id="button" onclick="myFunction();"></div>
    </div>
</div>

关于css - HTML Canvas 在右下角对齐 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55581529/

相关文章:

javascript - jQuery UI 对话框标题区域被拉长

javascript - 如何在悬停时将类添加到不同的元素?

jquery - 使用jQuery拖放后如何获取坐标位置?

css - 当最后一个图像或 div 从浏览器顶部到达指定点时如何锁定或修复滚动?

html - 绝对定位到 div 底部的文本需要向下而不是向上增长/扩展

html - 使用 css-transforms 为遇到定位问题的所有浏览器创建掩码

asp.net - 如何在 ASP.NET 中不使用 runat=server 的情况下从代码后面将 value/css 设置为 ASP 按钮?

html - DIV 随机移动

html - 如何在 HTML 和 CSS 中将文本定位在图像上方

javascript - 动画 div 使 Edge/Safari 重绘/布局父容器