What are some ways to use CSS to customize the appearance of a "D-PAD" controller?

Example of a completed DPAD

body {
    background-color: black; 
    margin: 0;
    padding: 0;
    overflow: hidden; 
}
div#controller {
    display: none; 
}
div#instructions {
    font-size: 20px;
    color: white; 
    position: static;
    text-align: center; 
}

@media only screen and (max-width: 480px) {
    div#instructions {
        display: none; 
    }
    div#controller { 
        display: flex; 
        position: relative;
        background-color: grey;
        opacity: 0.6;
        height: 33%;
        width: 80%;
    }
    div#controller.dpad {
        width: 60%; 
    }    
}

@media only screen and (max-width: 768px) {
    div#instructions {
        display: none; 
    }
    div#controller {
        display: flex;
        position: relative;
        top: 300px;  
        background-color: grey; 
        opacity: 0.6; 
        height: 50%;
        width: 80%;
    }
    div#controller.dpad {
        width: 33%;
    } 
}
<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
        
        <!-- The CSS is missing! Your mission is to re-create it -->
        <link rel="stylesheet" href="env3d.css" />
        
        <script src="http://css.operatoroverload.com/exercise/bundle.js"></script>
        <script src="http://css.operatoroverload.com/exercise/game.js"></script>        
        
        <script type="text/javascript">         

         function playGame() {
             console.log("playGame");
             var game = new Game();

             game.setup();
             
             var env;
             if (game.env) {
                 env = game.env;
             } else {
                 env = new env3d.Env();
             }
            
             env.loop = game.loop.bind(game);             
             env.start();
         }
         
         window.addEventListener('load', function() {
            playGame();
         });
         
         document.addEventListener("contextmenu", function(e) {
             e.preventDefault();
         });         
         
        </script>
         
    </head>
    <body>
        <div id="controller">
            <div class="dpad">
                <button env3d-key="KEY_UP">UP</button>
                <button env3d-key="KEY_LEFT">LEFT</button>
                <button env3d-key="KEY_RIGHT">RIGHT</button>
                <button env3d-key="KEY_DOWN">DOWN</button>
            </div>
            <button env3d-key="KEY_A">A</button>
            <button env3d-key="KEY_Z">Z</button>            
        </div>
        <div id="instructions">Use arrow keys to change camera angle, A to zoom in, Z to zoom out.</div>
        <div id="env3d"></div>        
    </body>
    
</html>

I am currently working on a small project that requires coding mobile controllers using CSS. However, I am facing difficulties in styling it to resemble the provided image.

If anyone could offer guidance or point me in the right direction, it would be greatly appreciated!

Thank you for your assistance! :)

Answer №1

Hey there, fellow web development classmate! 😄👍

If you're struggling with any part of the assignment, feel free to ask for assistance.

To start off, make sure to adjust the size and position of the #controller and .dpad divs towards the bottom of the screen. Utilize the position, width, and height attributes for this task.

Next, arrange the buttons within their respective container divs by employing the position, width, and height properties. You can target individual buttons using selectors like element>element, attribute=value, or :nth-child(), as detailed in this resource.

If needed, refer to this guide on vertically centering an element by specifying

position: relative (or absolute);
, top: 50%;, and transform: translateY(-50%);. For horizontal alignment, use
position: relative (or absolute);
, left: 50%;, and transform: translateX(-50%);.

I hope these instructions prove helpful to you!

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

Visual representation has a numerical equivalent in HTML code

How can I insert an image into my HTML code? <input id="sendButton" type="button" value=<img src="sendbutton.jpg"> /> I attempted to do this, but the website only displays it as text "img src/>" when ...

Issues with IE6 hover state not properly resetting

Tutorial This particular issue has been isolated in the test case provided above. It is easily noticeable when viewed in IE6. Description of the Issue In Internet Explorer 6, when hovering over the link, all child elements that are supposed to be visibl ...

Tips for automatically scrolling to the bottom of a page and focusing on an iframe

My website features a large banner image with content followed by an embedded YouTube video within an iframe. While the webpage is responsive, on mobile devices the header appears too big and users have to scroll down to see the video. I want the webpage ...

Tips for eliminating the PHP form redirection issue

Having trouble with data insertion in MySQL and getting redirected to the PHP file after. Not ideal! Any suggestions on how I can display error or success messages within the same HTML file? index.html <form id="form" action="add_article.php" method=" ...

Centered at the bottom of the screen lies a Bootstrap button

As a beginner with bootstrap, I am currently exploring new concepts and experimenting with different features. One thing I am attempting is to center a bootstrap button at the bottom of the screen. Here is my current code: .bottom-center { position: a ...

Troubleshooting Bootstrap dropdown functionality: Tips for resolving the issue

I have reviewed other similar queries, but none of them seem to provide a solution. I am utilizing Django, and below is my code snippet. index.html {% extends 'base.html' %} {% block body %} <nav> <div class="logo" ...

How can I slow down or postpone file_get_contents PHP to fetch a fully loaded page for scraping?

I am currently utilizing the file_get_contents function along with regular expressions to extract data from a specific website. In order to scrape all pages ranging from 1 to 2000, I have implemented this function within a "for" loop. The website that I ...

Spin Card Animation Malfunction

I've been working on creating a rotating card animation, but I've run into a glitch that's causing the front side to be visible through the back. This issue seems to occur when using position: absolute elements inside one of the sides. While ...

No matter how many times I click the next button, I am unable to proceed to the next page

Trying to create a form for an insurance company using basic HTML, CSS & JQuery. However, encountering an issue where I cannot proceed past the first page after clicking the Next button, and therefore unable to view the remaining 2 fieldsets. Can someone h ...

Saving form data in AngularJS between route transitions

Currently immersed in AngularJS, one question nags at me: how can I retain data in an HTML form while navigating between routes using AngularJS route provider? Has anyone encountered this issue before and found a solution they could share with examples or ...

aligning a form next to an image side by side

I found this amazing design https://i.sstatic.net/dtO9h.jpg So I decided to implement it with the following code .page-account-box { width: 100%; margin-top: 70px; } .page-account-box .ds-userlogin .account-box { width: 100%; height: auto; p ...

Placing the video at the center of the background image

                    Can someone assist me with a design issue I'm facing? I have two divs within a section. The left div contains a heading and a button, while the right div contains a video. However, when I try to add a background image to ...

The JsFiddle code is malfunctioning

One question I have is about preparing a JSFiddle for a small click program which is not working. It consists of just two lines of code. HTML <body> <button onclick="javascript:launchdialog();">Click Me</button> </body> JavaS ...

What strategies can be implemented to improve the load time for bigvideo.js?

Why are my load times extremely slow for such a small site? I had hoped to display an image before the video loads, but they both seem to load simultaneously, even if the video takes forever to load. This is my HTML: <div id="bigvid"> <div cla ...

Utilizing Skeleton to create a cropped text button on an iPhone

I am currently using Skeleton for my simple CSS needs. While it works fine on desktop, I have noticed that on an iPhone, the text in my button gets cropped as shown in the picture. https://i.stack.imgur.com/EYo2P.png Below is the HTML code I'm using ...

How do I modify the sidebar width with CSS code?

I am trying to adjust the width of the right sidebar on my website. The current layout leaves too much empty space on the right side and makes it appear crowded next to the main content and images in the center. Despite exploring various solutions provide ...

Is there a way to align my two <div> elements together?

I am looking to align "Login" and "Register" with the height of the top, as shown in the example below for better clarity. https://i.sstatic.net/OArTq.png Here is how I want it: https://i.sstatic.net/MeI83.png Although I use Bootstrap 4, I prefer to ac ...

Using PHP to handle JSON responses

I am currently working on a project that involves retrieving JSON responses using PHP. My goal is to obtain a JSON array without any HTML tags mixed in, but unfortunately, the output includes unwanted HTML tags. I need assistance in figuring out how to r ...

Fade-In and Fade-Out CSS Effect with Background Images Displaying a Blank Last Image

I've been experimenting with applying a CSS-only background image transition to a div, but I encountered an issue where after cycling through three specified images, the background reverts back to the original black color. Even stranger, when I adjust ...

Choose does not showcase the updated value

My form contains a form control for currency selection Each currency object has the properties {id: string; symbol: string}; Upon initialization, the currency select component loops through an array of currencies; After meeting a specific condition, I need ...