Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a child div inside a video element, not showing

Tags:

html

css

My goal is to have text over each video element (there are many of them). The video is showing, but the div inside it does not.

<video autoplay playsinline style="transform: rotate(0deg); width: 100%; height: 100%; position: relative">
  <div style="width: 100px; height: 30px; color: white; z-index: 1; position: absolute; top: 0px; left: 0px; background: green;">test</div>
</video>

In the element inspector, when I hover over the div, it does not show a box anywhere on the page. How to make it show up?

like image 744
PhoenixB Avatar asked Feb 20 '18 17:02

PhoenixB


People also ask

Can you put a div inside a video tag?

Video elements cannot contain elements inside, unless the video tag is not supported. This is common practice to display an error message explaining the browser doesn't support video .

Can you add div inside section?

Yes you can use a div inside a section . we use section when we want separate elements (this same category or similar). First tag inside section should be header (h). Example: one page in newspaper is a section, article is article and on a top this side we have header.

How do you add content to a video in HTML?

HTML allows playing video in the web browser by using <video> tag. To embed the video in the webpage, we use src element for mentioning the file address and width and height attributes are used to define its size. Example: In this example, we are using <video> tag to add video into the web page.

What is adding video element?

<video>: The Video Embed element. The <video> HTML element embeds a media player which supports video playback into the document. You can use <video> for audio content as well, but the <audio> element may provide a more appropriate user experience.


1 Answers

Video elements cannot contain elements inside, unless the video tag is not supported. This is common practice to display an error message explaining the browser doesn't support video.

Place your video inside an element (like a div) and add that div next to it, as a sibling to the video element and not a child. Use position to place it inside:

<div style="position: relative;">
  <video autoplay playsinline style="transform: rotate(0deg); width: 100%; height: 100%; position: relative"></video>
  <div style="width: 100px; height: 30px; color: white; z-index: 1; position: absolute; top: 0px; left: 0px; background: green;">test</div>
</div>

Make sure you post your full code to ensure we can help you properly.

like image 132
chriskirknielsen Avatar answered Oct 06 '22 16:10

chriskirknielsen