Is it possible for webkit CSS resize to not function properly when applied to a canvas element that is

Consider this HTML and CSS code snippet:

#box {
  width: 100px;
  height: 100px;
  overflow: hidden;
  resize: both;
  border: 1px solid black;
}
#content {
  width: 100%;
  height: 100%;
}
<div id="box">
  <canvas id="content"></canvas>
</div>

When using the canvas element inside the box, I expected it to be resizable in Firefox, although it isn't in webkit-based browsers like Chrome and Opera. However, replacing the canvas with a div makes it work across all browsers. So my question is: why does using a canvas element prevent the outer div from being resizable in this scenario? And what are possible workarounds?

Answer №1

Upon analysis, it appears that the canvas element is capturing the mouse events, thus obstructing the resizing functionality. A simple solution to this issue would be to add pointer-events:none to the canvas:

#outer {
  width: 100px;
  height: 100px;
  overflow: hidden;
  resize: both;
  border: 1px solid black;
}
#inner {
  width: 100%;
  height: 100%;
  pointer-events:none
}
<div id="outer">
  <canvas id="inner"></canvas>
</div>

To further demonstrate, try reducing the canvas size slightly to avoid overlapping with the resize widget and notice that the resizing will function correctly:

#outer {
  width: 100px;
  height: 100px;
  overflow: hidden;
  resize: both;
  border: 1px solid black;
}
#inner {
  width: 100%;
  height: calc(100% - 10px);
  background:red;
}
<div id="outer">
  <canvas id="inner"></canvas>
</div>

You can also manipulate the z-index property as an alternative approach:

#outer {
  width: 100px;
  height: 100px;
  overflow: hidden;
  resize: both;
  border: 1px solid black;
  position:relative;
  z-index:0; /* mandatory to create a stacking context and keep the canvas inside */
}
#inner {
  width: 100%;
  height: 100%;
  position:relative;
  z-index:-1;
  background:red;
}
<div id="outer">
  <canvas id="inner"></canvas>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the discrepancy in sizes of the columns in my multi-column layout?

https://jsfiddle.net/drqjmssy/ Seeking assistance from the linked jsfiddle, I aim to align "div class='main_content'" vertically with "div class='sidebar'". What would be the best approach to achieve this alignment? In case the fiddle ...

Showing JSON information fetched from an AJAX request within an HTML page

I've been working on a project and I'm almost there with everything figured out. My main challenge now is to display an array of items on a web page after making an ajax call. Below is the code snippet I currently have: JQuery Code: var su ...

What are the steps to recreate the layout of my image using HTML?

What's the best way to create a layout in HTML that expands to fit the entire screen? ...

Click on the nearest Details element to reveal its content

Is there a way to create a button that can open the nearest details element (located above the button) without relying on an ID? I've experimented with different versions of the code below and scoured through various discussions, but I haven't be ...

Adding content to a text field and then moving to the next line

I am looking to add a string to a text area, followed by a new line. After conducting some research, here are the methods I have attempted so far but without success: function appendString(str){ document.getElementById('output').value += st ...

Scroll horizontally in a div with a minimum width while it is contained within a column using Bootstrap

I am seeking to create a bootstrap v4 grid with 3 columns, where certain content within the columns require a minimum width. This necessitates a horizontal scroll (overflow-x), but I am encountering some overlap where the scrollbar and content extend beyon ...

The unequal division of space between two flexed child divs is caused by varying image sizes

In my parent container, I have set the display property to flex. Inside, there are two divs with both having flex:1 set. However, the first child div contains an image and takes up twice as much space as the second div. If the screen is 1000px in height, ...

HTML5 for Bulk Video Upload

Is it possible to use the html5 api to record and upload video content directly from the browser? I am facing an issue in a project where the video recordings can be very long or large, causing extended upload times for users. Ideally, I would like the vi ...

How can the entire menu be closed in Bootstrap 5 when clicking on a link or outside of the page?

I'm currently utilizing BootStrap 5 for constructing my webpage. Within my page, I have a NavBar Menu containing various links. <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__ ...

The collapsed form-control is adjusting its attributes while resizing

Having trouble with a website design featuring a collapsed window and menu items, but the search bar is not displaying correctly? In image 3, you can see that the style of the search bar changes when the width exceeds a certain limit. I've tried vario ...

Create a variety of colors with a simple click

A form has been created for the footer where clicking on an input causes the text and border-bottom to transition from grey to white. Visit Code Pen HTML: <div class="footer"> <div class="footerContainer"> <form> <inp ...

Guide on submitting a get form and retrieving the information

Currently, I am employed as a penetration tester for a company. While conducting an analysis of their website, I discovered a vulnerability where CSRF tokens are generated via a GET request to the page localhost/csrf-token and then provided in plaintext fo ...

Choosing the type attribute of an input tag by using a javascript variable as a condition: What's the best approach?

I am currently utilizing an input tag on the client side to receive text input. <input type="text" class="form-control" placeholder="Enter Message" id="messageText" autofocus/> My goal now is to dynamically set the type attribute based on a Javasc ...

Dragend event for images does not trigger in webkit when using TinyMCE

When using the TinyMCE editor, I tried binding the dragend event on images with the following code: _imagePlugin.editor.dom.bind(_imagePlugin.editor.dom.select('img'), 'dragend', function(){console.log('aaaa');}); Oddly enou ...

As I continue to fill the child DIV element with more text, the shrink wrap is compromised and eventually breaks

Snippet of HTML code: <div id="container"> <div id="first"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lacinia velit ut magna ultricies. </div> <div id="second"> Blandit </div ...

What is the method for altering the text color within a disabled input field?

Currently facing difficulty in changing the color of the text within the input field when it's disabled. I'm utilizing Material UI for this purpose. import React from "react"; import { makeStyles } from "@material-ui/core/st ...

Enable AJAX to dynamically load pages without caching

I am currently using an ajax function to refresh a specific division on a webpage with HTML content. <script> $('#scene_container').load('scene.html', function () { cache: false }); </script> ...

Having trouble getting the Facebook Like Box to function properly

I am having trouble displaying the like box on my website. I followed the code provided at https://developers.facebook.com/docs/plugins/like-box-for-pages and even tried using the HTML5 version, but nothing appears on the page. This is the code I used: & ...

What will occur if I use an XMLHttpRequest to request a file that is currently being downloaded?

My goal is to enhance links in a progressive manner using the PJAX style. My plan was to layer this on top of some regular prefetch <link>s: <link rel="prefetch" href="next.html"/> If the browser has already downloaded next.html, then the PJA ...

Setting limits to disable or remove specific times from the time picker input box in Angular

I'm having trouble with a time input box. <input type="time" min="09:00" max="18:00" \> Even though I have set the min and max attributes to values of 09:00 and 18:00 respectively, it doesn't seem to be working properly. I want to ...