Even when the dimensions are set to 100 width and height, the scroll bar still makes an

I recently embarked on my journey to learn web development by enrolling in a course on Udemy. Currently, I am diving into CSS3/HTML5 and have started a small project involving CSS3 - creating a web page that represents the Universe. My goal is to incorporate an animation into this page. I've encountered an issue: I want the page to fill the entire width and height without any scrolling necessary. Initially, I set the background color of the page to black and then added a 616x616 PNG image featuring white dots representing stars. However, as soon as I inserted the stars onto the page, the full width/height disappeared and scrolling became active. Why is this happening? Below is my HTML code:

<html>
<head>
<title>Earth Planet Orbiting</title>
<link rel="stylesheet" type="text/css" href="normalize.css">
<link rel="stylesheet" type="text/css" href="style.css">
        <!--[if lt IE 9]>
<script src="bower_components/html5shiv/dist/html5shiv.js"></script>
<![endif]-->
</head>
<body id="universe">
    <div id="stars"></div>
    <div id="sun"></div>
    <div id="earth0rbit">
        <img src="images/earth.png" alt="Earth" width="130" height="125">
        <div id="moon0rbit">
            <div id="moon"></div>
        </div>
    </div>
</body>
</html>

This is my CSS code:

html, body {
height: 100%;
width: 100%;
}
#universe {
background: black;
background: -webkit-radial-gradient(#555, #000);
background: -moz-radial-gradient(#555, #000);
background: -o-radial-gradient(#555, #000);
background: radial-gradient(#555, #000);
}
#stars {
width: 100%;
height: 100%;
background-image: url('images/stars.png');

}

If I remove the lines with width and height from #stars, the scrolling feature is disabled but the star dots don't appear on the page. What can I do to fix this issue? Apologies for any language errors!

Answer №1

To start, adjust the margins of html and body to 0. By default, the margin is set at 8px, causing the body's total width to exceed 100% due to the additional 16px.

Next, in your current scenario, the #stars div has a height of 100%, but there is additional content following it totaling 125px. This results in the overall content height being more than 100%. To resolve this issue, decrease the height of #stars by 125px.

html, body {
height: 100%;
width: 100%;
margin:0; /* new */
}
#universe {
background: black;
background: -webkit-radial-gradient(#555, #000);
background: -moz-radial-gradient(#555, #000);
background: -o-radial-gradient(#555, #000);
background: radial-gradient(#555, #000);
}
#stars {
width: 100%;
height: calc(100% - 125px);
background-image: url('images/stars.png');

}
<html>
<head>
<title>Earth Planet Orbiting</title>
<link rel="stylesheet" type="text/css" href="normalize.css">
<link rel="stylesheet" type="text/css" href="style.css">
        <!--[if lt IE 9]>
<script src="bower_components/html5shiv/dist/html5shiv.js"></script>
<![endif]-->
</head>
<body id="universe">
    <div id="stars"></div>
    <div id="sun"></div>
    <div id="earth0rbit">
        <img src="images/earth.png" alt="Earth" width="130" height="125">
        <div id="moon0rbit">
            <div id="moon"></div>
        </div>
    </div>
</body>
</html>

Alternatively, you may have intended for the other divs to be nested within the #stars div. If so, make sure to move its closing tag accordingly.

Answer №2

To prevent scrolling, simply include the following CSS:

html,body{width:100%; height:100%;
overflow:hidden;}

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

"Utilizing jQuery to Trigger CSS3 Transform Animation Replays After a Set Number of Iterations

I currently have an animated image set up like this: <div class="image_for_sping"> <img src="/anyimage.png"> </div> The image has a style attribute added by jQuery which contains the following animation properties: animation: spin3 ...

I'm struggling to make my div display inline

My div elements are not displaying inline, I'm thinking maybe I shouldn't use the nav and div structure like this. But starting over again seems like a lot of work. How can I fix this issue? Just so you know, I'm only on my 4th day of learn ...

Incomplete Loading of Google Maps

Let me clarify that the solutions I have come across so far have not been successful. I am attempting to display a modal alert with a basic Google Maps integration. Problem: Google Maps does not load completely. Snippet from my .js file: var map; functi ...

How to customize the hover background color for multicolored series in Highcharts?

Highcharts offers a background color for all columns in a series. The hover color across themes is consistently a light blue (155, 200, 255, .2). To see an example, visit: http://jsfiddle.net/38pvL4cb/ If you look at the source code, Highcharts creates a ...

Ensure that the child div with a background color extends all the way to the bottom of its parent div

Having trouble getting two divs inside another one to stretch to the bottom without cutting off content? The goal is for both divs to adjust in height based on whichever one is longer, filling the outer div completely. When the left div (menu) is longer t ...

Using Jquery and CSS to display or conceal table elements depending on viewport width

I am seeking advice for my issue. Here is the code snippet on JSFiddle. I have a list of models and corresponding values that vary across different categories. I have created a simple table to display this data. However, I need to alter the table structur ...

The absence of image input was evident in the POST request

Within my Django template, I have an input field linked to a Django ImageField. Once rendered, the HTML code appears as follows: <form action="/accounts/username/" method="post" id="profile_form" enctype="multipart/form-data"> &l ...

React component rendering twice due to width awareness

In a React component that I've developed, I have utilized ResizeObserver to track its own width. Within this component, two divs are rendered with each having a "flex: 1" property to ensure equal width distribution. Under certain conditions, such as w ...

Utilizing conditional statements for confirming purchased orders with a pop-up confirmation box

function purchaseClicked() { var orders = prompt("Are you sure you want to buy these Items?"); if (orders != null) { alert('Please try selecting your items again!') } else { alert('Thank you for shopping ...

Show the HTML content fetched from the database using PHP

After pulling html source code from a database and storing it in a PHP variable, I noticed that the content consists of table rows structured like this: <tr><td>10:00 AM</td><td class="success">Available</td></tr> < ...

I am currently working on a one-page website that will feature both a Careers form and a Contact Us form. However, I am facing a challenge with the submission

I am currently working on integrating Careers FORM and Contact Us FORM into a single page website. However, I am facing an issue with the form Submit Buttons. The problem arises during validation of the input boxes. How can I differentiate between the two ...

Run a JavaScript code to show a hidden element

My latest project involves automating tasks on a website using Selenium. I encountered an issue where I cannot click on a hidden button defined this way: <body> <div class="smenu" id="smenu4"> <input tabIndex="-1" type="button" ...

What is the best way to include multiple ng-repeats within a single ng-repeat?

Hey, I'm facing quite a tricky situation with this grid and could use some assistance. I'm trying to figure out how to populate the data using ng-repeat. I've attached an image showcasing the desired layout of the grid and the order in which ...

How to access a particular tab in Bootstrap 5 using an external link

Is there a way to direct users to a specific tab upon clicking a link on another page? Check out the example below: <div class="products-btn"> <a href="products.html#pills-profile">view all</a> </div> On Pro ...

Prevent page refresh when submitting a form using PureCSS while still keeping form validation intact

I'm currently implementing PureCSS forms into my web application and facing a challenge with maintaining the stylish form validation while preventing the page from reloading. I discovered that I can prevent the page reload by using onsubmit="return f ...

Tips for incorporating line breaks into a contenteditable div using the key combination of ctrl + enter

$("#contenteditable").keydown(function(e) { var last = false; if (e.keyCode == 13) { if (e.ctrlKey) { let brNode = document.createElement('br'); let range = window.getSelection().getRangeAt(0); ...

Navigating to an offline HTML webpage using JavaScript in a PhoneGap application

I am currently developing a phonegap application. I am attempting to create a login feature where upon clicking the submit button on the Login.html page, I should be directed to a local HTML file. Login.html <tr> <td>&nbsp;</td> ...

Conceal elements that are overflowing slightly

I need help coming up with a purely CSS solution to hide div 3, which has extended beyond its container. Look at the picture linked below for reference. https://i.stack.imgur.com/isfvU.jpg ...

Update the display of the mouse pointer

I use CSS to set a custom cursor image: #scroll_up{ display: block; position: absolute; width: 960px; height: 300px; cursor: url(../imgs/cursor_up.png), auto; } The above style is assigned to a div element so that the cursor appea ...

Reiterating the text and determining the length of the string

Currently, the script is capable of calculating the width of the script based on user input and can also determine the width of a string. However, I am facing an issue when attempting to repeat a string entered by the user. For example, if the user input ...