html - Set height of <li> based of div height -
hope can me. trying create navigation variable amount of list elements. want automatically set height of list elements based on height of surrounding div element, , number of list elements in div. there way so, or can other way around, not giving div height value, rather give list elements fixed height?
hope can me.
#nav ul{ margin: 0; padding: 0; list-style: none; } #nav{ margin-top: 30px; width: 19%; background-color: red; float:left; border-top: 1px solid black; } #nav ul li{ text-align: center; width: 100%; background-color: yellow; height: 50px; margin-top: 20px; line-height: 50px; border-bottom: 1px solid black; border-left: 1px solid black; transform: rotate(20deg); }
you can use below code,it work
<!doctype html> <html> <head> <meta charset="iso-8859-1"> <title>insert title here</title> </head> <body> <div id="change" style="height:200px;border:1px solid black"> <ul> <li>hi</li> <li>hello</li> <li>bye</li> <li>byesdfsd</li> <li>sdfsd</li> <li>sdfsd</li> </ul> </div> <script> var height=document.getelementbyid("change").style.height; height=height.replace("px",""); var lis=document.getelementsbytagname("li"); for(var i=0;i<lis.length;i++){ lis[i].style.height=(parseint(height))/(parseint(lis.length))+"px"; console.log("getting height "+lis[i].style.height); } </script> </body> </html>
- so can give height of div in class or in inline style,but have change code accordingly in js part fetching height of div.
- i have got li tags , depending on number have divided height of enclosing div number of list tags
Comments
Post a Comment