Moving a blank block to the top using CSS transformation

After trying to implement the translate3d(150px,0px,0px); on my "content" div, I encountered an issue where an empty block appears at the top of the page. Unfortunately, I am unsure about how to resolve this issue.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <style>
        html, body {
            margin: 0;
            height: 100%;
        }
        #side-panel {
            color: white;
            width: 150px;
            height: 100%;
            background: #1BA39C;
            position: absolute;
            top: 0;
            left: 0;
            transition: all .2s ease-out;
        }
        ul {
            list-style: none;
            margin: 0;  
            padding: 0;
        }
        li {
            margin: 0px;
            padding: 10px;
        }
        li:hover {
            background-color: red;
        }
        #nav-bar {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 40px;
            background: black;

        }
        .hide {
            transform: translate3d(-150px,0,0);
        }
        .bodyhide {
            transform: translate3d(0,0,0);
        }
        .show {
            transform: translate3d(0,0,0);
        }
        .bodyshow {
            transform: translate3d(150px,0px,0px);
        }
        #content {
            transition: all .2s ease-out;
        }
        #subcontent {
            position: relative;
            top: 50px;
        }
    </style>


    <div id="side-panel" class="hide">
        <ul>
            <li>
                <a href='#'>Uno</a>
            </li>
            <li>
                <a href='#'>Dos</a>
            </li>
            <li>
                <a href='#'>Three</a>
            </li>
            <li>
                <a href='#'>Cuatro</a>
            </li>
            <li>
                <a href='#'>Cinco</a>
            </li>
        </ul>
    </div>

    <div id='content'>
        <div id='nav-bar'>
            <button id="panel-button">Panel</button>
        </div>
        <div id='subcontent'>
            <p>Content</p>
        </div>
    </div>


    <script type='text/javascript'>
        var panel = document.getElementById("side-panel");
        var button = document.getElementById("panel-button");
        var myContent = document.getElementById("content");

        panel.onclick = function () {
            panel.className = "hide";
            myContent.className = "bodyhide";
        };
        button.onclick = function () {
            panel.className = "show";
            myContent.className = "bodyshow";
        };
    </script>
</body>

If you want to see a live version of this code, visit this link: http://codepen.io/sbaglieri/pen/LERQXy

Answer №1

The space is not caused by the translation, but rather by the use of position: fixed on the #nav-bar.

A potential solution could be to include overflow: hidden in the styles for #content.

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

Scripting in jQuery to create dropdown menus

I've encountered a unique issue on my website where a user's selection from one list should update the values in another list: <form id="form1"> <div> <select id="workField"> <option value ...

The footer is not being properly pushed down by the DIV

I created a page and utilized toggle with jQuery. The layout of my page is great, but when clicking on the button to reveal content, the div remains fixed and my content expands and hides behind the footer. Take a look at the image here: https://i.stack.i ...

Steer clear of using absolute positioning in Material-UI and React for better styling and layout

Is there a way to achieve the same layout without using position: absolute for the "Hello There" button? I want to remove that CSS property while keeping the design intact. Any better suggestions? Feel free to check out my codesandbox: CODESANDBOX -----&g ...

Tips for limiting the size of image uploads to under 2 megabytes

I am trying to implement an html select feature that allows users to upload images. <div class="row smallMargin"> <div class="col-sm-6"> Attach Image </div> <div class="col-sm-6"> <input type="file" ng-model="image" accept=" ...

How can we integrate this icon/font plugin in CSS/JavaScript?

Check out the live demonstration on Jsfiddle http://jsfiddle.net/hc046u9u/ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materializ ...

Using absolute positioning for child elements within a table cell division in CSS

Similar Question: Is it possible to position items relatively or absolutely within a display: table-cell? I am working with a display: table layout example. You can view the demo here. In the second panel, there is a #pos div that has a position: abs ...

Reduce whitespace when resizing

Is there a way to adjust the content to fill in the margin space when the browser is resized smaller? http://jsfiddle.net/denWG/62/ Html: <div class="jp-sleek jp-jplayer jp-audio"> <div class="jp-gui"> <div class="jp-controls jp-ico ...

Using Jquery to implement autocomplete functionality by iterating over each item with the .each

I have been attempting to implement autocomplete using the .each() function. I am referring to the documentation on http://jqueryui.com/autocomplete/. You can view my attempt in this FIDDLE link where it is currently not functioning as expected. The scen ...

What causes the list to shift instead of the image when the vertical-align property of the image is unchecked?

How come when the vertical-align property on this image is unchecked, it affects the list rather than the image itself? Checked: https://i.sstatic.net/NQhf0.jpg Unchecked: https://i.sstatic.net/jS7er.png ...

What is the best way to retrieve classes from arrays and apply styling to them using javascript?

Imagine having 3 unique classes: alpha, beta, and gamma. Each class contains 3 individual div elements like so: <div class="alpha"></div> <div class="alpha"></div> <div class="alpha"></div> <div class="beta">< ...

Deleting the HTML element

Can someone assist me with my script issue? I am facing a problem: when I open my file on fullscreen (over 768px), and move my pointer around the logo div, nothing happens. However, if I resize my browser to below 768px, then back again above 768px, the ...

Custom property fallback values do not function properly with CSS Variables

I defined a custom property in the :root selector as shown below, but for some reason my color is not rendering correctly. Can someone please help me identify what I am doing wrong? :root { --color-primary: var(--color-primary, #ffc107); } body { ...

CSS - Issues with transition smoothness on Safari

I am facing an issue with a simple font-size transition in Safari, causing stuttering while it works smoothly in Chrome and Firefox. I'm not sure if this is a Safari problem, a Webkit issue, or something else entirely. Any workaround suggestions would ...

How to Customize Password Input Fields in HTML

My input field is set to password type, allowing only a six-digit number: <fieldset> <label for="password-input">Enter New Pin</label> <input type="password" name="password" id="password-input" inputmode="numeric" minlength="6" ...

Instructions for making a crossword-inspired grid using a high quantity of divs or alternative elements

I am looking to create a grid on the screen of a web browser or mobile device, with each grid item containing just one letter. It's similar to a crossword puzzle, but taking up most of the screen. I've tried using divs for this purpose, but it se ...

Ways to create a sequential appearance of elements through CSS animations

Can you help me achieve a wave effect for elements appearing one by one using CSS animation (jQuery)? Currently, all the elements show up at once and I want to create a wave-like motion. Any assistance would be greatly appreciated. $(window ...

Arrange various numbers in a single row to be in line with

I'm utilizing bootstrap in an attempt to design the layout depicted below: https://i.sstatic.net/0w06U.png Here is a simplified version of my code: .curr { font-size: 12px; font-weight: 700; letter-spacing: .5px; } .price { -webkit-tap-h ...

Tips for setting a specific height for an HTML table

For some reason, I can't seem to control the height of this table. I've set it to a maximum of 20px but all the rows are still showing. Here is the CSS: table { border:1px solid black; overflow:hidden; height:20px; max-height:20 ...

Navigation through dots on a single page

Having an issue with my dot navigation and anchor links placement. I want the anchors to be vertically centered in the middle of the section, regardless of window size. Here's what I'm aiming for : For larger windows : https://i.sstatic.net/pK4 ...

Ways to showcase every resource from an API in React JS

I need help with adding code to display products along with their images from an API in my existing code. Can someone assist me with this? import React, {useState, useEffect} from 'react' import "bootstrap/dist/css/bootstrap.min.css" im ...