如何在HTML5画布旁边放置div

时间:2019-10-12 12:54:25

标签: html css browser position styling

我正在尝试创建一个基于Web的绘画软件,并且想要定位一个按钮来更改画笔的颜色(我最终将其更改为条形)。我该如何将按钮定位在画布的右侧。

HTML和CSS:

#include <stdio.h>
#include <string.h>
#define INPUT_BUFFER_SIZE 256

int main(void) {
    // Reading user input
    char buf[INPUT_BUFFER_SIZE];
    fgets(buf, INPUT_BUFFER_SIZE, stdin);

    int words_to_skip = 3;
    char* current_pos = &buf[0];

    while (current_pos != 0 && *current_pos != 0 && words_to_skip > 0) {
        current_pos = strchr(current_pos, ' ');
        if(current_pos != 0) {
            current_pos++;
        }
        words_to_skip--;
    }
    if (current_pos == 0) {
        printf("Not enough words entered\n");
    } else {
        printf("%s\n", current_pos);
    }
}

1 个答案:

答案 0 :(得分:1)

<canvas>只是一个普通的块元素,因此可以放置它,但是将放置一个块元素。您可以在画布和按钮上应用float:left(请使用真实的<button>),可以display:inline-block,可以在它们周围添加包装纸,然后display: flex,甚至是display: grid或添加position: relative并将position: absolute添加到其子级。有很多方法可以实现这一目标。这是一个很好的起点:https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction