我可以在画布中放置一个HTML按钮吗? [英] Can I put an HTML button inside the canvas?

查看:115
本文介绍了我可以在画布中放置一个HTML按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把我作为真正HTML按钮的游戏的按钮,但他们需要在画布内。

I want to make the buttons for the game I'm making as real HTML buttons, but they need to be inside the canvas.

我会如何去

推荐答案

由于 canvas元素具有透明内容模型,它可以包含在 canvas 元素不被支持的情况下显示的 fallback 元素。

Given that the canvas element has a transparent content model, it may contain fallback elements which are displayed in the event that the canvas element is unsupported. They will not be displayed if the canvas is supported.

您可以将HTML元素相对于画布的位置放置在 父级具有悬停在画布上的按钮。 菜单元素可以是用于呈现控件列表的适当语义元素,具体取决于上下文:

You can position HTML elements relative to the canvas' parent to have the buttons "hovering" over the canvas. A menu element could be an appropriately semantic element to render a list of controls, depending on the context:

<div id="container">
  <canvas id="viewport">
  </canvas>
  <menu id="controls">
  </menu>
</div>



CSS:

CSS:

#container
{
  height: 400px;
  position: relative;
  width: 400px;
}
#viewport
{
  height: 100%;
  width: 100%;
}
#controls
{
  bottom: 0;
  left: 0;
  position: absolute;
  width: 100%;
}

这篇关于我可以在画布中放置一个HTML按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆