我的页面左侧有一个垂直菜单 div,底部有 6 个链接和一个图像。链接的样式为框。我希望能够使用 JS 来更改链接框的边距,以便它们填充高度但不会以较小的分辨率消失。这是我尝试过的没有效果。
这是CSS
.sidebar {
float: left;
background-color:#FFFFFF;
background-image: url('../images/sandMenu1.jpg');
width: 150px;
min-height: 100vh;
color: #04B4AE;
margin-top: 50px;
background-size: 100%;
background-repeat: no-repeat;
background-position: left top;
z-index: 1;
padding-top: 35px;
position: fixed;
}
#sidebarLink a:link, a:visited{
display: inline-block;
font-weight: bold;
background-color: #D7F5BA;
color: #04B4AE;
width: 90px;
padding: 4px;
border-style: outset;
border-width: 2px;
border-color: #D8D8D8;
margin-top: 35px;
margin-bottom: 35px;
margin-right: 30px;
float: right;
}
#sidebarLink a:hover, a:active, a:focus{
font-weight: bold;
background-color: #B404AE;
color: #04B4AE;
width: 90px;
padding: 4px;
border-style: outset;
border-width: 2px;
border-color: #6A0888;
margin-top: 35px;
margin-bottom: 35px;
margin-left: 15px;
margin-right: 30px;
float: right;
}
.sidebarLinkList li {
list-style-type: none;
margin: 0;
padding: 0;
}
这是HTML。
<div id="sideMenu" class="sidebar">
<nav id="sidebarLink">
<ul class="sidebarLinkList">
<li><a href="home.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="link.html">link</a></li>
<li><a href="Destination.html">Destination</a></li>
<li><a href="homepage.html">Home</a></li>
<li><a href="homepage.html">Home</a></li>
</ul>
</nav>
<div>
<img src="images/sand.jpg" class="sand" id="sidePic">
</div>
</div>
<script>
var winHeight = $(window).height();
var winWid = $(window).width();
var spacing = 0;
var menuHeight = 0;
menuHeight = (winHeight - 280); /*header height+image height+image margin = 280px*/
spacing = (menuHeight - (6 * 25))/12; /*links are ~25px tall*/
document.getElementById("sidebarLink").style.marginTop=spacing+"px";
document.getElementById("sidebarLink").style.marginBottom=spacing+"px";
</script>
我愿意接受任何建议,我不打算使用 Javascript 来做到这一点。谢谢你。