Is it possible for me to set my HTML body class as ".body" in CSS?

CSS

.body {
    background: linear-gradient(-45deg, rgb(255, 0, 0), rgba(216, 29, 29, 0.856), #fdfdfdd7, #234cd5, #ffffff);
    background-size: 400% 400%;
    background-repeat:no-repeat;
    animation: gradient 35s ease infinite;
    height: 100vh;
}

HTML

<!DOCTYPE html>
<html>
<link rel="stylesheet" href="style.css">
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="./listener.js" type="text/javascript"></script>
<body class="body">
<div id="container">
      <title>Police 10 Codes</title>
      <h1>LSPD Ten Codes</h1>
      <img src="https://i.ibb.co/2vNZgd9/lspd-removebg-preview.png" alt="LSPD Image"style="width:150px;height:150px;">
      <div class="dropdown">
        <button class="dropbtn">Non-Serious</button>
        <div class="dropdown-content">
          <a href="#">10-1 Unable to Copy / Weak Signal</a>
          <a href="#">10-3 Stop Transmitting</a>
          <a href="#">10-4 Affirmative / Understood</a>
          <a href="#">10-7 Out of Service</a>
          <a href="#">10-8 In Service</a>
          <a href="#">10-12 Stand by</a>
          <a href="#">10-17 En-route to Scene</a>
          <a href="#">10-19 Return to Station/Location</a>
          <a href="#">10-20 Location</a>
          <a href="#">10-22 Disregard</a>
          <a href="#">10-23 Arrived at Scene</a>
          <a href="#">10-24 Assignment Complete</a>
          <a href="#">10-30 Traffic Stop</a>
          <a href="#">10-36 Correct Time</a>
          <a href="#">10-37 Suspicious Vehicle</a>
          <a href="#">10-40 Run Silent No Lights/Siren</a>
          <a href="#">10-53 Road Blocked</a>
          <a href="#">10-56 Intoxicated Pedestrian</a>
          <a href="#">10-58 Direct Traffic</a>
          <a href="#">10-59 Convoy / Escort</a>
          <a href="#">10-60 In the Area</a>
          <a href="#">10-61 Clear for Radio Traffic</a>
          <a href="#">10-74 Negative</a>
          <a href="#">10-77 ETA</a>
          <a href="#">10-68 Dispatch Information</a>
          <a href="#">10-92 Improper parking</a>
        </div>
      </div>
      <div class="dropdown2">
        <button class="dropbtn2">Medium</button>
        <div class="dropdown2-content">
          <a href="#">10-0 Use Caution</a>
          <a href="#">10-10 Fight in Progress</a>
          <a href="#">10-25 Report in person</a>
          <a href="#">10-26 Detaining/Arresting Subject</a>
          <a href="#">10-29 Warrant Check</a>
          <a href="#">10-31 Crime in progress</a>
          <a href="#">10-50 Traffic Crash</a>
          <a href="#">10-55 DUI</a>
          <a href="#">10-57 Hit & Run</a>
          <a href="#">10-78 Requesting backup</a>
          <a href="#">10-80 Fire Alarm</a>
          <a href="#">10-94 Street Racing</a>
          <a href="#">10-96 Mental Patient</a>
        </div>
      </div>
      <div class="dropdown3">
        <button class="dropbtn3">Serious</button>
        <div class="dropdown3-content">
          <a href="#">10-18 Urgent</a>
          <a href="#">10-32 Person with Gun</a>
          <a href="#">10-39 Run with Lights/Siren</a>
          <a href="#">10-67 Report of Death</a>
          <a href="#">10-80 Pursuit in Progress</a>
          <a href="#">10-82 Fire in Progress</a>
          <a href="#">10-89 Bomb Threat</a>
          <a href="#">10-90 Bank Alarm</a>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>

Whenever I check this code, the size of the .body class keeps readjusting. I have a #container ID class that is meant to control the opening and closing of the UI. The UI works fine, but the problem lies in the fact that the size of the .body class keeps changing. I want it to remain at its current settings, either 400% 400% or fit perfectly for full-screen viewing. Any assistance on this matter would be greatly appreciated. Thank you.

Answer №1

<div> should always be within the <body> tag in HTML. The body tag needs to precede the Div element, and all HTML elements must be contained within the <body> tag. To ensure the body occupies the entire height of the browser window, you can set the body height using the following CSS:

HTML, 
body {
    height: 100%;
}

Alternatively, you can use the following CSS:

html {
  height: 100%;
}
body {
  min-height: 100%;
}

For more information, please refer to the original answer on Stack Overflow - Make body have 100% of the browser height

Answer №2

Your HTML is not valid because all elements must be children of the body. Currently, you have

<div id="container">
as the parent of body. Please move it inside the body.

Check out this revised code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>LSPD Ten Codes</title>
    <link rel="stylesheet" href="style.css">
    <script src="nui://game/ui/jquery.js" type="text/javascript"></script>
    <script src="./listener.js" type="text/javascript"></script>
    <style type="text/css">
        .body {
            background: linear-gradient(-45deg, rgb(255, 0, 0), rgba(216, 29, 29, 0.856), #fdfdfdd7, #234cd5, #ffffff);
            background-size: 400% 400%;
            background-repeat:no-repeat;
            animation: gradient 35s ease infinite;
            height: 100vh;
        }
    </style>
</head>
<body class="body">
    <div id="container">
      <title>Police 10 Codes</title>
      <h1>LSPD Ten Codes</h1>
      <img src="https://i.ibb.co/2vNZgd9/lspd-removebg-preview.png" alt="LSPD Image" style="width:150px;height:150px;">
      <div class="dropdown">
        <button class="dropbtn">Non-Serious</button>
        <div class="dropdown-content">
          <a href="#">10-1 Unable to Copy / Weak Signal</a>
          <a href="#">10-3 Stop Transmitting</a>
          <a href="#">10-4 Affirmative / Understood</a>
          <a href="#">10-7 Out of Service</a>
          ...
          <a href="#">10-90 Bank Alarm</a>
        </div>
      </div>
      <div class="dropdown2">
        <button class="dropbtn2">Medium</button>
        <div class="dropdown2-content">
          <a href="#">10-0 Use Caution</a>
          ...
          <a href="#">10-96 Mental Patient</a>
        </div>
      </div>
      <div class="dropdown3">
        <button class="dropbtn3">Serious</button>
        <div class="dropdown3-content">
          <a href="#">10-18 Urgent</a>
          ...
          <a href="#">10-90 Bank Alarm</a>
        </div>
      </div>
    </div>
</body>
</html>

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 list with a repeating group of radio buttons

I have a set of 'options', which consists of the following: {Id: 1, Label: "option 1"}, {Id: 2, Label: "option 2"} Additionally, I have a list of 'products' structured as follows: {Id: 1, Name: "Name 1", Recommend: options[0]}, {Id: ...

Revolutionizing Interaction: Unveiling the Power of Bootstrap 3

Would you be able to assist me in customizing buttons to resemble a typical dropdown link? <div class="dropdown"> <button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">Dropdown <span class="caret"&g ...

The component's div does not respond to the max-width attribute

I'm currently facing an issue with my chart component in a view. I've been trying to reduce its size using max-width property but it doesn't seem to be working. Below are the relevant code snippets: <div id="chart"> < ...

Alignment issue with Bootstrap 4 form fields within inline form group

My experience with Bootstrap 4 on certain pages has been quite challenging, specifically when it comes to aligning fields with labels to the left and maintaining an aligned appearance for input fields. Here is the snippet of my code: <div class="wrap ...

Refreshing a webpage to accurately display changes made in a CRUD application without the need for a hard reset

My to-do app is almost fully functional - I can create items, mark them as completed, and delete them using a delete button. However, there's one issue: when I delete an item, the page doesn't update in real-time. I have to manually refresh the p ...

CSS for Page Header with Scroll-Over Content

Having trouble creating a "collapsing header" design where the page content scrolls over the banner image. I've tried adjusting z-index and positioning properties in CSS, but can't achieve the desired effect. Any help or guidance would be greatly ...

I am experiencing an issue where the CSS file is not being loaded in my HTML file while using the Netbeans IDE

I am a beginner in HTML and CSS and I have been trying to link my CSS file to my HTML code after reading various solutions on Stack Overflow. Unfortunately, I am facing difficulty as the CSS file is not loading in my HTML code. If anyone can offer assistan ...

Setting specific variables in an array with corresponding key-value pairs

I need help with extracting specific columns from a table that has 5 columns. The columns in question are: column1, user_id, column3, column4, and user_exp. Let's say I have the following select query: $mat_sql = mysql_query( "SELECT * FROM users ...

Apply CSS styling to the entire element when hovering over its pseudo-element 'after'

I am working on a button/speech bubble design with a unique hover effect. Here is the current setup: https://i.stack.imgur.com/4OrpL.png Here is the code snippet for the button: <div value="GO" id="go-div" class="bubble"> <input type="submit ...

External CSS File causing improper sizing of canvas image

I have been working on implementing the HTML5 canvas element. To draw an image into the canvas, I am using the following javascript code: var img = new Image(); var canvas = this.e; var ctx = canvas.getContext('2d'); img.src = options.imageSrc; ...

Navigating through Expression Engine and utilizing conditional statements

Would greatly appreciate some assistance with this issue. I am working on an Expression Engine website and encountering difficulties with simple conditionals for navigation active states. Despite having a color state designated within the styles, there s ...

Which Javascript/Css/HTML frameworks and libraries would you suggest using together for optimal development?

Interested in revamping my web development process with cutting-edge libraries, but struggling to navigate the vast array of tools available. The challenge lies in finding a harmonious blend of various technologies that complement each other seamlessly. I& ...

Persistent button positioned at the bottom of the page, remaining visible even when scrolling to the very end of the content

I am looking to add a floating button that remains in the same position relative to the content until the window is scrolled to a certain point, after which it sticks to the end of the content. In simple terms, I want the element to act as 'relative& ...

Designing functions with HTML

I have been working on creating a Coffeescript function that incorporates common HTML for an object that is frequently used on my page. To make the content dynamic, I am passing a variable to the function which will be replaced each time it is called. Unfo ...

What is the best way to create a cornered button using CSS?

Is there a way to create a button using only CSS? https://i.stack.imgur.com/7mjVV.png This is the code I've come up with so far: .customButton { width: 100px; height: 100px; background: #6d1a3e; position: relative; transform: rotate(-90 ...

How can I redirect a remote image URL to a local folder during development?

Currently, I am pulling image URLs from a database that was dumped from the production server. An example of one of these URLs is https://example.com/imageStorage/photo.jpg. These URLs are then used to display images in HTML templates using the following f ...

Unshrinkable item causing multiple lines text-overflow in a flexbox layout

My goal is to achieve the following design: https://i.stack.imgur.com/YLUtN.png Currently, I have attempted the following approach (although it doesn't fully meet my requirements): .parent { max-height: 40px; display: flex; flex-wrap: wrap; ...

The offcanvas menu in the NextJS Tailwind website does not handle hover or tap events properly when outside of the parent dimensions

My header includes an off-canvas menu that slides in from the right side. Everything seems to be working fine, except for one issue: when the menu is open and visible, the mouse and touch events pass through it to the content underneath. Check out the cod ...

Unable to display <iframe> containing a YouTube video on Mozilla Firefox page

I have included an <iframe> in my webpage to display videos from YouTube, but I am facing an issue with Mozilla Firefox. In Chrome, IE, and Edge, the videos display correctly using the following code: <iframe src="http://www.youtube.com/v/DNLh8p ...

Top way to include an HTML and javascript file in an Ext.Panel within Sencha Touch

My main goal is to efficiently include external HTML files and display them on an Ext.Panel in Sencha touch 2.3 by creating a wrapper module for the HTML file that can be instantiated using xtype, with an external Javascript file for event handling. Updat ...