admin管理员组文章数量:1418065
I have defined styles for <li>
#mainNav{clear:both;background-image: url(../images/bg_menu.jpg);width:975px;height:43px;color:#fff;margin-top:-25px;}
#mainNav ul{list-style: none;padding: 0;margin: 0;}
#mainNav ul li{line-height:43px;float:left;background-image: url(../images/bg_menu.jpg);font-size:15px;font-weight:normal;text-align:center;cursor:default;padding:0px 15px;}
#mainNav ul li:hover{background:#332a03;color:#f7df84;}
<div id="mainNav">
<ul>
<li>Home</li>
<li>Training and Workshops</li>
<li>Community Consultations</li>
<li>Community Surveys</li>
<li>Program and Facility Assesments</li>
<li>Reports</li>
</ul>
</div>
I now want to go back and change the padding for the <li>
to '0px 14px' because for some reason it doesn't render right only on Firefox on Mac. So I have this script so far...
var browser = "other";
var OpSys = "other";
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
browser = "Firefox";
}
if (navigator.userAgent.indexOf('Win') != -1) {
OpSys = "Macintosh";
}
// if its a Mac and Firefox, then change the padding
if (OpSys == "Macintosh" && browser == "Firefox") {
// how do I change the padding for each <li> ?
}
I have defined styles for <li>
#mainNav{clear:both;background-image: url(../images/bg_menu.jpg);width:975px;height:43px;color:#fff;margin-top:-25px;}
#mainNav ul{list-style: none;padding: 0;margin: 0;}
#mainNav ul li{line-height:43px;float:left;background-image: url(../images/bg_menu.jpg);font-size:15px;font-weight:normal;text-align:center;cursor:default;padding:0px 15px;}
#mainNav ul li:hover{background:#332a03;color:#f7df84;}
<div id="mainNav">
<ul>
<li>Home</li>
<li>Training and Workshops</li>
<li>Community Consultations</li>
<li>Community Surveys</li>
<li>Program and Facility Assesments</li>
<li>Reports</li>
</ul>
</div>
I now want to go back and change the padding for the <li>
to '0px 14px' because for some reason it doesn't render right only on Firefox on Mac. So I have this script so far...
var browser = "other";
var OpSys = "other";
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
browser = "Firefox";
}
if (navigator.userAgent.indexOf('Win') != -1) {
OpSys = "Macintosh";
}
// if its a Mac and Firefox, then change the padding
if (OpSys == "Macintosh" && browser == "Firefox") {
// how do I change the padding for each <li> ?
}
Share
Improve this question
edited Feb 5, 2010 at 19:10
Andy E
345k86 gold badges481 silver badges451 bronze badges
asked Feb 5, 2010 at 17:31
HristoHristo
46.7k67 gold badges168 silver badges234 bronze badges
1 Answer
Reset to default 2Using jQuery:
jQuery("div#mainNav li").each(function() {
var $li = jQuery(this);
$li.css("padding", "0px 14px 0px 0px");
});
Without jQuery:
var liArr = document.getElementsByTagName("LI");
for(var i = 0; i < liArr.length; i++) {
var parent = liArr[i].parentNode;
var grandParent = parent.parentNode;
if(grandParent != null && grandParent.id == "mainNav") {
liArr[i].style.padding = "0px 14px 0px 0px";
}
}
本文标签: use javascript to change ltligt styleStack Overflow
版权声明:本文标题:use javascript to change <li> style - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745250544a2649798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论