中打开html文档我一直在尝试为自己构建一个个人网站,我已经构建了骨架。我的页面左侧有导航按钮,类别为.main
的内容区域。我想这样做,当点击一个按钮时,内容会加载到.main
div中。我不知道如何解决这个问题,因此任何对解决方案的投入都会得到应用。下面是我到目前为止的html和css代码。
CSS:
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, caption {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
html{
height: 100%;
width:100%;
}
body{
position: fixed;
background-color: #000000;
background-image: url(../images/background-lights1.jpg);
background-position: center;
background-size: contain;
background-repeat: no-repeat;
font-family: 'Asar', serif;
position: relative;
width: 100%;
overflow: hidden;
}
header{
position: fixed;
width: 100%;
height:75px;
}
aside{
position: fixed;
background-color: #000000;
width: 150px;
height: 550px;
border-bottom: 1px solid #FEB41C;
}
#buttons li{
position: relative;
list-style: none;
text-align: center;
background-color: #000000;
line-height: 60px;
padding: 38px 0 38px 0;
width: 150px;
border-top: 1px solid #3E474F;
}
#buttons li a{
text-decoration: none;
color: #FFFFFF;
padding: 3px;
transition: all 0.3s ease 0s;
}
#buttons li a:hover{
text-decoration: none;
border-bottom: 5px solid #FFFFFF;
padding: 20px;
color: #FEB41C;
}
#myPicture{
display: block;
height: 150px;
width: 150px;
border: 2px solid #FEB41C;
border-radius: 100%;
margin: 5px auto 5px auto;
}
.main{
background: linear-gradient(#849696, #FEFFFB);
height: 550px;
width: 100%;
border-top: 1px solid #FEB41C;
border-bottom: 1px solid #FEB41C;
overflow: hidden;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/limit-dne.css">
<link href='https://fonts.googleapis.com/css?family=Asar' rel='stylesheet' type='text/css'>
<script src="js/jquery.js"></script>
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<title>The Limit Does Not Exist</title>
<header>
<img src="images/Dion.jpg" id="myPicture" alt="A picture of the site creator">
</header>
</head>
<body>
<div class="main">
<aside>
<ul id="buttons">
<li><a href="index.html">HOME</a></li>
<li><a href="portfolio.html">PORTFOLIO</a></li>
<li><a href="blog.html">BLOG</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</aside>
</div>
<script>
</script>
</body>
</html>
CSS:
答案 0 :(得分:1)
JavaScript:你可以用一些简单的jQuery来做到这一点。例如:
var i = false;
$(document).ready(function() {
$('#home').click(function(){
if (i == false) {
$('#home_content').css("display","block");
i = true;
} else {
$('#home_content').css("display","none");
i = false;
};
});
});
HTML:
<div class="main">
<aside>
<ul id="buttons">
<li id="home"><a href="index.html">HOME</a></li>
<div id="home_content" style="display: none"></div>
<li><a href="portfolio.html">PORTFOLIO</a></li>
<li><a href="blog.html">BLOG</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</aside>
</div>