fixed width div with width proportion

experts.

I'm currently experimenting with a spinning cube effect for my gallery and I recently came across Paul Hayes' experimental cube on his website (it's best viewed in Google Chrome). However, I am facing a challenge in getting it to work smoothly on mobile devices where it automatically adjusts to fit the page width. The front face of the cube needs to precisely match the browser width to maintain the perspective during the transformation process.

The main issue I've encountered is how to achieve this responsive design for the cube on different devices. I've tried various methods such as setting the outer div's width/height to 100%, adjusting offsets to percentages, and exploring transformation points with -webkit-perspective-origin, but haven't found a perfect solution yet.

After numerous attempts and hours of troubleshooting, I attempted to build the cube from scratch, scaling it to 100% and incorporating rotations around its y-axis. However, challenges arose with applying transformations using percentage values, particularly when trying to position images further back on the z-axis.

So, the question remains: Is it feasible to make the entire front face of the cube adapt to the full width of the browser, effectively scaling the content regardless of its size? And if so, how can this be accomplished?

Here is the key portion of the code I have been working with:

img {
    min-width:100%;
    min-height:100%;
}

.viewport {
    -webkit-perspective: 800;
    -webkit-perspective-origin: 50% 100px;
    min-height: 100%;
    min-width: 100%;
    position:relative;
}

.cube {
    position: relative;
    margin: auto auto;
    height: 300px;
    width: 300px;
    -webkit-transition: -webkit-transform 50ms linear;
    -webkit-transform-style: preserve-3d;
}

.cube h2 {
    color: #fff;
    padding-top: 0;
    margin-top: 0;
}

.cube a {
    color: #fff;
}

.cube > div {
    position: absolute;
    height: 100%;
    width: 100%;
}

.cube > div:first-child  {
    -webkit-transform: rotateX(90deg) translateZ(150px);
}

Answer №1

Consider adding the following code snippet to the head section of your webpage:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

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

Ways to replace CSS classes created using makeStyles

To clarify, my development environment is using MUI version 4.12.3. Inside file A, I have a simplified code snippet for a functional component, along with the usage of makeStyles to style a JSX element within the return statement (not displayed here). Ever ...

Is there a way to dynamically assign the background color of a webpage based on the exact width and height of the user's screen?

I have customized the CSS of my website by setting the height to 800px and width to 1050px. Additionally, I have chosen a blue background-color for the body tag. It is important that the entire application adheres to these dimensions. However, when viewe ...

Button with Circular Design by Tailwind

Is there a way to place a circle inside a button with text positioned to the right of it without overlapping in a centered manner? Take a look at this playground HERE <button class="btn btn-change"> <span class="w-5 h-5 bg-red-5 ...

"Encountering an Ajax error 419 when using radio buttons and a form

I'm attempting to use AJAX to send radio button values to a Laravel route when a button is clicked, but I keep receiving error code 419 even though I am sending the CSRF token. $(document).ready(function(){ $("#valor").on('click' ...

Add a CSS class to the text that is selected within a Content Editable div

Hey there, I'm having an issue where the class is being applied to the button when pressed instead of the selected text. Here's my current code: The button needs to be a div, but it might be causing the problem. I just want the highlighted text ...

"Enhanced interactivity: Hover effects and selection states on an image map

Hello there, I need assistance with my code. Here it is: <img id="body_image" usemap="#body_map" src="assets/images/body.jpg" alt=""> <map name="body_map"> <area shape="poly" alt="d" href="#body_chart" name="ad" coords="153, 153, 145, 1 ...

Unique ideas for organizing the layout and loading of content on my website

Last year, I created a fan site dedicated to a popular PC game, but now I feel like it could use some improvements. Currently, all the pages on my site share a common header and footer, with only the main content area changing from page to page. My curren ...

The :before pseudo element doesn't seem to be functioning properly on Internet Explorer 11

The following code works well in Chrome and Mozilla, but unfortunately does not function correctly in IE11. I am attempting to apply a background color on hover to a div with the class .border-green, however this functionality is failing specifically in ...

adjusting three sections within a flexible navigation bar

Having difficulties creating a dynamic navbar that changes on scroll and keeping the elements within the nav fixed when the menu options appear. For reference, you can check out this codepen: http://codepen.io/timothyfernandez/pen/azXQPV Any assistance w ...

Is it possible for an SVG to derive its dimensions from the containing element?

I am currently in the process of transitioning a Vue/Vuetify application from using web fonts for Material Design Icons to utilizing SVG icons instead. With the web font, an example of a heading that includes an icon looks like this: <template> &l ...

Prevent the Icon in Material UI from simultaneously changing

I'm working on a table where clicking one icon changes all icons in the list to a different icon. However, I want to prevent them from changing simultaneously. Any suggestions on how to tackle this issue? Code: import React from 'react'; im ...

The site is visually appealing in Firefox, but has a few issues on Chrome

I've encountered a common issue where my website displays perfectly in Firefox but looks terrible in Dreamweaver and Chrome. To fix it, I made live CSS edits in Firefox then copied them to Dreamweaver resulting in a mess. Here's how it should lo ...

What's the reason for not being able to customize classes for a disabled element in Material-UI?

Currently, I am utilizing Material-UI to style my components. However, I am facing challenges when trying to customize the label class for disabled buttons. Despite setting a reference as "&$disabled", it does not yield the desired results. import Rea ...

automatically collapse a submenu once a different menu option is selected

After doing some research and trying out various solutions, I still couldn't get it to work. I made adjustments to my dropdown menu and click function so that each submenu opens and closes when its parent is clicked. However, I'm now looking to f ...

Dragging and dropping elements onto the screen is causing them to overlap when trying

I am having trouble merging the drag and drop functionality from Angular Material with resizing in a table. Currently, both features are conflicting and overlapping each other. What I am hoping for is to automatically cancel resizing once drag and drop s ...

Inconsistent functionality of HTML5 BrightCove videos on Android devices

Encountered an issue with the Brightcove HTML5 video embedded on my website showing a black screen when clicked to play. The video plays sporadically and only on Android Devices (testing on KitKat only). In instances where it doesn't work, the templa ...

Associating data with controller upon click event

My application displays a tab full of objects for the user to choose from by clicking on any line. Once they make their selection, I need to send specific data related to that object to the server. This is what the interface looks like: The tab is create ...

modify the appearance of HTML controls in real time with C#

Is there a way to dynamically add an additional navigation item to my website's menu list when the admin logs in through admin.aspx? The menu list is created using HTML controls such as <ul>...<li>, and I would like the new navigation item ...

Restricting zooming to only occur within the img element in a UI

Is there a method to enable image zoom inside specific divs without affecting the overall page zoom? At the moment, I have: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale ...

What is the best way to center-align the label of a TextField in React Material-UI horizontally?

I'm trying to center-align the label in this TextField: import React from "react"; import { withStyles } from "@material-ui/core/styles"; import TextField from "@material-ui/core/TextField"; export ...