css display show code example
Example 1: hide element using css
#tinynav1
{
display:none
}
Example 2: how to show hide div in html javascript
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#myDIV {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: lightblue;
margin-top: 20px;
}
</style>
</head>
<body>
<p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
This is my DIV element.
</div>
<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>
<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
</body>
</html>
Example 3: css block layout
/******************* BASIC BLOCK DISPLAY **********************/
/**************** Block display Elements *********************/
/*Elements that block any other elements from being in the
same line. You can change the width from being the maximum
width of the page, but you can´t put elements side by side */
tag_name {
display: block;
}
/*Exemple of default block display elements:*/
<h1> ... </h1>
<p> ... </p>
/**************** Inline display Elements *********************/
/*They are the type of blocks that only take up the minimum space
required (both in width and height). You can place these types of
blocks side by side (on the same line) but you cannot change their
dimensions */
tag_name {
display: inline;
}
/*Exemple of default inline display elements:*/
<spans> ... </spans>
<img> ... </img>
<a> ... </a>
/************* Inline-block display Elements *****************/
/*They take the best of the two other types above. You can put
elements side by side (on the same line) and you can change this
block width and height */
tag_name {
display: inline-block;
}
/***************** None display Elements ********************/
/*This block will never appear on your webpage and will never
interact with the other elements (it doesn't take up space) */
tag_name {
display: none;
}