Tips for incorporating video into my beginner website

I am currently setting up a grid layout for articles and videos on my homepage. I want to ensure that all the boxes are of equal dimensions, including the ones containing videos. However, I have some queries regarding the integration of YouTube videos on my website.

Question 0: I've heard that HTML5 supports video, but considering most of my videos are from YouTube and the rumored lack of support for HTML5 video, should I go for embedding YouTube videos instead?

Question 1: In the case of YouTube videos, how can I add them to my HTML and CSS code?

Question 2: How do I ensure that the video fits perfectly within my markup without being either too small or too large?

Question 3: Additionally, how can I provide users with access to the same video controls offered by YouTube such as fullscreen, play, etc.?

I would greatly appreciate any advice on optimizing my HTML and CSS structure.

Here's the HTML snippet for the grid layout featuring articles and videos:

     <div class="modules-container">

            <h3 id="on-god">On God</h3>

            <div class="row clear-fix">
                <section class="article-module">
                    <header>
                        <h4>
                            Article Name
                        </h4>
                    </header>
                    <blockquote cite="articles/name">
                        <p>
                            <em>My example quote will go here</em>
                        </p>
                    </blockquote>
                    <footer class="article-module-footer">
                        <a href="#">Read More</a>
                    </footer>
                </section><!-- end .article-module -->

                <section class="article-module middle">
                    <header>
                        <h4>
                            Article Name
                        </h4>
                    </header>
                    <blockquote cite="articles/name">
                        <p>
                            <em>My example quote will go here</em>
                        </p>
                    </blockquote>
                    <footer class="article-module-footer">
                        <a href="#">Read More</a>
                    </footer>
                </section><!-- end .article-module -->

                <section class="article-module">
                    <header>
                        <h4>
                            Article Name
                        </h4>
                    </header>
                    <blockquote cite="articles/name">
                        <p>
                            <em>My example quote will go here</em>
                        </p>
                    </blockquote>
                    <footer class="article-module-footer">
                        <a href="#">Read More</a>
                    </footer>
                </section><!-- end .article-module -->
            </div><!-- end .row -->



            <hr>

            <h3 id="videos">Videos</h3>

            <div class="row clear-fix">
                <section class="video-module">
                    <h4>
                        Name of video
                    </h4>
                    <p>
                        My embedded video will go here
                    </p>
                </section><!-- end .video-module -->
                <section class="video-module">
                    <h4>
                        Name of video
                    </h4>
                    <p>
                        My embedded video will go here
                    </p>
                </section><!-- end .video-module -->
                <section class="video-module">
                    <h4>
                        Name of video
                    </h4>
                    <p>
                        My embedded video will go here
                    </p>
                </section><!-- end .video-module -->

            </div><!-- end .moduels-container -->
        </div>

Below is the CSS I've worked on so far. Please note that I'm utilizing normalize.css in a separate file.

     /* 
Author: David Espejo
    */

     /* rem is base off of root font size */

   /* 
Padding and borders are
included in the width
of all elements
    */
    *, *:before, *:after {
        -moz-box-sizing: border-box;
         -webkit-box-sizing: border-box;
         box-sizing: border-box;
     }

    /* Small screens (default) */
     html { font-size: 100%; } /* root font size 16px */

    /* Medium screens (640px) */
    @media (min-width: 40rem) { 
      html { font-size: 112%; } /* root font size 17.92px */
    }

    /* Large screens (1024px) */
    @media (min-width: 64rem) { 
        html { font-size: 120%; } /* root font size 19.2px */
       .article-module, .video-module {
     float: left;
     width: 30%;
     padding: 0.3rem 0.5rem;
     }
      .article-module.middle, .video-module.middle { margin: 0 5%;  }
     }



    .container {
  margin: 0 auto;
  max-width: 48rem; /* not > (48 * 19.2 = 921.6px)! */
  width: 90%; /* when < 921.6px */
    }

    .row { border: 1px solid blue; }
    .article-module, .video-module { border: 1px solid red; }


    .clear-fix:after {
   content: " ";
   display: block;
   clear: left;
     }

Answer №1

Advice 0: To simplify video usage, consider embedding videos especially if you are primarily using YouTube videos. This eliminates concerns over video controls.

Advice 1: Copy the embed code from YouTube and paste it directly into your HTML wherever needed.

<iframe width="560" height="315" src="//www.youtube.com/embed/PKa6XdWat2s" frameborder="0" allowfullscreen></iframe>

In your scenario, place this iframe tag in the spot where you indicated "My embedded video will go here."

I recommend utilizing a div tag rather than a p tag to house the videos. Typically, the p tag is meant for text paragraphs.

Advice 2: Adjust the dimensions of the iframe tag within the stylesheet to ensure the video fits appropriately within your grid.

Consider implementing something like this:

.iframe {
  width:100%;
  height:100%;
}

This adjustment will make the video size match that of the containing div.

Advice 3: The video controls should already be present as mentioned previously.

fiddle link : http://jsfiddle.net/6vh2t/1/

Answer №2

Your coding skills are on point! Consider using the <article> tag instead of <section> for better structure.

To get the embed code for a video, simply click on share and then select embed. Youtube has shifted from using <object> to <iframe>.

<iframe width="560" height="315" src="//www.youtube.com/embed/9bZkp7q19f0" frameborder="0" allowfullscreen></iframe>

You have the flexibility to customize the width and height in pixels. Refer to the documentation for information on controls settings.

For more details, visit https://developers.google.com/youtube/player_parameters

Keep up the great work and best of luck with your project!

Answer №3

If you want to embed YouTube videos on your website, you can use an iframe code similar to this:

<iframe width="560" height="315" src="//www.youtube.com/embed/ajdfIUAsdYs" frameborder="0" allowfullscreen></iframe>

In the code, you can adjust the width and height of the embedded video by changing the values in the respective attributes.

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

Utilizing Angular 2 for Binding HTML Elements to a Fixed Length

I've been working on compiling a list of movies using Angular: <li *ngFor="let movie of movies"> <span class="badge">{{movie.title}}</span> {{movie.year}} </li> While some movies look great, others don't. How can I ...

Toggle the hamburger menu using JavaScript

How can I close my hamburger menu when clicking a link for one page navigation? The menu is functioning properly, but I need a way to close it. Unfortunately, I have limited knowledge of JS. I only have the HTML and CSS for this: HTML in index.html file ...

Restart the AJAX form submission process to enable the sending of updated information

Looking for a popup form to use on your website? The issue is that after the form is submitted once, it doesn't show again to send different information. The only solution seems to be reloading the page, but that's not ideal. Check out this tuto ...

What is the reason for Materialize CSS forms not being contained within boxes?

Is there a way to achieve a form similar to the one in Bootstrap 4 but using Materialize CSS? The current implementation only displays an underline for the input field, rather than a full containing box. <input placeholder="Placeholder" id="first ...

Continuous Div Carousel with Looping in jQuery

I have developed a basic carousel to cycle through a series of divs, but I am facing some issues. I want the carousel to loop continuously so that after reaching "slide 07," it goes back to "slide 01." Unlike using a carousel plugin, I prefer having an ove ...

Utilizing JQuery/Ajax to retrieve information from a php file

My challenge lies in populating a table with 3 different headings, as it is currently empty. I aim to retrieve individual data from a PHP script using jquery.get method and insert each row into the table. I am struggling as the button click event returns ...

Turning off HTML buttons using an associative array in PHP

I have initialized an associative array using some variables and now want to display the data in this array inside an HTML table. Everything is working fine, except for a small issue - if the user enters a NULL value for $aid, the HTML control below remain ...

What is the best method for removing all HTML tags except the <p> tag when pasting

Having a bit of trouble with my inline text editor. Users are able to copy and paste onto the textarea div, which is fine. However, I don't want them pasting HTML content with images or div elements. I've tried using valid_elements: "p,br,b,i, ...

What steps should be taken when encountering the "Cannot Get" error message on a webpage?

Currently, I am in the process of creating an HTML file within xcode with the intention of displaying its contents in the browser. With an empty file as my starting point, the following code was added: <html> <head> <title>HTML is S ...

What is the best way to pass parameters in an HTML script?

I am struggling to submit parameters to a website using an html code in order to execute an XSRF attack. In the following html, I have defined parameters for the action involving an account number, routing number, action, and a value that requires reverse- ...

I am interested in learning how to retrieve the page URL in order to trigger the opening of a menu in my sidenav bar

This is my navigation bar. I am trying to use JavaScript or jQuery to retrieve the current page's URL and open the corresponding dropdown container. I want to display the relevant section of the side navigation based on the URL. I have tried writing t ...

Is there a way to give a unique color to a single <a> element with a specific class, differentiating it from the

Apologies if my title is not precise enough. Describing this in just a few words for the title was a bit challenging. Context I am personalizing a template on wordpress.com. The website in question is: I have enclosed the DONATE menu item in a gold-col ...

Receiving HTTP POST data using Classic ASP script

I'm currently working on a project and have come across an area where I am facing some challenges. Despite my best efforts, I haven't been able to find a solution using Google. In my ASP web application, I've added an HTML canvas that I nee ...

What is the procedure for utilizing Javascript to redirect a user on a website back to the login page if necessary?

Is there a way to redirect a website user back to the login page if they try to access a secure page without logging in first? I'm looking to implement this using JavaScript and cookies. Any suggestions or ideas on how to achieve this seamlessly for t ...

Using JavaScript, create a function that accepts an HTML element as a parameter

I have a script with two functions. One function generates a lengthy HTML string, and the other function processes this string as a parameter. function myFirstFunction() { // Generate HTML content return myHTML; } var myHTML = myFirstFunction(); ...

What's the reason for switching from a custom tab icon to a React icon?

I've encountered a strange issue while working on my app - the tab icon keeps changing from the one I've set to the ReactJS icon whenever I navigate between different routes. I have linked the icon correctly in my HTML file, so I'm not sure ...

Is there a way to make my red div switch its background color from red to green when I press the swap button?

How can I make the red div change its background color to toggle between red and green when I click on the swap button in the following code? $(document).ready(onReady); var numberOfClicks = 0; function onReady() { console.log('inside on ready ...

Fluid 3-panel layout with CSS for optimal spacing between content sections

I've been having great success with my 3-panel liquid layout, but recently I encountered an issue. It seems that when a div is floated to the left and another div below it has a clear:both property, all subsequent divs are being pushed down to the he ...

Transform page appearance using CSS exclusively, without altering DOM structure

I have a structure that must remain unchanged for various reasons. Here is the current layout: <h1>heading</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLore ...

Having trouble with element.scrollTo not functioning properly on mobile devices?

I have been working on creating a vertical scrolling carousel, and so far everything seems to be functioning well. I can scroll horizontally using buttons and swipe gestures successfully on the simulator. However, when I view the website on a real mobile d ...