Guide to generating a consistent 16:9 preview of a different html page

I'm currently developing a simple webpage editor that allows users to create "slides" for later display elsewhere.

For this purpose, I have designed the following layout:

The left section serves as a preview while the right section functions as the editor where users can adjust paragraph properties. Both sections are styled as follows:

float: left;
height: 100%;
width: 50%;
padding: 2%;

My objective is to ensure that the preview maintains a consistent aspect ratio of 16:9 for accurate representation.

Below is my current code structure:

<div class="leftItem">
    <div class="leftArrow"></div>
    <div class="preview">
        <!-- Text content to be edited goes here -->
    </div>
    <div class="rightArrow"></div>
</div>
.leftItem {
    height: 95%;
    width: 50%;
    float: left;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview {
    display: block;
    width: 90%;
    height: 40vh;
    border-style: solid;
    border-width: 1px;
    -webkit-box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.2);
    -moz-box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.2);
    box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.2);
}

Answer №1

To achieve this effect, you can set a padding bottom for a nested box within the main container that you are resizing. Then, you will need to add content inside a separate child element and position it absolutely, as the resized box may shift all other contents. The crucial part of the code is:

.preview:after {

  display: block;
  content: '';
  padding-bottom: calc(100% / 16 * 9);
  width: 100%;

}

Here's how it appears in practice:

.preview:after {
  display: block;
  content: '';
  padding-bottom: calc(100% / 16 * 9);
  width: 100%;
}
.preview .content {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.leftItem {
  height: 95%;
  width: 50%;
  float: left;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview {
  position: relative;
  display: block;
  width: 90%;
  border-style: solid;
  border-width: 1px;
  -webkit-box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.2);
  -moz-box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.2);
  box-shadow: 2px 2px 5px 1px rgba(0,0,0,0.2);
}
<div class="leftItem">
    <div class="leftArrow"></div>
    <div class="preview">
        <div class="content">
        <!-- Text goes here -->
        </div>
    </div>
    <div class="rightArrow"></div>
</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

Troubleshooting media queries on an example webpage

Hey there! So, I'm having a bit of trouble with running media queries on a simple HTML page. It's been a while since I worked on this stuff, and I feel like I must be doing something silly that I can't quite pinpoint. If you want to take a ...

I am looking to adjust/modulate my x-axis labels in c3 js

(I'm specifically using c3.js, but I also added d3.js tags) I have been working on creating a graph that displays data for each month based on user clicks. However, I am facing an issue where the x-axis labels show 0-X instead of 1-X. For instance, ...

What is the process for deactivating touch gesture recognition in a particular view within an IONIC3 application?

I am looking to prevent all touch gestures on certain views within my app. Users should only be able to interact with the app using an external keyboard while in these views. I have reviewed the Ionic Docs but couldn't find clear instructions, I onl ...

A versatile tool for creating customizable components on the fly

I am looking to create a function within my service that generates dynamic components into a ViewChild reference... I attempted to do this by: public GenerateDynamicComponent(ComponentName: string, viewContainerRef: ViewContainerRef, data?: any) { sw ...

Facing issues with integrating json data into html through svelte components

Just starting out with svelte and taking on a project for my internship. I have my local json file and I'm struggling to integrate it into my HTML. I've been scouring the internet but haven't found a solution yet. This is what I've tr ...

EventEmitter is failing to refresh the properties bound with [(ngModel)]

I am currently working with the forms module and Google Maps to update the geocode based on the search box provided on the map. The map is a separate component that emits the Geocode using the function geoCodeChange(). This event is handled by another func ...

Developing a single source code that can be used across various platforms such as desktop, Android, and

Having a background in C++ and some knowledge of HTML, CSS, and JavaScript, I am currently working on developing a web application using Node.js and React.js. This application will be accessible through both web browsers and mobile devices. My goal is to ...

Selenium's XPath locator unable to locate element despite being visible on the browser

Attempting to extract the WHO coronavirus data from the left sidebar of this website: using Xpath. Here is the code snippet: from selenium import webdriver import time driver = webdriver.Firefox() driver.get("link_to_the_page") time.sleep(30) coun ...

Tips on preventing duplicate data from being extracted from an HTML source with HtmlAgilityPack

In my project, I am utilizing HtmlAgilityPack to scrape data from an HTML Code source. Let me show you an example of the HTML structure: <div class="enum-container"> <div class="enum"> <span class="field-key">MD5</span> ...

Retrieving Color Values from Stylesheet in TypeScript within an Angular 2 Application

Utilizing Angular2 and Angular Material for theming, my theme scss file contains: $primary: mat-palette($mat-teal-custom, 500, 400, 900); $accent: mat-palette($mat-grey4, 500, 200, 600); There is also an alternate theme later on in the file. Within one ...

What could be causing the javascript styling to malfunction when using Ractive.js?

When the button is clicked in this fiddle, it seems that in addition to other lines, the following code is also being executed: document.getElementById("WeatherData").style.visibility = "block"; weatherDataDiv.style.visibility='block'; However, ...

What steps should I take to address this issue using IONIC and TypeScript?

Running into an issue with my TypeScript code for an Ionic project. I'm attempting to pass the value of the variable (this.currentroom) from the getCurrentRoom() function to another function (getUser()) but it's not working. Here's my chat s ...

Is there a way to contain the text within a div and have the div expand downwards if the text is too large?

Is there a way to ensure that text stays inside a div even if it exceeds the width, with the div's height expanding to fit the entire text? UPDATE: Thank you all for your help so far. Should I use 'Inherit' or 'min-height'? A ba ...

Supported video formats in various web browsers

Are there detailed records of video codec compatibility across various desktop and mobile web browsers? ...

Ways to eliminate unused classes from JQuery UI

We have successfully implemented JQuery UI library for enhancing our interface. However, since we no longer need to support outdated browsers like IE6, classes such as .ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl are unnecessary and clu ...

How to Modify CSS in Angular 6 for Another Element in ngFor Loop Using Renderer2

I have utilized ngFor to add columns to a table. When a user clicks on a <td>, it triggers a Dialog box to open and return certain values. Using Renderer2, I change the background-color of the selected <td>. Now, based on these returned values, ...

What is the best way to incorporate external HTML content while ensuring HTML5 compatibility? Exploring the different approaches of using PHP, HTML

While this may seem like a simple task to the experts out there, I have been struggling for over an hour without success... My objective is to use a single footer file and menu file for all my webpages while considering blocking, speed, and other factors. ...

gather and handle data from the shared interface between different parts

I have two different paths. One is for products and the other is for products-cart. I want to use a shared ts file for both to store the product and cart information in an array. However, I am encountering an issue. I am unable to make any changes or trans ...

Utilize a custom Angular2 validator to gain entry to a specific service

For accessing my custom http service from within a static method, consider the following example: import {Control} from 'angular2/common'; import {HttpService} from './http.service'; class UsernameValidator { static usernameExist( ...

An intriguing inquiry regarding HTML form intricacies

Looking to enhance the source code by adding a new column to display Client Mobile, Client Office Telephone, and Client E-mail in a separate popup PHP page. My attempt involved adding a form and submit button to generate the new column. However, pressing ...