Struggling with creating text that adapts to various screen sizes when displayed

As someone who is new to HTML/CSS, I recently developed my first website using the Cargo platform.

Within a section on my site featuring various videos, I encountered difficulty in properly positioning the titles over them while ensuring they remain responsive.

Upon viewing the website on wide monitors, I noticed that the titles appeared somewhat misaligned, and on mobile devices, they were completely out of place. Despite attempting to implement a grid layout, I was unable to achieve the desired result.

Below is an example of the messy HTML & CSS code I used for the videos and titles.

To gain a better understanding of my issue, you can visit the website at constantinesko.com/Sounds-1.

UPDATE: Thanks to the helpful response provided below, I have successfully wrapped my videos with their corresponding titles, ensuring responsiveness. However, I am now facing an issue where I am unable to align the titles to the left of each video. I attempted to use text-align:"left";, but it did not work as expected. Additionally, when trying to move the titles using left:50%; or transform: translate(-50%,-50%);, the responsiveness is compromised.

For instance, utilizing left:15%; results in:

27-inch monitor ()

Wide monitor ()

<div class="video-container">
  
     <div class="vcontainer">
       <video id="vid1" preload="auto" onloadstart="this.volume=0.9" onmouseover="this.play()" onmouseout="this.pause()" loop="loop" width="100%" height="240px" poster="https://freight.cargo.site/t/original/i/75971115b3c32e4fdff42672cceb851cec352ac0d47b9fa22e985591df3f80ec/Metron_01_Cropped_Thumpnail.png" class="">
           <source src="https://skovideos.s3.us-west-2.amazonaws.com/9+Sec+Metron+01+Cropped.mp4" type="video/mp4">
       </video>
       <div class="title">
           <a href="https://constantinesko.com/Metron-01%22%3E">
           <div class="linkbox"> METRON 01 </div></a>
       </div>
     </div>
.video-container {
     display: flex;
     flex-direction: column;
     justify-content: center;
    
   }
   .vcontainer {
     width: 100%;
     height: 240px;
     position: relative;
     margin-bottom: 2%;
       
   }
 
 .title {
     width: auto;
     height: auto;
     display: block;
     position: absolute;
     font-family: "Monument Grotesk Variable", Icons;
     font-size: 2vw;
     font-style: normal;
     font-weight: 400;
     font-variation-settings: 'slnt' 0, 'MONO' 0;
     animation-duration: 1.5s;
     animation-name: slidein;
     top: 50%;
     left: 50%;
     transform: translate(-50%,-50%);
     z-index: 3;
 }




#vid1{
    width: 100%;
    height: 240px;
    z-index: 2;
}

Answer №1

Resolve the issue for a single video. The container class is designated for a singular video along with its title. Introduce a main-container class to encompass all of your videos

    <div class="main-container">
     <div class="container">
       <video id="vid1" preload="auto" onloadstart="this.volume=0.9" onmouseover="this.play()" onmouseout="this.pause()" loop="loop" max-width="100%" height="718" poster="https://freight.cargo.site/t/original/i/92cc00ce1aa5295ba7248c875a72c8c25c5f4abf3ebcf0059648c1371855431b/Metron_01.png" class="">
           <source src="https://skovideos.s3.us-west-2.amazonaws.com/9+Sec+Metron+01.mp4" type="video/mp4">
       </video>
       <div class="title">
           <a href="https://constantinesko.com/Metron-01%22%3E">
           <div class="linkbox"> METRON 01 </div></a>
       </div>
     </div>
    </div>

<style>
   .main-container {
     display: flex;
     flex-direction: column;
     justify-content: center; 
   }
   .container {
     width: 400px;
     height: 200px;
     position: relative;
     margin: 50px;
   }
   video {
     width: 400px;
     height: 200px;
     position: absolute;
     top: 0;
     left: 0;
   }
 .title {
     width: auto;
     height: auto;
     display: block;
     position: absolute;
     top: 50%;
     left: 50%;
     transform: translate(-50%,-50%);
     z-index: 2;
 }
 </style>

Answer №2

Here is a demonstration of utilizing Flexbox to create a responsive layout. I have implemented a 100% width and adopted a mobile-first approach. By incorporating media queries, you can adjust the design for larger screens.

<html>
  <head>
    <style>
      .flex-container {
        display: flex;
        flex-direction: column;
        justify-content: center;
      }
      video {
        width: 100%;
      }
      .box {
        font-size: 2em;
        color: white;
        position: relative;
        margin: 2px 0 0 0;
        width: 100%;
        text-align: center;
        top: 40px;
      }
    </style>
  </head>
  <body>
    <div class="flex-container">
       <!-- Video content here -->
   </div>
  </body>
</html>

Update:

Consider trying out

Try 

.item > .box {
        font-size: 2em;
        color: red;
        align-items: flex-start;
        position: relative; left: 10%; top: 100px; text-shadow: 0 0 15px;
    }


    <div class="flex-container">
      <div class="item">
        <div class="box">test</div>
        <video id="vid1" preload="auto" onloadstart="this.volume=0.9" onmouseover="this.play()" onmouseout="this.pause()" loop="loop" poster="https://freight.cargo.site/t/original/i/92cc00ce1aa5295ba7248c875a72c8c25c5f4abf3ebcf0059648c1371855431b/Metron_01.png" class="">
           <source src="https://skovideos.s3.us-west-2.amazonaws.com/9+Sec+Metron+01+Cropped.mp4" type="video/mp4">
        </video>
      </div>
...

This adjustment ensures the text alignment on the left with a fixed percentage offset included.

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

`Modifying CSS in Bootstrap 4 for a personalized website design`

I am currently building a Bootstrap website for my sister, but I am facing issues with changing the CSS. Most of the time, the changes do not seem to take effect. I created a new file called "style.css" to override the Bootstrap styles and placed it below ...

Trouble with CSS navigation

Hello! In Dreamweaver, I have completed the design for my navigation bar. Here is how it looks: However, when I view it in Firefox, the navigation appears all jumbled up. It's quite frustrating... Below is the code that I'm using: #navbar { ...

How come my dimensions are not returning correctly when I use offset().top and scrollTop() inside a scrolling element?

Currently in the process of developing a web app at , I am looking to implement a feature that will fade elements in and out as they enter and leave the visible part of a scrolling parent element. Taking inspiration from myfunkyside's response on this ...

What is the best way to implement automatic color changing in PHP code?

I have a MySQL table called 'contact number' that contains the field 'c_n'. I need to display data from this field and change the color based on the length of the value. If the field's value is less or more than 11 digits, the colo ...

how to show an error in a modal window when encountering an error

Using Blazor and Blazorstrap, typically when the server disconnects, an "Error" message is displayed. However, with the BsModal from Blazorstrap, it appears in the background layer, making it unresponsive. How can this be fixed? Is it possible to close the ...

Tips for tackling drag and drop functionality with only HTML, CSS, and JavaScript

Currently, I am faced with a challenge involving drag and drop TEST. Observing the image provided below, you will notice 3 columns each containing 3 small boxes of varying colors. These boxes are draggable, meaning they can be moved between columns follow ...

Is there a way to execute Javascript in Django without revealing static files?

When setting up payments on my Django site using Stripe, I realized that the .js file is visible under Sources in the developer tools when inspecting elements on any browser. This presents a potential security risk as anyone can access this file. How can ...

What can be done to address the problem of background-image opacity making text difficult to read?

I am having an issue with the background. I am aiming for something similar to what is shown in screenshot 1, but instead, I am getting the result shown in screenshot 2. Where could the problem lie? html, body, .bg-for-1 { height: 100%; } .bg-for-1 ...

Browsing through dual snap points simultaneously on Google Chrome

I'm currently developing a website that incorporates scroll snapping for 3 viewport-sized <section> elements set up like so: html, body { scroll-behavior: smooth; scroll-snap-type: mandatory; scroll-snap-points-y: repeat(100vh); scrol ...

Tips for identifying HTML tags that include a specific attribute automatically

Is there a way to automatically identify an HTML tag that contains a specific attribute like data-wow-delay? This query revolves around wow.js. The goal is to have the classes wow bounce added automatically to any HTML tag that has this particular attribu ...

Obtaining the count of a specific column in Angular 6 by grouping objects based on the same value in an array

In TypeScript, I have an array of objects and I am using a foreach loop. The array contains 2 columns with a progress value of 100, while the rest have values less than 100. My goal is to calculate the count of columns with a progress value of 100, which ...

Include the window.innerWidth value in the initial GET request

When dealing with a server-side rendered app that has responsive styling based on window.innerWidth, the challenge lies in how to pass the client's screen size in the initial GET request for index.html. This is crucial so that the server can prepare a ...

Avoid flickering of images by properly handling the object URL when setting the image source in an asynchronous pipe

Implementing a JWT authorized endpoint for images has made it impossible to directly link to image urls in HTML. To work around this issue, we have created an async pipe that loads the image with proper authorization (handled by an HTTP interceptor, not s ...

Canvas with a button placed on top

I am working with a canvas and trying to position an HTML element over it using CSS. My goal is for the button to remain in place on the canvas even when resizing the entire page. Here is the code I am currently using. https://jsfiddle.net/z4fhrhLc/ #but ...

Concentrate on all elements within the form

I am in the process of developing a form with multiple input fields, one of which is shown below. I am interested in triggering an event using jQuery's focusout function. The form goes by the name: form_test <form id="form_test"> <input ...

Is it possible to make a div's width 100% until a certain point, and then change it to 30% beyond that breakpoint?

I am trying to work with a div element <body style="width: 100vw; height: 100vh"> <div id="containerDiv"> <div id="canvasDiv" /> </div> </body> My goal is to adjust the width of canvasDiv based on the screen size. ...

Using jQuery to locate a JavaScript variable is a common practice in web development

I recently created a JSFiddle with buttons. As part of my journey to learn jQuery, I have been converting old JavaScript fiddles into jQuery implementations. However, I seem to be facing a challenge when it comes to converting the way JavaScript fetches an ...

Applying a left margin has caused the right border to disappear

After adding a margin-left to the box, I noticed that my right border is missing. You can see the issue in this example. However, when I remove the margin-left property, everything looks fine as shown in this example. Is there any way to solve this proble ...

Appending an empty <li> tag has no effect

I'm facing an issue with this loop where it always generates empty <li></li> tags. Can anyone help me understand why this is happening and suggest a solution? For reference, the loop runs 2 times (verified). function a(){ for (var i ...

Explication of syntax not functioning

Following the instructions provided here but encountering issues, any assistance? <script type="text/javascript" src="sh/src/shCore.js"></script> <script type="text/javascript" src="sh/scripts/shBrushJScript.js"></script> <lin ...