Having issues with Div CSS functionality not properly functioning

My background CSS is working fine, but the styling for the .about div is not applying.

Here is my HTML code:

   <DOCTYPE! HTML>
    <head>
    <link rel="stylesheet" type="text/css" href="CSS.css">
    </head>
    <body>
    <div class="About"
    <p>Hi</p>
    </div>
    </body>

This is how I have set up my CSS:

body {
    background-image: url("BG.jpg");
    background-repeat: repeat-repeat;
}
.About{
    font-size:24px;
    color:#ffffff;
    background-color:#000000;
    padding:50px;
    margin:50px;
}

The body background works, but the rest of the styles are not being applied as expected.

I have tried a few different approaches like this:

body {
    background-image: url("BG.jpg");
    background-repeat: repeat-repeat;
}
.About{
    font-size:24px;
    color:#ffffff;
    background-color:#000000;
    padding:50px;
    margin:50px;
}
p.About{
    font-size:24px;
    color:#ffffff;
    background-color:#000000;
    padding:50px;
    margin:50px;
}

However, none of these solutions seem to work properly. I also attempted:

body {
    background-image: url("BG.jpg");
    background-repeat: repeat-repeat;
}
.About{
    font-size:24px;
    color:#ffffff;
    background-color:#000000;
    padding:50px;
    margin:50px;
}
p.About{
    font-size:24px;
    color:#ffffff;
    background-color:#000000;
    padding:50px;
    margin:50px;
}
p{
    font-size:24px;
    color:#ffffff;
    background-color:#000000;
    padding:50px;
    margin:50px;
}

The "p" tag seems to work, but it applies the styles too broadly. I specifically need it to apply to the "About" div only.

I have tested this in both Google Chrome and Internet Explorer, so it doesn't seem to be a browser compatibility issue. Any thoughts on what might be causing the problem?

Answer №1

Make sure to properly enclose the tag

<div class="Description"> ... </div>

In your CSS, there is an extra }.

The correct format is:

.Description{font-size:16px;
color:#333333;
background-color:#ffffff;
padding:20px;
margin:10px;
}

Answer №2

Your code contains several syntax errors that may lead to unexpected behavior, including one incorrect rule.

  1. Make sure to properly close your div tag to prevent the browser from misinterpreting the markup
  2. In the .About rule, there is an extra } after margin: 50px;, potentially causing other rules to be ignored
  3. The rule p.About targets a p tag with the class .About; however, you should use .About p to target any p tags within an element with the class .About

For targeting the p in the .About div, only include the rule .About p (the .About and p rules are unnecessary).

body {
  background-image: url("BG.jpg");
  background-repeat: repeat-repeat;
}
.About p {
  background-color: #000000;
  color: #FFFFFF;
  font-size: 24px;
  margin: 50px;
  padding: 50px;
}
<div class="About">
  <p>Hi</p>
</div>

Answer №3

Ensuring the div tag is correctly enclosed is essential:

<div class="Information">

Answer №4

Make sure to check for any syntax errors in your CSS code, such as an extra '}' and ensure that the div is properly enclosed.

<div class = "details">.. </div>

Answer №5

initially wrap in tag

<div class="Information"> ... </div>

Next step is to

.Information{font-size:18px;
color:#333333;
background-color:#f4f4f4;
padding:30px;
margin:20px;
}

Answer №6

<div class = "Information">
    <p>Hello</p>
</div>

as opposed to

<div class="Information"
    <p>Hello</p>
</div>

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

Placing a button above another element using CSS styled components

I'm attempting to make a button overlap and be positioned in a specific location on top of a search bar. The current appearance is not what I desire, as the button seems to shift back to its original position when adding a :hover element after applyin ...

Can PhoneGap be used to create HTML5 applications from scratch?

Despite diligently searching through the PhoneGap website and their support group, I am still coming up empty-handed in my quest for an answer: My current project involves creating an application that functions as a pure HTML5 application, capable of runn ...

What could be the reason for the CSS file not getting applied to the HTML in my project?

Having trouble applying an external CSS file to my HTML file. Currently working on a Cloud IDE (goormIDE, similar to C9) and trying to link an external CSS file to my HTML file on the web server using Node.js. However, the CSS file is not being applied to ...

What could be causing my HTML button to malfunction when attempting to navigate to a different section of the webpage?

Just starting out and developing my website. My hosting provider is IPage, but I'm running into an issue. When I click on a button to switch to another section of the site, it's not working as expected. Here's the code snippet: <button on ...

The Send.php script is missing the input fields for Name and Email

Running my own website at CrystalVision.com, I have some challenges with my PHP skills. The issue lies within my send.php file. Although the email functionality works fine and I receive messages, the Name and Email fields filled in by users are not display ...

The input range in ChromeVox is behaving incorrectly by skipping to the maximum value instead of following the correct step value

Attempting to get an input type="range" element to function correctly with ChromeVox has presented me with a challenge. Here's what I'm facing: When I press the right arrow key to move forward, it instantly jumps to the maximum value of 100 in ...

Finding the variance in the given situation is as simple as following these steps

To find the variance between the "Total Marks" in a question and the input texts for each answer, we need to consider specific scenarios. Firstly, if a question has only one answer, the text input should be displayed as readonly with the same value as the ...

How to modify the appearance of the md-tab-header component in Angular2

Currently, I am working on a project that was passed down to me by a former colleague. It is a gradual process of discovery as I try to address and resolve any issues it may have. One particular element in the project is a md-tab-header with a .mat-tab-he ...

CSS code to modify background color upon mouse hover

I am currently working on creating a navigation menu. Check out the code snippet here: http://jsfiddle.net/genxcoders/ZLh3F/ /* Menu */ .menu { height: 100px; float: right; z-index: 100; } .menu ...

How does the size of a font affect the amount of screen space a character occupies in pixels?

I am currently working on a custom user interface that requires precise measurement of how many pixels are taken up by a specific string of text. My attempts to control the character size using the font-size property have been met with unexpected results. ...

Javascript does not function on sections generated by ajax

I'm facing an issue with a JavaScript function not working on a dynamically generated part using AJAX. Here is the AJAX call: <script> $(window).on('scroll', function() { $("#preloadmore").show(); if ($(window).height() + $(window ...

Obtaining the source id using HTML5 Drag & Drop functionality

Is there a way to retrieve the id of the div I am dragging from, similar to how it is demonstrated here? Your insights are greatly appreciated. Thank you. ...

Display exclusively the chosen option from the dropdown menu

I am facing an issue with the select input on my webpage. Whenever I try to print the page, it prints all the options of the select instead of just the one that is selected. Can someone please guide me on how to modify it so that only the selected option ...

Dynamic manipulation of classes based on user attributes

One thing I've noticed is that certain WordPress themes, like 'Thematic', include user-specific classes in the body element to avoid using CSS browser hacks. For example: wordpress y2010 m02 d26 h05 home singular slug-home page pageid-94 pa ...

Child Theme setup in progress! Beware of the error message: "Unable to access file: file_get_contents9(). The specified stream does not exist."

I am currently in the process of developing a child theme based on my existing theme (Tesseract 2). I have carefully followed the guidelines outlined here, but unfortunately, I keep encountering the following error: Warning: file_get_contents(/home/fletch ...

Choose the heading element based on its class

I am trying to target a specific element by its class and store it in a variable, but I specifically need this element to be a heading element. To clarify: at any given time, there are always exactly 3 elements with this particular class on my page: an < ...

Guide on centering an unfamiliar element in the viewport using HTML, CSS, and JavaScript

In the process of developing my VueJS project, I have successfully implemented a series of cards on the page. However, I am now facing a challenge - when a user selects one of these cards, I want it to move to the center of the screen while maintaining its ...

What is the best way to add padding to each line within a block of text containing multiple lines

My <span> tag has a background color and left and right padding applied to it. However, the padding is only visible at the beginning and end of the <span>, not on each line when the text wraps onto multiple lines. Is there a way to add padding ...

Tips for assigning an AngularJS data-bound value to the href attribute of an anchor tag

I need to include multiple email ids separated by commas from an angularjs binded value in the mailto field of an anchor tag. The team.emails variable can contain either a single email id or multiple email ids separated by commas. <tr ng-repeat="team ...

Exploring the process of querying two tables simultaneously in MySQL using PHP

I currently have a search box in my PHP file that only searches from the "countries" table. However, I also have another table called "continent" and I would like the search box to retrieve results from both the "countries" and "continent" tables. Here is ...