List is not considering the CSS class

The outcome is as expected:

#container {
  display: flex;
}

#red_box {
  height: 30%;
  width: 30%;
  background-color: red;
}

  <div id ="container">
      <div id="red_box">a</div>
      <div id="blu_box">b</div>
  </div>

However, when I separate the height property into its own class and apply both styles to the element, the height setting is not recognized.

#container {
  display: flex;
}
#box {
  height: 30%
}
#red_box {
  width: 30%;
  background-color: red;
}

  <div id ="container">
      <div class="box red_box">a</div>
      <div class="box blu_box">b</div>
  </div>

Answer №1

To differentiate between the box and red_box CSS selectors, replace "#" with "." as classes can be used by multiple elements while IDs should be unique.

Answer №2

Your code has a few issues that need to be addressed:

#container {
  display: flex;
}

.box { /* Make sure to change the id selector "#" to class selector "." */
  height: 30%
}

.red_box { /* Change the id selector "#" to class selector "." */
  width: 30%;
  background-color: red;
}
  <div id="container"> <!-- Remove the space between the id and equal sign -->
      <div class="box red_box">a</div>
      <div class="box blu_box">b</div>
  </div>

Answer №3

In my opinion, it is preferable to use CSS classes rather than IDs, but the most important thing is to maintain consistency. The issue arises when you mix ID selectors (#box and #red_box) with class references.

Here is the corrected code using classes:

.container {
  display: flex;
}
.box {
  height: 30%
}
.red_box {
  width: 30%;
  background-color: red;
}

  <div class="container">
      <div class="box red_box">a</div>
      <div class="box blu_box">b</div>
  </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

Is there a way to pass locale data using props in VueJS Router?

To access hotel data, the URL path should be localhost:8080/hotel/:id (where id is equal to json.hoteID). For example, localhost:8080/hotel/101 This path should display the specific data for that hotel. In order to achieve this, we will utilize VueJS vu ...

Creating grids and dividing them using a combination of CSS, JavaScript, and PHP

I've encountered an interesting challenge while working on a web project and would love some advice on how to tackle it: Within a database, I have a collection of images that I want to display in a grid format. The twist is that higher ranked images ...

Is it possible to stop the manipulation of HTML and CSS elements on a webpage using tools similar to Firebug?

How can we prevent unauthorized editing of HTML and CSS content on a webpage using tools like Firebug? I have noticed that some users are altering values in hidden fields and manipulating content within div or span tags to their advantage. They seem to be ...

In Firefox, selecting the <option disabled> feature causes the corresponding option item to vanish

<select class="form-control" id="service_select"> <option disabled="disabled"></option> </select> It works fine in Chrome, but is there an alternative method to disable it without hiding it? Thank you. ...

Using an image link in CodeIgniter will not function properly

Could someone please clarify why this particular code is not functioning properly in CodeIgniter? .linkBack{ background-image:url('/myBlog/CodeIgniter_1.7.2/pictures/arrow.gif'); display:block; height:58px; width:105px; text-indent:-999px ...

Laravel is having trouble loading CSS and JS files

Despite trying multiple solutions, my application on the server is still not loading the CSS and JS files in main.blade.php when the CSS files are located in public/assets_setup/css/style.css. I have made changes to the files, but the page remains the same ...

Guidelines for refreshing owl carousel on ng-click using AngularJS

I am encountering a significant issue with the use of an owl carousel in angular.js. It functions properly the first time, but when I have buttons on the same page and need to rebuild the owl carousel upon clicking a particular button with new data, that&a ...

A plugin for creating modal video pop-ups using jQuery

I am currently experiencing an issue with a JQuery plugin I am using. Everything seems to be working fine except for the fact that the video is not loading, and I can't seem to pinpoint the cause of the problem. My goal is to display a Vimeo video on ...

CSS displaying differently in Chrome compared to IE

Working on a basic asp.net web project, I came across an issue with my CSS files. Within the Styles folder of the project, there are four css files, all quite simple. The Main.css file contains the following code: body { font-family: Arial, Helvetica, San ...

How to use jQuery Animate to create a step-by-step animation with image sprites?

I'm working on creating an image sprite using jQuery and I'm curious if it's feasible to animate it in steps rather than a linear motion. I initially tried using CSS3 animations, but since IE9 is a requirement, the animations didn't wor ...

Learn how to incorporate a vertical divider pipe into your website using Bootstrap

Hello, I'm having trouble adding a separator between nav-links that actually works. I tried adding the following code snippet: nav-link:after { content:"|"; } But unfortunately, it's either not working at all or appearing on the left side of th ...

Can the active link color be modified in Bootstrap 5 without the use of CSS?

It's been a while since I've worked with HTML, and this is only my second attempt at creating tabs, so I might be approaching this the wrong way. Currently, the link text in the tabs is in the primary bootstrap color (blue) by default and change ...

Showing child elements within a div using AngularJS

I am eager to create a straightforward AngularJS website that will showcase an initially hidden HTML element along with all of its children. Below is the HTML structure snippet I plan to use: <div class="hiddenStuff"> <h3>Game Over</h3&g ...

jQuery for validating input fields with positive integers only using regular expressions

I currently have two input fields in my HTML that look like this: <input type="text" class="txtminFeedback" pattern="^\d+([\.\,][0]{2})?$" placeholder="Minimum Feedback"> <input type="text" class="txtmaxFeedback" pattern="^\d ...

What is the best way to retrieve the current URL with a hashtag symbol using JavaScript?

I am attempting to display the current URL after the question mark with a hash symbol using PHP, but unfortunately, it is not achievable. Therefore, I need to utilize JavaScript for this task, even though I have limited knowledge of it. This is the specifi ...

The image selection triggers the appearance of an icon

In my current project, I am working on implementing an icon that appears when selecting an image. The icon is currently positioned next to the beige image, but I am facing difficulties in making it disappear when no image is selected. Below are some image ...

Issues Encountered with Bootstrap Modal Form Code

ASP.NET <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> < ...

The sequence of CSS and deferred JavaScript execution in web development

Consider this scenario: you have a webpage with a common structure in the <head>: <link rel="stylesheet" href="styles.css"> // large CSS bundle <script defer src="main.js"></script> // small JS bundle with defer attribute There is ...

Open the URL in a new tab based on certain conditions

Currently, my page redirects if a specific checkbox is selected and the "submit" button is clicked: if request.Form("myCheckbox") = "on" then response.Redirect("/newPage.asp?txt="staff"") else response.Redirect("/thisPage.asp") end if I ...

Is there a way to keep a div element stationary during scrolling without using fixed positioning?

Is there a way to prevent a div from moving when scrolling up or down without using the position:fixed property? When an element is fixed, the scroll bar disappears making it impossible to reach the element by scrolling. div{ position:fixed; top:1 ...