width 100% css code example
Example 1: width css property
/* <length> values */
width: 300px;
width: 25em;
/* <percentage> value */
width: 75%;
/* Keyword values */
width: max-content;
width: min-content;
width: fit-content(20em);
width: auto;
/* Global values */
width: inherit;
width: initial;
width: unset;
Example 2: css 100% height
<!DOCTYPE html>
<html>
<head>
<title>100% height</title>
<style>
html,
body {
height: 100%;
margin: 0;
}
.container {
height: 100%;
background: #000;
}
</style>
</head>
<body>
<div class="container"></div>
</body>
</html>
Example 3: width css
/*Based on viewport*/
width: 100vh;
width: 100vw;
Example 4: css width percentage
<div style="background-color:navy;">
<div style="width:50%; margin-left:20%; background-color:chartreuse;">
Width: 50%, Left margin: 20%
</div>
<div style="width:30%; margin-left:60%; background-color:pink;">
Width: 30%, Left margin: 10%
</div>
</div>
Example 5: what does it mean when we write width :100%?
if you specify width:100%, the element's total width will be 100% of its containing block plus any horizontal margin, padding and border
Example 6: default value width
width: auto;