Building a DIV Element in the Space Between a Header and Footer Using HTML and CSS

I'm attempting to get my DIV element (MainPageImage) to cover the entire screen area, situated between the header and the footer.

Here's my HTML code:

body {
  padding: 0;
  margin: 0;
  overflow-y: scroll;
  font-family: Aerial;
  font-size: 18px;
}
#nav {
  background-color: #222;
  Height: 50px;
}
#nav_wrapper {
  width: 960px;
  margin: 0 auto;
  text-align: left;
}
#nav ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
  position: relative;
  text-align: center;
}
#nav ul li {
  display: inline-block;
}
#nav ul li:hover {
  background-color: #333;
}
#nav ul li a,
visited {
  color: #F00;
  display: block;
  padding: 15px;
  text-decoration: none;
}
#nav ul a:hover {
  color: #C03;
  text-decoration: none;
}
#nav ul li:hover ul {
  display: block;
}
#nav ul ul {
  display: none;
  position: absolute;
  background: #333;
  border: 5px solid #222;
  border-top: 0;
  margin-left: -5px;
}
#nav ul ul li {
  display: block;
}
#nav ul ul li a,
visited {
  color: #F00;
}
#nav ul ul li a:hover {
  color: #099;
}
footer {
  position: fixed;
  bottom: 0;
  background-color: #333;
  border: 5px solid grey;
  color: #F00;
  font-size: 24px;
  text-align: center;
  width: 100%;
  Height: 40px;
  padding-top: 15px;
}
    <div id="nav">
        <div id="nav_wrapper">
            <ul>
                <li><a href="#">Home</a>
                </li>
                <li><a href="#">About us</a>
                </li>
                <li><a href="#">Games</a>
                </li>
                <li><a href="#">Social</a>
                    <ul>
                        <li><a href="#">Youtube</a>
                        </li>
                        <li><a href="#">Facebook</a>
                        </li>
                        <li><a href="#">Twitter</a>
                        </li>
                    </ul>
                    <li><a href="#">Contact me</a>
                        <ul>
                            <li><a href="#">Email</a>
                            </li>
                            <li><a href="#">Form</a>
                            </li>

                        </ul>
                    </li>
                    <li><a href="#">Bugs</a>
                    </li>
                </li>

            </ul>
        </div>
    </div>
    
    <div id="MainPageImage">
    <img src="http://i.imgur.com/MHHu946.jpg" style="width:100%; height:auto;" >
    </div>
 <footer>
<p>Copyright @DcoltGaming 2016</p>
</footer>   
</body>
</html>

I've experimented with setting the height to auto, but I haven't had any luck with other solutions I've come across.

If anyone can offer a solution to this issue, I would greatly appreciate it.

Thank you, DcoltGaming

Answer №1

relocate the image from the HTML code to the CSS section under the body selector and include background-size: cover; as shown below

background: url("http://i.imgur.com/MHHu946.jpg") no-repeat center center fixed; 
 -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;

provided here is a snippet

@charset "utf-8";
/* CSS Document */

body{
    padding: 0;
    margin: 0;
    overflow-y: scroll;
    font-family: Aerial;
    font-size : 18px;
     background: url("http://i.imgur.com/MHHu946.jpg") no-repeat center center fixed; 
 -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

#nav{
    background-color: #222;
    Height:50px;
}
#nav_wrapper{
    width: 960px;
    margin: 0 auto;
    text-align: left;
}

#nav ul{
    list-style-type: none;
    padding:0;
    margin: 0;
    position:relative;
    text-align:center;
}

#nav ul li{
    display: inline-block;
}

#nav ul li:hover{
    background-color: #333;
}

#nav ul li a,visited{
    color: #F00;
    display:block;
    padding: 15px;
    text-decoration:none;
}

# nav ul a:hover{
color: #C03;
text-decoration: none;
}

#nav ul li:hover ul{
    display:block;
}
#nav ul ul{
    display: none;
    position: absolute;
    background:#333;
    border: 5px solid #222;
    border-top: 0;
    margin-left: -5px;
}

#nav ul ul li{
    display: block;
}

#nav ul ul li a,visited{
    color: #F00;
}

#nav ul ul li a:hover{
    color:#099;
}


footer{
    position:fixed; bottom:0;
    background-color:#333;
    border:5px solid grey;
    color:#F00;
    font-size:24px;
    text-align:center;
    width:100%;
    Height:40px;
    padding-top: 15px;
}
<body>
    <div id="nav">
        <div id="nav_wrapper">
            <ul>
                <li><a href="#">Home</a>
                </li>
                <li><a href="#">About us</a>
                </li>
                <li><a href="#">Games</a>
                </li>
                <li><a href="#">Social</a>
                    <ul>
                        <li><a href="#">Youtube</a>
                        </li>
                        <li><a href="#">Facebook</a>
                        </li>
                        <li><a href="#">Twitter</a>
                        </li>
                    </ul>
                    <li><a href="#">Contact me</a>
                        <ul>
                            <li><a href="#">Email</a>
                            </li>
                            <li><a href="#">Form</a>
                            </li>

                        </ul>
                    </li>
                    <li><a href="#">Bugs</a>
                    </li>
                </li>

            </ul>
        </div>
    </div>

    <div id="MainPageImage">
    </div>

</body>

<footer> 
<p>Copyright @DcoltGaming 2016</p>
</footer>

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

"Angular 6: A Guide to Customizing Text Colors Based on Status

I have a view on angular just like this: https://i.sstatic.net/JimWN.png And this is my dashboard.component.ts: export class DashboardComponent implements OnInit { tablePresetColumns; tablePresetData; ngOnInit() { this.tablePresetColumns = [{id: ...

"Customize your Vuetify v-card with uniquely styled rounded corners on only

I am seeking to create a unique v-card design where only two corners are rounded. Despite my attempts, the card ended up rotated by 90° and didn't achieve the desired outcome. DESIGN ATTEMPT: <div class="text-center rotate-ninety ml-n6" ...

IFrame transparency setting not recognized

I am encountering an issue with transparency when adding an iframe to a webpage. I have set the allowTransparency attribute of the iFrame to true, but upon inspecting the element using Internet Explorer's F12 Developer Tools, I noticed that although t ...

How can an accordion icon be added and list toggling be accomplished when HTML data is sourced from an API instead of a JSON response?

I have an API that sends HTML data as a response. The task at hand is to add accordion icons to the items in the list and enable list toggling using HTML, CSS, JavaScript, React, and MaterialUI. Unfortunately, I am limited in my options and cannot use JQ ...

What is the best way to incorporate a third-party element into Vue using a script tag?

I am in the process of developing a website and I would like to include a widget that links to a podcast on BuzzSprout. Initially, I created the site using HTML to test out different designs, but now I am looking to transition it to VueJS. In my HTML vers ...

Achieving a transparent background color for a div without affecting the content with CSS

I am attempting to design a div element with a basic background color and some text displayed on it. I would like to lower the opacity of the background color in this div, but every time I try, the opacity of the text also changes. Is there a way to adjust ...

What is the best way to capture a form submission when there are no errors?

My form includes a validation check for valid fields upon submission. Here is an example of how it is structured: <form class="form-horizontal" method="post" action="#" name="basic_validate" id="basic_validate" /> <div class="con ...

Issues with style not loading properly within innerHTML in Angular2

Currently, I am in the process of developing a page using Angular2/4 that includes a left navigation bar. To achieve reusability, I have separated this left menu into its own component and nested it within the main component. The objective is to utilize th ...

Implementing a CSS codepen within a React Material-UI component

I'm struggling to implement this effect on my material ui card component using react and makeStyles. I am having difficulty translating this effect to the cards, could someone assist me in simplifying it into a CSS code that can be used in MakeStyles? ...

What is the best way to make the child Div float to the bottom of the parent Div?

Screenshot I attempted various CSS techniques in an effort to make the .booknetic_appointment_container_footer float to the bottom of #booknetic_theme_5, but unfortunately, I was unsuccessful. The closest solution I found involved hardcoding padding, but ...

What is causing the error message "Error: Cannot update active font: 'Fira Sans' is not included in the font list" in react-font-picker?

For my project, I have implemented a font picker component in the following manner: <FontPicker apiKey={process.env.REACT_APP_GOOGLE_API_KEY} activeFontFamily={activeFontFamilyMobile} ...

Can variables in JavaScript clash with input names in HTML?

I have the following code in an HTML file: <input type="..." name="myInput1" /> Then, in a JS file associated with this HTML file, I declare a variable to store the value of that input after it loses focus: var myInput1; Should I be concerned abo ...

What is the best way to apply a CSS class to a ComponentRef that has been generated in Angular 5

I am attempting to dynamically add a CSS class to a component right after its creation by utilizing ViewContainerRef and ComponentFactoryResolver. My goal is to determine the class based on which other Components have already been added to myViewContainerR ...

Numerous HTML documents being uploaded to the server for a multitude of individuals

Currently, I am developing a game on a website where players create new rooms and are assigned specific roles with individual powers. Some players need to wait for input from others, creating a dynamic gameplay experience. Additionally, there are certain ...

Ensure that the remaining space on the page is filled by utilizing 2 divs

I am currently in the process of developing a website that needs to be responsive on all pages. The layout consists of 5 divs positioned horizontally. The three middle divs have fixed sizes - 200px, 400px, and 200px respectively. However, I am facing a cha ...

It is not possible to submit a form within a Modal using React Semantic UI

I am working on creating a modal for submitting a form using React semantic UI. However, I am encountering an issue with the submit button not functioning correctly and the answers not being submitted to Google Form even though I have included action={GO ...

Repositioning the images to a new location

I've been having trouble moving the small images (thumbnails) on my page. They seem to be stuck in place on the left and I've tried adjusting their margins using a div id, but it hasn't had any effect. Below are the relevant code snippets: ...

Do not open iframe links in a new window

Is it possible to manipulate the iframe so that links open inside the iframe window? I want the links clicked within the iframe to stay within the same window instead of opening in a new one. However, I have too many links to individually edit their code ...

Achieving Vertical Centering of Text in Bootstrap 5 Buttons with Flex Box to Prevent Overlapping Icons

How can I prevent the text on a Bootstrap 5 button with horizontally and vertically centered text, along with a right aligned icon, from overlapping when it wraps? Additionally, how do I ensure that the icon stays vertically centered when the button text w ...

I would like to know how to create a dropdown menu that shows the country name, flag, and code based on the

I have successfully generated the telephone input field. One requirement is to display the Country flag along with the country name as soon as the dropdown is selected. Another requirement is that once the country is selected, it should display the countr ...