Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames Croxford
12,723 PointsPlacing audio/video tags into a div which already contains an audio/video element won't show on page?
As per the title really. I'm just practicing this course again, and threw the code into a website I'm currently creating for a portfolio of work.
I've noticed that if I have a div, containing a audio/video element inside, that will appear as intended when I render the webpage. However, if I then throw one or more other audio or video tags inside that same div, then those players won't appear on the webpage.
So this seems to only show the first video:
<div class="video-audio-example-wrapper">
<h2>Video Example 1</h2>
<!--- Method 1 --->
<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" controls />
<!--- Controls attribute- Boolean, so by having the attribute there it means it is true and will display controls. Controls will be browser default. --->
<!--- can also use autoplay attribute --->
<h2>Video Example 2</h2>
<!--- Method 2 --->
<video controls>
<source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" />
<source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.ogg" type="video/ogg" />
</video>
<!--- allows for multiple sources of video for browser compatability by putting source into a seperate element inside of video element --->
<h2>Audio Example</h2>
<!--- Audio tag- like video tags, either a single tag representing the entire elements, or an open & closing tag with child elements underneath --->
<audio controls>
<source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge-audio.mp3" />
</audio>
</div>
But then here I can see both videos and the audio element?
<div class="video-audio-example-wrapper">
<h2>Video Example 1</h2>
<!--- Method 1 --->
<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" controls />
<!--- Controls attribute- Boolean, so by having the attribute there it means it is true and will display controls. Controls will be browser default. --->
<!--- can also use autoplay attribute --->
<h2>Video Example 2</h2>
</div>
<!--- Method 2 --->
<video controls>
<source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4" />
<source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.ogg" type="video/ogg" />
</video>
<!--- allows for multiple sources of video for browser compatability by putting source into a seperate element inside of video element --->
<h2>Audio Example</h2>
<!--- Audio tag- like video tags, either a single tag representing the entire elements, or an open & closing tag with child elements underneath --->
<audio controls>
<source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge-audio.mp3" />
</audio>
Is this a quirk of workspaces, or is there an underlying reason for this?
1 Answer
Ezra Siton
12,644 PointsWrong markup - missing closing tag for video element
You write:
<!--- Wrong - Method 1 --->
<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4"
type="video/mp4" controls />
correct
Missing closing tag </video>
(So you get "weird results" like not showing the next heading and video):
<!--- Correct Method 1 --->
<video src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4"
type="video/mp4" controls /></video>
For the future:
- Debug your HTML - https://teamtreehouse.com/library/debugging-css-with-chrome-devtools
- Validate your code: https://validator.w3.org/#validate_by_input
- https://www.w3schools.com/tags/tag_video.asp
Please mark as a solution to close this topic :)