CSS almost there!

Below is the HTML code I am using:

<div class="ObjectList" id="ObjectList">
    <p class="ObjectListTitle" id="Element">TEST</p>
</div>

The CSS is applying properly to the ObjectList class but is not working for the ObjectListTitle class.

Here is the content of my CSS file:

#ObjectList{
    background-color:red;
    height:100%;
    width:25%;
}

#ObjectListTitle{
    background-color:yellow;
}

Answer №1

The identifier for your element is not ObjectListTitle, it is actually the class ObjectListTitle. You should use a class selector (.) instead of an ID selector (#).

.ObjectListTitle{
    background-color:yellow;
}

View Demo

Answer №2

Here's a suggestion to try: When creating CSS, define the styling for an ID and then apply it to the HTML source code within a class like this:

<div class="ObjectList" id="ObjectList">
    <p class="ObjectListTitle" id="Element">TEST</p>
</div>

Answer №3

Understanding CSS involves grasping how various groups of elements are styled.

For example, styling a <div></div> tag means applying the style to all elements with that tag, in this case, all divs.

div{background:black;}

When it comes to classes, such as

<div class="foo" id="bar"></div>
, the CSS rule is applied to all tags with that class. This means the rule will affect the page every time the class is used.

.foo{background:black;}

On the other hand, styling an ID, like

<div class="foo" id="bar"></div>
, is similar to styling a class, but the ID must be unique on a page. This ensures that the rule is only applied once per page at most.

#bar{background:black;}

Answer №4

Here is some example code you can try out.

Code Snippet

<div class="ObjectList" id="ObjectList">
    <p class="ObjectListTitle" id="Element">TEST</p>
</div>

Styling

#ObjectList{
background-color: red;
height: 100%;
width: 25%;
padding: 10px;
}

.ObjectListTitle{
background-color: #ff9900;
width: 50px;
height: 50px;
display: block;
}

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

Transforming the inputted URL into a clickable hyperlink

I have a text input field where any text entered is displayed below using angular.js. However, I am trying to convert any http URL entered into a clickable link. I found reference to the solution on this Stack Overflow page. Despite successfully converting ...

Reacting like sticky bottoms and tops

I'm working on a react/tailwind project that involves a component I want to be fixed at both the top and bottom of the screen. In simpler terms, there's an element that I need to always stay visible even when the user scrolls up or down the page ...

Struggling to reset the first item in an HTML select dropdown with Angular - any tips?

I am having an issue with my dropdown in a modal window. When I first open the modal, the dropdown works as expected. However, if I make a selection and then close and reopen the modal, the selected value remains instead of resetting to 'None selected ...

What is the process for showing a button once a typewriter animation has completed?

Is there a way to implement a typewriter effect that types out a text line and then displays a button once the animation is complete? Here is the CSS code for the typewriter effect: .welcome-msg { overflow: hidden; /* Ensures the content is not revea ...

Tips for creating gaps between wells within a Bootstrap row

Utilizing bootstrap, I am aiming to position two wells side by side without them being squeezed right next to each other. However, I am encountering some issues with achieving this. Here's the code snippet I am currently using: <div class="contai ...

What is the best way to retrieve the value of an object in PHP?

There seems to be an issue with retrieving the value of an object. When attempting to get the object value, it appears empty. However, when simply echoing the object, there is content and not null. I'm struggling to understand how to access that value ...

What is the best way to include CSS code in the output display?

I'm looking to customize the appearance of my table rows and cells. Specifically, I want the cell file name, size, etc., to be colored blue while each row should have a different color on hover. I've attempted to achieve this using CSS and variou ...

Remove a table along with its contents from HTML code using PHP

I'm working with some HTML code that includes a table, and I need to completely remove the table and its contents using PHP. While I know how to strip the table tags using PHP's strip_tags function, I'm not sure how to delete the table conte ...

Struggling to successfully transmit my form information to my email

I've been trying to figure out how to get the information submitted through the form on my website sent to my email, but I can't seem to make it work... Here's what I have in my email.php file: <?php $EmailFrom = "<a href="/cdn-cgi/ ...

Exploring ways to obtain the value of an unchecked checkbox in CodeIgniter

I am currently working on an attendance system using CodeIgniter. I have a list of checkboxes and I have successfully managed to insert the checked data into the database. However, I am now trying to figure out how to insert the unchecked data into the dat ...

Opening Tags in Selenium for HTML

Is it possible for Selenium with XPath to properly work with HTML that is not in the form of XML, and contains open tags like <col> and <input>? I'm curious if anyone can confirm this. I ask because our automation testing team has noticed ...

Display PHP Array data in a table on a webpage

I need help arranging the results from a MYSQL database into an HTML table. Right now, each item is displayed in one column per row. Here is my current code: <?php $catagory=$_GET["q"]; $con = mysql_connect("localhost","cl49-XXX","XXX"); if (!$con) ...

Activate jquery code during interaction

I am in need of a scalable image that can be centered within a scalable <div>. Currently, I have a wrapper <div> along with the scalable <div> that contains the image. Additionally, there is some jQuery code in place to calculate the widt ...

Hide the parent div element if the nested unordered list does not contain any items

I transformed an HTML template into a typo3 template using automaketemplate. Within the HTML code, there is a structure of divs like this <div class="bigPostItWrap">1 <div class="postit">2 <div class="p ...

How can I display a pre-existing div with a dropdown button?

I have individual div elements for each type of clothing item (shirt, pant, suit) that I want to display when the corresponding service is selected. This means that when I click on one of them, only that specific div will be shown. I am looking for a solut ...

What is the proper way to add comments within CSS code inline?

Can anyone provide instructions on how to comment an inline css property, such as height, in the following code snippet? <div style="width:100%; height:30%;"> Any help is appreciated. Thank you! ...

Incorporate ng-click as an attribute in AngularJS

Is there a way to include ng-click as an attribute? For example, imagine I want to add ng-click if my <li> has the class someClass: angular.element(root.querySelector('li.someClass').attr({'ng-click': 'someFunc()'}); ...

HTML5 Canvas Border

Hey Everyone, I've been working on an HTML5 canvas project where I set the canvas width to $(window).width(). Everything was going smoothly until I added a border, which caused a horizontal scroll to appear. Important: I attempted to use the innerWid ...

What is a method to raise the height when scrolling down without reducing it when scrolling up?

For my One Page project, I want a DIV element to increase in height when scrolling down, but maintain that increased height when scrolling up. Currently, I am utilizing JQuery with the code snippet below: $(function(){ $(window).scroll(function() { ...

Retrieve CSS hover values using jQuery

When the page is loaded, I need to execute a function that retrieves the CSS background image settings as well as the hover background image setting, which I intend to use in a different way. The only technique I have come across requires an actual mouseo ...