Creating a unique aspect ratio for your div with CSS

This is my current design.

https://i.sstatic.net/VOexn.png

This is the layout I aim to achieve:
https://i.sstatic.net/hMy7C.png

1. The width and height of the outer container should maintain the specified aspect ratio.
2. The content area should also adhere to the same aspect ratio.

App.js (Bootstrap is being utilized, hence no separate CSS file at the moment)

      <div class="border p-3 m-2 bg-info" style={{ width: "400px" }}>
        <div class="p-2 bg-light">
          <div class="border p-1 border-warning" style={{ height: "100%" }}>
            <div
              class="card text-center d-flex flex-column justify-content-between bg-light border border-warning"
              style={{ height: "100%" }}
            >
              <div class="card-body" style={{ flexGrow: 2 }}></div>
              <div class="card-footer text-white p-4 border-top border-warning">
                <span class="bg-danger fs-3">123</span>
              </div>
            </div>
          </div>
        </div>
      </div>

CodeSandbox link:
https://codesandbox.io/s/condescending-monad-50lwd?file=/src/App.js

Answer №1

Take out p-4 from the

<div clas="card-footer">
, and include aspect-ratio: 16 / 9; in the .card-body class

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

Validating the body in Node.js for POST and PUT requests

When working in a production setting, what is considered the standard for POST / PUT body validation? I typically approach it like this: const isValid = (req.body.foo && /[a-z0-9]*/i.test(req.body.foo)) This method involves checking that the var ...

What is the most effective way to extract information from a .txt file and showcase a random line of it using HTML?

As a newbie in HTML, my knowledge is limited to finding a solution in C#. I am attempting to extract each line from a .txt file so that I can randomly display them when a button is clicked. Instead of using a typical submit button, I plan to create a custo ...

Bootstrap does not control the text family, weight, and line height

Currently, I am practicing adding grid layouts using Bootstrap. I have been trying to change the font styling within my project, but unfortunately, none of the changes seem to be taking effect. It's quite frustrating because even though I'm follo ...

The Vuex mutation does not execute synchronously and does not resolve as a promise

My vuex mutation doesn't work synchronously as expected. Here is the code: mutations: { computeStatusData(state, status) { if (status.active !== true) { return } const started = new Date(status.startedAt); started.setHour ...

Framework7 disables the jQuery.appear plugin

I am utilizing Framework7 and aiming to incorporate jQuery.appear for executing a script once an element becomes visible to the user. The implementation is successful when using this code in a basic HTML setup: <!DOCTYPE html> <html> < ...

Tips for optimizing the use of JS promises?

I'm encountering issues with implementing promises in JavaScript. There are 3 asynchronous functions that rely on each other: The functions are named func1, func2, and func3 respectively. func1 produces a single result that func2 requires. func2 a ...

What is the best method for utilizing a single L.Shapefile/zip file Object and modifying the onEachFeature function for each layer?

I am currently facing an issue where I have multiple tileLayers each containing a shape file. These tile layers represent different datasets based on variables and adjust colors accordingly. I have been able to achieve this by creating three separate Obje ...

A vertical line in Javascript extending upward from the base of an element

Is there a way to create a design where an infinite vertical line extends from the bottom of a circle (or in my case, a rectangle) without using css :after or pseudo-elements? I would like the line to be its own element and not limited by the restriction ...

Transitioning backgrounds in a slideshow

I am attempting to create a unique slideshow effect for my page background by changing the image URL at specific intervals with a smooth fade in and fade out transition. However, I am faced with the challenge of figuring out the best way to achieve this. ...

Identify regions with clickable functionality within an <img> element in an Ionic application

I have a static image with various buttons like Main, F1, F2, etc. within it that need to be made clickable in order to call an API. I am looking for suggestions on how to achieve this scenario. Any assistance would be greatly appreciated.https://i.sstat ...

Learn how to successfully place a draggable object into a sortable container while ensuring that the dropped item is a personalized helper element rather than the original object

The jQuery draggable/sortable demo showcases the process of dropping a clone of the draggable item (both draggable and sortable elements share the same structure). However, I am interested in dropping a different DOM structure. For example, when dragging a ...

Web page numerical data

Apologies if I'm repeating a question and I acknowledge that this is quite general. I am struggling to comprehend how to approach the following scenario: I aim to set a numerical value and enable the user to select checkboxes for different sides, wit ...

"Error: Tooltip z-index is not properly displayed and is hidden beneath

Currently, I am facing an issue with a tooltip displaying when hovering over navigation elements. The problem is that while the tool tip appears over the element being hovered on, it displays underneath all other elements as well. (To clarify, imagine a na ...

Having trouble deleting multiple rows with ng-repeat in datatables

Having followed the instructions in this post, I quickly integrated it with jquery datatables. However, the functionality is not as expected. When attempting to delete rows, they do not get deleted. Furthermore, if I navigate to the next page and return, ...

Tips for dynamically populating a dropdown menu in Laravel with Ajax and JQuery

Hey pals, I'm encountering an issue with Ajax. Everything seems to be running smoothly when the page initially loads. However, once I hit the add button to insert a new row for a second entry, things start to go haywire. The functionality is perfect u ...

Exploring and Troubleshooting HTML and JavaScript with Visual Studio Code Debugger

Visual Studio Code Version 1.10.2 Windows 10 I am currently experimenting with VS Code and would like to debug some basic HTML and JavaScript code. The instructional video found at http://code.visualstudio.com/docs/introvideos/debugging mentions that ...

Version 66 of Chrome on Mobile Browser now offers Autoplay functionality

My goal is to implement a feature where an image with a play icon is displayed, and when the user clicks on the icon, a video is loaded in an iframe within a popup window. Despite following the guidelines provided in this link, we are facing issues with ...

Steps to extract the data from a submitted HTML form and save it into a nested document within a Mongoose schema

Mongoose Schema for Contact Information: const addressSchema = new Schema({ street: { type: String, trim: true }, state: { type: String, trim: true , match: [/^[a-zA-Z]{2,}/, 'Please Enter State in a Correct Format']}, zip: {type: Nu ...

When navigating to a new route in VueJS with parameters, the browser displays the previously used

Scenario In my app, I am using vue.js 2.6 and vue-router 3.0. Within the app, there are links to detail pages set up like this: <div v-for="item in items"> <router-link :to="{name: 'details', params: {key: item.shortKey}}"> &l ...

The width specified for the table is not being applied

I've been struggling to adjust the width of my table in order to display data from a database. I've tried using inline width, !important tag, id, and class but none have worked. Interestingly, when I apply a fixed width without dynamic data, it w ...