Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a <li> item in html and make it not occupy any space?

Tags:

html

hidden

I have an html list like this:

<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>

How can I hide a li item and make it not occupy any space? Let's say, I need the first li item (coffee) to be invisible, so the result will contain only Tea and Milk. I used css (or style="visibility: hidden"), but it still occupies some space.

=======

Note: the first li is just some template used to create the other li items. The template li is generated during the run time, and that's why I need to hide it. I remove it eventually after generating the other li items (Tea and Milk), but before I generate Tea and Milk, Coffee is still visible.

============

Thanks. Answer is style="display:none"

like image 227
Simo Avatar asked Sep 24 '15 21:09

Simo


People also ask

How do you make the hidden element not take up space?

Look, instead of using visibility: hidden; use display: none; . The first option will hide but still takes space and the second option will hide and doesn't take any space.

How do I hide a list item in HTML?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <li> element is not visible, but it maintains its position on the page. Removing the hidden attribute makes it re-appear.

How would you hide an element on a webpage so it doesn't take space in the flow of the page but is still present in code?

visibility: hidden means it will be hidden, BUT will remain in the flow of the website. Essentially, visibility: hidden will not show the element, but will retain the space it takes up. Whereas display: none completely removes it.

Which property is used to hide an element without using any space on the page?

The visibility CSS property shows or hides an element without changing the layout of a document.


1 Answers

Create a class and apply it to elements which you wish to hide. You can do it when you generate markup or add the class to each element using a selector, like jquery

.hide{
  display:none;  
}
<ul>
  <li class="hide">Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>
like image 111
Vu Nguyen Avatar answered Sep 20 '22 11:09

Vu Nguyen