Issue with Displaying Full-Page Div

My HTML page consists of just one div. The body code is as follows:

<div>
</div>

Here is the corresponding CSS:

body {
    margin:0;
    height:100vh;
    width:100vh;
}

    div {
    height:100vh;
    width:100vh;
    color:#000000;
}

I came across a similar example in a different stackoverflow thread, which can be found here.

After implementing this code, I realized that the div displayed correctly in terms of height, but only occupied slightly more than half of the width. I must have made a mistake somewhere.

Answer №1

For those seeking assistance, consider using height 100% instead of "Viewport Units" due to limited browser support. View the Browser Support Table for Viewport Units: http://caniuse.com/#search=vh

If you wish to extend the div into scrollable areas beyond the viewport, implement the following code:

html{
margin:0;
padding:0;
border:none;
height:100%;
}

body {
margin:0;
padding:0;
border:none;
height:100%;
}

#wrapper-div {
min-height:100%;
}

The key is to set height to 100% on html and body, and min-height 100% on the wrapper div. The div will naturally expand 100% horizontally. Min and max width and height are widely supported in browsers, except for IE6. (Note: For IE6 support, a simple hack can be added to the wrapper-div, though it may not validate your CSS{*display:inline; *zoom:1;})

Check Browser Support for Min and Max Height and Width http://caniuse.com/minmaxwh

Experiment with both 100% and Viewport Units using this JSFiddle:http://jsfiddle.net/TalkingRock/ZHC5h/


If you opt for Viewport Units, use this code with width set as vw, not vh:

body {
margin:0;
height:100vh;
width:100vw;
}

#wrapper-div {
height:100vh;
width:100vw;
background-color:#cccccc;
color:#000000;
}

Reference this article for more insights:

  • 1vw: 1% of viewport width
  • 1vh: 1% of viewport height
  • 1vmin: 1vw or 1vh, whichever is smaller
  • 1vmax: 1vw or 1vh, whichever is larger

Answer №2

When you set your background color to white, it may not appear. Consider using the color code #000 for black instead.

Answer №3

Although it may work, there is one thing to consider: the div is white, so how can you be sure it actually appears?

The best way to confirm its appearance is by changing the background color.

See a live example http://jsfiddle.net/Cr3f2/

body {
    margin:0;
    height:100vh;
    width:100vh;
}

    div {
    height:100vh;
    width:100vh;
    color:#FF0000;
    background-color:#FF0000;
}

Answer №4

Maybe consider adjusting the div attributes slightly, such as:

div {
height:inherit;
width: inherit;
color:#000000;

}

This way, the div will inherit the height and width values set in the body's CSS selector.

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

Is it feasible to transition a mobile webpage seamlessly without using jqm?

I'm currently developing a Phonegap app and I am trying to steer clear of jqm in my project. I find that the css is causing some issues with the html code. As a workaround, I can transition between pages using: window.location = "profiles.html"; How ...

The best way to organize and position a Label and TextBox in C#

I need help styling the aspx file. The Label and TextBox elements are not aligned properly. I want the Label and TextBox to be positioned side by side with appropriate spacing. <div class="col-md-12"> <p> ...

react elements are consistently positioned at the bottom of the webpage

I am currently in the process of developing an airline reservation system using the MERN stack. I have successfully implemented the navbar, however, whenever I try to add a new div or element, it appears outside of the page and requires additional styling ...

Adjust the FlipClock time based on the attribute value

When setting up multiple FlipClock objects on a page, I need to retrieve an attribute from the HTML element. The specific HTML tag for the clock is: <span class="expire-clock" data-expire="2015-09-22"> Is there a way to access '2015-09-22&apos ...

The animation unexpectedly resets to 0 just before it begins

Currently, I am developing a coverflow image slider with jQuery animate. However, there are two issues that I am facing. Firstly, when the animation runs for the first time, it starts at `0` instead of `-500`. Secondly, after reaching the end and looping b ...

Spin a sphere within a semicircle using html and css

I have been working on a project to animate a ball inside a crescent shape using HTML and CSS. You can check out my codepen here. However, I am facing an issue where the ball is currently stuck at the top of the crescent. I would greatly appreciate any as ...

Tips for displaying only one image when clicked and hiding other divs:

Currently tackling a project that involves JavaScript and I've hit a roadblock. Before you dive into the text, take a look at the image. Check out the picture here. I have successfully created a slider, but now I want to implement a feature where cli ...

Incorporating an HTML/Javascript game into a reactJS website: A step-by-step

After developing a game using plain javascript and HTML along with a few JS libraries, I find myself inquiring about the process of integrating this game into my ReactJS website. Typically, the game is initiated by opening the index.html file located with ...

Inject data from ajax into the body of the html document

Is it possible to retrieve values from an ajax call and insert them into the body of an HTML document? Here is an example: function check() { $.ajax({ url : '/check', datatype : 'json', async ...

Enable the text to wrap around an interactive object that the user can freely manipulate

Looking for a solution where I can have a floating div that can be moved up and down using javascript while the text wraps around it seamlessly. Similar to how an object positioned in a word document behaves, I want the text to flow around the div both ab ...

Discovering instances of a specific string within a larger string

My goal is to customize the default behavior of the alert function. Below is the code I am using: window.alert=function(txt) { waitOk='wait'; setMsgBox(txt); btnMsgOk.focus(); } However, I need this functionality to vary ba ...

Progress Bar Rating System in Bootstrap 4

Trying to achieve a specific layout using Bootstrap 4: https://i.sstatic.net/Ym6Ov.jpg Disregarding "See All" and "4,327 Ratings" Progress so far has led to: https://i.sstatic.net/hPSRn.png The numerical ratings can be replaced with font icons. Provi ...

Spread out elements equally into columns

I am facing a challenge with arranging items within a single div called .wrap. The goal is to place an unknown number of items (.thing) into four columns, stacked on top of each other. <div class="wrap"> <div class="thing"> thing1 </div ...

A method of submitting by simply pressing the enter key alongside clicking on a Bootstrap button

Here is the HTML code I am using to input prompts into a chatbot: <div class="input-group mb-3"> <input type="text" class="form-control" id="chat-input"> <div class="input-group-append ...

How can I incorporate a counter into my ng-repeat loop in Angular?

Do you know where I can find documentation on adding a numbered count to each item returned by an ng-repeat in Angular? This is not like assigning an Id, but more like, if 4 items are returned, each JSON object could include a number before the data. Her ...

tips for displaying a label and text side by side on a single line

Is there a way to keep my label and text on the same line by adjusting the CSS? I've tried using float based on suggestions from other posts, but they still end up on different lines. .indentColumn { width: 71px; padding-top: 5%; } .labelColumn ...

Is there a different option available in place of the JavaScript confirm function?

I developed an application where I heavily utilized the javascript confirm function. confirm("Do you want to proceed"); However, I am not satisfied with the default appearance of the confirm dialog and would like to implement a customized version with be ...

Issue with Ref when used in a distinct HTML template

I have encountered a frustrating issue with my simple Vue project. When I separate the template and code into individual files, the ref stops working and I end up with an undefined value in the HTML template. This scenario works fine: map.component.vue ...

Fixed position halting in a specific area

I have a fiddle where the black box is fixed on the page, but it overlaps the map when scrolling. I want to stop the black box from overlapping the map. How can I achieve this? CSS: .item{ background:#eee; padding:10px; width:50%; margin-bottom:15px;} .n ...

Is there a way to dynamically alter the heading color in Shopify liquid code?

After utilizing ChatGPT to review the code, I am uncertain if it is related to the color schemes. I am unsure of what I may be missing or doing incorrectly. While I can successfully alter the heading text, I am unable to change the color. Below is the code ...