Overridden CSS rules

Having a slight CSS dilemma.

Within my webpage's html, I have the following structure:

<div class='box-div'>
  <div>Entry 1</div>
  <div class='hide'>Entry 2</div>
</div>

Here is my associated CSS styling:

.box-div div {
  display: inline-block;
}

.hide {
  display: none;
}

My goal is to hide the second nested div, however, the first rule overrides the second one. How can I resolve this issue?

Answer â„–1

Elevate the power of your code to surpass the previous standard:

.box-div .hide {
  display: none;
}

alternatively,

div.hide{
   display: none;
}

Answer â„–2

There are various methods to achieve the same outcome.

1

.container {
  display: block;
}

.hidden {
  display: none;
}

2

.wrapper div{
  display: inline-block;
}

div.hidden {
  display: none;
}

3

.wrapper div{
  display: inline-block;
}

div.hidden {
  display: none;
}

4

.content div {
    display: inline-block;
}

.hidden {
    display: none !important;
}

Answer â„–3

.hide.hide  {
  visibility: hidden;
}

To enhance the specificity of your CSS, consider repeating it multiple times.

Answer â„–4

It's incredibly simple

Add this to your HTML:

<div class='container'>
  <div>Item 1</div>
   <div class='hidden-item'>Item 2</div>
</div>

And for CSS, use:

.container div {
  display: inline-block;
}

.container > div.hidden-item {
  display: none;
}

Give it a shot!

Answer â„–5

In my opinion, utilizing a singular class named .hidden is an effective approach to concealing an element on the webpage regardless of its nesting level. I believe in having a versatile class that can be applied universally.

Thus, it seems more practical to devise a class for dispaly:inline-block which can be easily repurposed.

While one could specify that the initial div within .box-div always possesses the property of inline-block, such an approach may prove overly constricting.

Here is the solution I propose:

.ib {
  display: inline-block;
}

.hide {
  display: none;
}

<div class='box-div'>
  <div class="ib">Entry 1</div>
  <div class='hide'>Entry 2</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

Automatically adjusting jQuery script now functions on all hyperlinks for seamless resizing

I am attempting to create a rollover script that will resize my social network links when hovered over. The desired effect is for the 32px square icon to expand and display the trailing address. For example, when hovering over the Facebook link, it should ...

The 'refresh' function in jQM listview is causing issues with inset lists

For some reason, I am struggling to understand why this issue is occurring: In jQuery Mobile, I have an unordered list with data-inset="true". Initially, it displays perfectly with rounded top and bottom edges. However, on dynamically adding new elements t ...

Tips for making inline elements match the line height

Consider this block element : <div style="background-color: gray; line-height: 30px;"> Some text and a <a style="background-color: yellow;">link<\a> <\div> Why is it that the yellow color does not extend the full hei ...

One column in HTML table row is functional, while the other is not functioning as intended

Currently, I am working on a mapping application that allows users to add features to a database. These features are then displayed on a mapping page in an HTML table. The table consists of three columns: Feature Name, Selected (with an on/off slider switc ...

CSS - Nesting classes within one another

I'm currently working on customizing a Tumblr theme. Users have the option to choose between a one-column or two-column layout style, and I'm facing some challenges with implementing this in the CSS code. I attempted to add a class based on the u ...

JavaScript/DOM - What sets apart a "CSS Selector" from an attribute?

When it comes to excluding declarative event handlers: <a href='#' onclick=<handler> ... /> Is there a significant difference between an Attribute and a CSS Selector? For example, if I define my own attribute: <a href='#&a ...

Maintaining the image's aspect ratio while cropping it to fit within the maximum or minimum height

Is there a way to make an image responsive by resizing it while keeping its aspect ratio intact at all sizes? I want the height of the image to stay fixed above 650px, cropping the top and bottom to maintain the ratio without stretching. Additionally, I do ...

Changing the positions of objects on a resized HTML Canvas

I am currently developing a tool that allows users to draw bounding boxes on images using the Canvas and Angular. Everything was working smoothly until I encountered an issue with zooming in on the canvas causing complications when trying to draw bounding ...

Achieving a fixed footer at the bottom with absolute positioning on a webpage

I'm facing an issue with positioning a footer on my webpage, which is made up of div sections that are absolutely positioned. The problem arises because using the bottom property fixes the footer to the bottom of the screen rather than the bottom of t ...

Implementing AngularJS drag and drop functionality in a custom directive

I am in search of an example that demonstrates similar functionality to the HTML5 File API using Angular-js. While researching directives for Angular 1.0.4, I found outdated examples that heavily rely on DOM manipulation. Here is a snippet of the pure Ja ...

Is there a way I can turn off the dragging functionality in my situation?

Is there a method to disable the dragging functionality within a draggable element? $('#dragitem').draggable({ scroll : false, drag: function(event, ui){ //check if condition is met if(†...

The collapse component from bootstrap is not visible due to an overlapping button

I am currently working on a responsive calendar featuring full-width buttons for events, accompanied by additional information displayed using the collapse component below. However, I am facing an issue where the button overlaps with other elements, preven ...

What is the best way to manipulate HTML elements with Selenium VBA and insert text into them?

I've been encountering difficulties when attempting to reference a search box on a website using Selenium in VBA. The search box's HTML code is as follows: <input type = "search" class ="form-control input-sm" placeholder aria-controls="resul ...

Ways to turn off .removeClass()

Encountering an issue with jquery-2.1.4.js. Upon integrating a layerslider into my website, the script modified div classes. Attempted using older versions of the script without success. Currently have classes as follows: <a href="#" class="col-md-3 ...

Generating a Popup Alert with a DIV

Looking at this instance: HTML / CSS Popup div on text click I am curious about how to have this display on the main page upon initial visit to the website. I prefer it to load automatically without requiring a button click, and once the content is read, ...

Using HTML5 input type number along with a regular expression pattern

In order to display only numbers and forward slashes in the input field with regex pattern, I attempted the following code: <input type="number" pattern="[0-9\/]*"> However, this code only shows the number pad from 0 to 9. How can I modify the ...

How can you adjust the width of the Material UI Select component?

Trying to customize the width of the Material UI Select component can be a bit tricky. To set the desired width, you need to assign a specific class to the FormControl component. This class, such as mw-120, should define the minimum width as 120px in your ...

Identify the font style of the text box and ensure that the contenteditable feature matches the appearance of the

I'm struggling to style a contenteditable element to resemble a regular textbox on my website. Can anyone help me identify the font used in this picture? I've tried several but none seem to match perfectly. https://i.sstatic.net/2aAbb.jpg The co ...

What is the best way to display content at a specific time using Angular?

Whenever a user searches something and no results are found, I display a message. However, when there is content to show, an error message pops up for about 3-4 seconds before disappearing and showing the search results. This is my HTML: <div> &l ...

Do the values returned by window.screen.width and height represent CSS pixels or physical screen pixels?

After exploring the API named screen and visiting this documentation link, my initial anticipation was that I would receive information regarding actual screen size pixels. https://developer.mozilla.org/en-US/docs/Web/API/Screen/width https://i.sstatic.n ...