The expected outcome of the value display in CSS is not being achieved as anticipated

Here is some HTML code:

<!DOCTYPE html>
<html>
    <head>
        <title>Testing Page</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <h1 class="hidden">Hello World</h1>
    </body>
</html>

This is the CSS code:

.shown {
    display: hidden;
}

After running this code, the heading is still visible. Why is that? I expected the 'display: hidden' property to hide the element from view on the page's normal flow.

Answer №1

concealed is not a valid value for display, you are looking for none. Also, your class name is incorrect, it should be .hidden

.invisible{
    display: none;
}

Additionally, there is another attribute known as visibility that conceals content with visibility: hidden. The distinction lies in the fact that display makes it seem like the element has been completely eradicated from the page, whereas visibility causes the content to vanish while still acknowledging the space occupied by the element.

Answer №2

It appears there has been a mix-up with the values of two distinct CSS properties: visibility and display.

display

.class_name
{
    display:none;
}

When the display property is set to none, the element becomes invisible and does not take up any space in the layout.

visibility

.class_name
{
    visibility:hidden;
}

On the other hand, when the visibility property is set to hidden, the element remains invisible but still occupies the space it needs within the layout.

Source

Answer №3

incorrect class, please use the following:

<h1 class="visible">Greetings Earthlings</h1>

along with this css:

.visible {
    visibility: hidden;
}

Answer №4

Implement

.hidden{
    visibility: hidden;
}

Answer №5

Employ

.visible {
  display: none;
}

or

 .visible {
  visibility: hidden;
}

Answer №6

The naming of your CSS class does not match with the HTML code provided, causing a mismatch. Additionally, there are errors in your CSS syntax.

To hide elements, consider using either display: none or visibility: hidden in your CSS style rules.

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

Arranging links in a horizontal line (JSFiddle)

CodePen: https://codepen.io/example/abc123 I am attempting to align the elements "Favourite", "0", and "Reply" next to each other so they appear as: Favourite 0 Reply ...

Query CSS to target an empty array within the .data() method

I have a scenario where I am storing an array in a button using Jquery's .data() method. If the array happens to be empty, I want the button to appear in red color. How can I target the button with an empty array using CSS? var values1 = []; var ...

Embed the website onto a webpage using ajax or an iframe without any need for navigation

I have a unique challenge ahead. Imagine there are two websites, one is a web page and the other is hosted within the same domain. My goal is to load the entire second website into a div or iframe of the first web page, similar to how a free proxy browser ...

A step-by-step guide on how to refresh a circular loading indicator

I have been researching how to create a circular progress bar using canvas, and I came across this code. After making some modifications to the code snippets that I found online, I encountered an issue - I can't seem to reload the circular path once i ...

Is there a way to collapse multiple blocks at once using just one button?

I have multiple hidden blocks that I want to reveal simultaneously by clicking one button. I am using bootstrap 4 alpha 6. The issue is that when I click the button, only the first block opens. I can't use IDs in the data-target attribute because the ...

Undefined jQuery was encountered on the object when using the appropriate selector

Having a jQuery issue with the following HTML code snippet: <div class="side-finder"> <div class="brand"><img src="/img/test.net-logo.png" /></div> <div class="finder-content"> <ul class="nav nav-pills nav-stacked" id= ...

Angular text input with customizable placeholder text and embedded icon

Hey there, I'm looking to create a unique custom textbox that includes a text placeholder and a help icon that will display useful information in a popover. https://i.sstatic.net/Zh0IK.png When typing into the input, the textbox should have a specif ...

What is the best way to ensure that two checkboxes are mandatory out of a total of three in

<input type="checkbox" name="Package1" value="packagename"> <input type="checkbox" name="Package2" value="packagename"> <input type="checkbox" name="Package3" value="packagename"> Is there a way to require the user to select at least t ...

Having trouble vertically aligning text? Combining AngularJS, Bootstrap, and Flexbox can help!

I have spent a lot of time trying to understand why I am unable to vertically align the text inside these cells. I have tried multiple solutions: align-items: center; vertical-align: middle; justify-content: center; justify-items: center; Unfortunately, ...

Javascript retrieve the style of an element in every possible state

I am interested in retrieving the line height of an element; it's a simple task. Here is a method that I know works: console.log(document.getElementById("myDiv").style.lineHeight); console.log($("#myDiv").css('lineHeight')) ...

The checkbox is failing to display as checked even after its value has been dynamically set to true

Currently, I am immersed in a project within ASP.NET MVC that involves displaying data on a page where users can interact by selecting checkboxes to make changes. In cases where there are numerous checkboxes present, a "Select all Checkboxes" button become ...

Issue with checkboxes preventing submission of form

Currently working on a website project for a company that requires certain steps to be completed for deliveries. Unfortunately, I am facing issues with the submit button, and I apologize as I am still new to this. The code I have pasted is divided into tw ...

Design a dynamic pagination button for my project that allows users to navigate between pages effortlessly

Can anyone assist me in creating next and previous buttons? I've been struggling with my JavaScript skills. I noticed that many people use jQuery or pure JavaScript for this. Since I'm still learning JavaScript, there are a lot of concepts I&apos ...

What is the best way to link a single post to a collection of posts?

I am currently working on building a basic blog using PHP. My goal is to create a link from a post to a list of all posts on the blog, similar to the example shown below: Example of how I plan to display posts and a post viewer There are two distinct par ...

Reposition various div elements within a static container

Struggling to align div boxes like the image below was exhausting: I attempted fixing it with the code provided in this JSBIN link. How can I resolve the issue and adjust the layout as desired? Any help would be greatly appreciated. Thank you in advance ...

Troubles encountered when wrapping columns in bootstrap framework

I'm experimenting with a design that utilizes Bootstrap's grid system, but I'm experiencing some challenges with the content either wrapping or extending off-screen. What I want is to have a sidebar with fixed width (around 250px), and its a ...

Resolving problems related to window scrolling in javascript for implementing a "sliding door" style animation triggered by a scroll event

I am new to web development and I have been working on creating a portfolio website to learn. I have seen some websites with really cool effects on their landing pages and I would like to incorporate something similar into my site. Specifically, I am inte ...

Utilize various CSS styles for individual sections within a multi-page website

Having a web page with multiple subpages each having their own specific CSS can be quite challenging. Sometimes, when all the CSS files are applied globally, they tend to mix with each other causing a headache for developers. One common approach is to decl ...

a label placed in a random location on the webpage

I am experiencing an issue on our website that uses a WordPress theme called Flat. Whenever we add a new page, there is an 'a' tag that appears to surround the entire page. This tag is not visible in the editor, leading me to believe it is being ...

Grouping Columns in an HTML Table using Angular 4

I'm currently faced with the task of retrieving flat data from an API and presenting it in an HTML table using Angular 4. I'm a bit unsure about how to iterate over the data, possibly using a for-each loop. I have attempted to utilize ngFor but I ...