我正在HTML页面的左侧边栏上工作。我的左侧边栏有很少的文字,如果我们点击,那么它们应该下拉并显示其他文本:
这是我的jsfiddle:https://jsfiddle.net/g2ahx6nq/40/
我有以下文字:
因此,如果我点击左侧栏上的任何上述文本,它应该下拉并显示属于他们的其他文本。从技术上讲,它应该像这样的图像:https://s3.postimg.org/gbxn8hkf7/home1.png
正如您在左侧边栏(上图中)所见,上述每个文本的扩展版本。我必须匹配颜色和字体。下面是我的左栏导航的HTML代码,但不知何故,我的点击根本不起作用,也无法匹配字体和大小。我也错过了下拉箭头。
<div id="leftBar">
<br />
<svg id="clippedImg" width="0" height="0">
<clipPath id="clipPolygon">
<polygon points="1 100%,131 100%,130 0,0 0">
</polygon>
</clipPath>
</svg>
<nav>
<ul>
<li class="dropdown">
<a href="#">OUR DNA</a>
<ul class="dropdown-content">
<li><a href="#"><i>RISK</i></a></li>
</ul>
</li>
<li class="dropdown">
<a href="#">PROGRAMS</a>
<ul class="dropdown-content">
<li><a href="#"><i>PROFESSIONAL</i></a></li>
<li><a href="#"><i>ADVENTURE SPORT</i></a></li>
<li><a href="#"><i>ENTERTAINMENT</i></a></li>
<li><a href="#"><i>COLLEGIATE</i></a></li>
<li><a href="#"><i>INDIVIDUAL</i></a></li>
<li><a href="#"><i>COMMERCIAL</i></a></li>
</ul>
</li>
<li class="dropdown">
<a href="#">RESEARCH</a>
<ul class="dropdown-content">
<li><a href="#"><i>CORPORATE SURVEY</i></a></li>
<li><a href="#"><i>INDIVIDUAL SURVEY</i></a></li>
</ul>
</li>
<li class="dropdown">
<a href="#">STORIES</a>
</li>
</ul>
</nav>
</div>
这是我的CSS:
nav ul {
list-style-type:none;
margin:0;
padding:0;
}
nav ul li {
display:inline-block;
position:relative;
}
nav ul li a {
color: #fff;
text-decoration: none;
cursor: pointer;
padding: 10px 20px;
display: block;
width: 80px;
}
nav ul li a:hover {
background: #00648C;
}
ul.dropdown-content {
position: absolute;
display: none;
}
我正在做什么,我的点击不起作用?我们如何才能匹配字体,颜色?
答案 0 :(得分:1)
尝试在css中给出nav ul选择器一个位置和z-index,&#39; top&#39;元素和img位于列表的顶部,因此您不会实际点击列表项。
的CSS:
nav ul {
z-index:10;
position:absolute;
list-style-type:none;
margin:0;
padding:0;
}
我还没有修复列表中的样式问题;)
更新:也尝试添加此
nav{
height:auto;
}
并将此位置更改为相对
ul.dropdown-content {
position: relative; //was absolute
display: none;
}
编辑:进行了其他更改
.dropdown-content li a{
font-size:11px;
}
*{
box-sizing:border-box; //using this on all elements, element size wont change when you set borders. giving a 2px border to a 150px div, the div will remain 150px. Same goes for paddings.
}
nav ul li {
display:inline-block;
position:relative;
width:100%; //makes sure the hover effect is the same width with all Li's
}
nav ul li a{
display:flex;
justify-content:space-between; //spreads the li's text and arrow, arrows on 1 line
}
#leftBar {
background-color: #030303;
box-shadow: 2.996px 0.157px 7.65px 1.35px rgba(40, 40, 41, 0.25);
border-right: solid #EF7440;
border-right-width: 4px;
top: 0px;
bottom: 0px;
left: 0px;
height: 2278px;
position: absolute;
width: 150px; //gives more space for the arrow next to text.
}
答案 1 :(得分:1)
<强>更新强>
试试这个小提琴https://jsfiddle.net/jgf90mh9/18/
$(document).ready(function(){
$(".dropdown a").click(function(){
$(this).closest('.dropdown').find('.dropdown-content').slideToggle(200);
$(this).closest('.dropdown').siblings('.dropdown').find('.dropdown-content').slideUp(200);
});
});
答案 2 :(得分:0)
由于您z-index: 2
设置了#clipimgA1
,因此您的图片会重叠#leftBar
div。您现在无法与#leftBar
进行互动,因为它位于#clipimgA1
的下方,但由于opacity: 0.5
已设置#clipimgA1
,您仍然可以看到它。我在z-index: 2; opacity: 0.5
中对#clipimgA1
进行了评论,现在按预期工作了
$(document).ready(function(){
$(".dropdown").click(function(e){
e.preventDefault();
var $this = $(this).children(".dropdown-content");
$(".dropdown-content:visible").not($this).slideToggle(200); //Close submenu already opened
$this.slideToggle(200); //Open the new submenu
});
});
&#13;
* {
margin: 0px;
}
body {
margin: 0px;
overflow-x: hidden;
}
p,
span,
h1,
h2,
h3,
h4,
h5,
h6,
td,
div,
ul,
li {
margin: 0px;
padding: 0px;
text-decoration: none;
list-style: none;
}
.login {
position: relative;
top: -50px;
z-index: 9999;
color: white;
text-decoration: none;
padding: 0 10px;
font-size: 13px;
}
.signup {
position: relative;
top: -50px;
z-index: 9999;
color: white;
text-decoration: none;
padding: 0;
font-size: 13px;
}
.above {
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
position: relative;
z-index: 9999;
top: -60px;
padding: 0 5px;
}
.fa {
color: white;
margin: 5px;
}
img {
/* Set max width to be 100% of the containing element */
max-width: 100%;
max-height: 100%;
}
body .company-bio p {
font-family: 'agenda';
margin-bottom: 20px;
letter-spacing: .18em;
font-family: 'agenda';
font-weight: 400;
color: rgb(254, 254, 255);
}
div.company-bio {}
body .company-bio {
position: relative;
top: -42px;
padding-top: 40px;
margin-left: 131px;
/*Added Just now */
padding-bottom: 40px;
max-width: 100%;
background: url("https://s30.postimg.org/l04wudgs1/grey-bar.png");
padding-left: 140px;
padding-right: 155px;
font-size: 20px;
font-family: "Adelle PE";
}
.top h1 {
color: #f86d2c;
font-style: italic;
font-size: 37px;
}
.top p {
color: white !important;
background-color: black;
}
.mission-statements .programs {
position: relative;
top: 60px;
width: 300px;
border-style: solid;
border-width: 4px;
text-align: center;
font-size: 19px;
border-color: #EF7440;
padding: 25px;
margin: 25px;
margin-left: auto;
margin-right: auto;
text-shadow: 1.5px 2.598px 7.65px rgba(40, 40, 41, 0.16);
font-family: "adelle regular";
color: rgb(40, 40, 41);
line-height: 1.979;
}
.top h4 {
font-size: 25px;
font-family: "ITC Avant Garde Gothic";
color: rgb(255, 255, 255);
text-transform: uppercase;
line-height: 1.792;
text-align: left;
-moz-transform: matrix( 1.65479981820633, 0, 0, 1.66565153423699, 0, 0);
-webkit-transform: matrix( 1.65479981820633, 0, 0, 1.66565153423699, 0, 0);
-ms-transform: matrix( 1.65479981820633, 0, 0, 1.66565153423699, 0, 0);
position: absolute;
left: 684.247px;
top: 280.77px;
}
.top h2 {
position: absolute;
top: 320px;
left: 450px;
letter-spacing: .3em;
font-size: 22px;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
color: rgb(255, 255, 255);
text-transform: uppercase;
line-height: 1.6;
text-align: center;
text-shadow: 0px 3px 6.37px rgba(40, 40, 41, 0.004);
}
body .northmanwild .title {
/* background-image:url(assets/img/Uploads/insta-pics.png); */
width: 100%;
padding-bottom: 40px;
padding-top: 40px;
text-align: center;
font-size: 37px;
margin-top: 0px !important;
margin-bottom: 0px !important;
font-family: "Adelle PE";
color: rgb(255, 255, 255);
font-weight: bold;
font-style: italic;
line-height: 1.979;
text-align: center;
/*text-shadow: 1.5px 2.598px 7.65px rgba(40, 40, 41, 0.5);
opacity: 100%;
fill: 57%;
*/
}
div.leftBar-bottom {
background-image: url("https://s17.postimg.org/yvv4w2gmn/nav-background.png");
float: left;
}
div.northmanwild {
margin-top: -2px;
width: 90.1%;
float: right;
opacity: 0.8;
margin-bottom: -7px;
}
body .footer {
width: 90.3%;
float: right;
color: rgb(40, 40, 41);
padding-top: 30px;
padding-bottom: 20px;
font-weight: normal;
background-size: 100% 100%;
background-repeat: no-repeat;
background-image: url(assets/img/Uploads/footer-bg.png);
}
/*FIGURE OUT PROBLEM WITH MISSION STATEMENTS*/
body .mission-statements {
margin-left: 131px;
padding-bottom: 130px;
padding-left: 45px;
padding-right: 45px;
background-size: 100% 100%;
background-repeat: no-repeat;
background-image: url(assets/img/Uploads/bg-trees.png);
}
body .mission-statements .why {
padding-top: 40px;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
padding-bottom: 40px;
padding-left: 40px;
position: relative;
left: -40px;
top: 30px;
}
body .mission-statements .how {
padding-top: 40px;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
padding-bottom: 10px;
padding-right: 40px;
}
body .mission-statements .what {
padding-top: 40px;
padding-bottom: 40px;
padding-left: 40px;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
position: relative;
left: -40px;
top: 30px;
}
body .mission-statements .why pre {
padding-left: 40px;
}
body .mission-statements .how {
margin-top: 0px !important;
padding-right: 0px;
margin-bottom: 0px !important;
}
/*.top .imgB1
{
position: relative;
top: -225px;
}
*/
.top {
position: relative;
top: 0;
left: 0;
margin-bottom: -7px;
}
.imgA1 {
position: relative;
top: 0;
left: 0;
}
.clippedmain {
position: absolute;
top: 0;
left: 0;
}
#clippedImg {
position: absolute;
top: 0;
left: 0;
z-index: 2;
}
#clipimgA1 {
/*Chrome,Safari*/
-webkit-clip-path: polygon(1px 100%, 131px 100%, 130px 0px, 0px 0px);
position: absolute;
top: 0;
left: 0;
/*z-index: 2;
opacity: 0.5;*/
}
/*Firefox*/
clip-path: url("#clipPolygon");
/* iOS support inline encoded svg file*/
-webkit-mask: url(data:image/svg+xml;charset=utf-8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIwIiBoZWlnaHQ9IjAiPgogIDxjbGlwUGF0aCBpZD0ic3ZnQ2xpcCI+CiAgICA8cGF0aCBpZD0ic3ZnUGF0aCIgZD0iTTI1LDI1MCBMNzAsMjUwIDcxLDI4NSAyNjAsMjg1IDI2MSwyNTAgMTYwLDI1MCAxNjAsMTE1IDIyNSwxMTUgMjI1LDkwIDE2MCw5MCAxNjAsNzAgMjUsNzAgeiIvPgogIDwvY2xpcFBhdGg+CiAgPHBhdGggaWQ9InN2Z01hc2siIGQ9Ik0yNSwyNTAgTDcwLDI1MCA3MSwyODUgMjYwLDI4NSAyNjEsMjUwIDE2MCwyNTAgMTYwLDExNSAyMjUsMTE1IDIyNSw5MCAxNjAsOTAgMTYwLDcwIDI1LDcwIHoiICAvPgo8L3N2Zz4=) no-repeat;
}
.imgB1 {
position: absolute;
top: -65px;
left: 70px;
}
.footer .footer-section1 {
float: left;
width: 33%;
}
.footer .footer-section2 .block-title {
position: relative;
width: 338px;
left: -140px;
font-size: 16px !important;
font-family: "AvantGarde";
color: rgb(40, 40, 41);
/* font-style: italic; */
letter-spacing: 4px;
border-bottom: 2px solid #000000;
}
.footer .footer-section2 .block-content {
font-style: italic;
line-height: 1.52;
top: 18px;
left: 52px;
position: relative;
}
.footer .footer-section3 .block-content {
position: relative;
line-height: 1.52;
left: 12px;
letter-spacing: 4px;
top: 15px;
font-style: italic;
}
.footer .footer-section3 .block-title {
border-bottom: 2px solid #000000;
width: 60%;
left: 14px;
position: relative;
}
.footer .footer-section1 .block-content {
position: relative;
line-height: 1.52;
top: 67px;
left: 125px;
font-style: italic;
}
.footer .footer-section2 {
position: relative;
left: -89px;
}
.footer .footer-section2 {
float: left;
width: 33%;
}
.footer .footer-section3 {
float: left;
width: 33%;
}
.scroll-down {
opacity: 1;
-webkit-transition: all .5s ease-in 3s;
transition: all .5s ease-in 3s;
}
.scroll-down {
position: absolute;
bottom: 28px;
left: 55%;
margin-left: -16px;
display: block;
width: 32px;
height: 32px;
background-size: 14px auto;
border-radius: 50%;
z-index: 2;
-webkit-animation: bounce 2s infinite 2s;
animation: bounce 2s infinite 2s;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
}
.scroll-down:before {
position: absolute;
top: calc(50% - 8px);
left: calc(50% - 6px);
transform: rotate(-45deg);
display: block;
width: 12px;
height: 12px;
content: "";
border: 2px solid white;
border-width: 0px 0 2px 2px;
}
section.ok {
position: relative;
top: 2000px;
}
.copy-rights {
font-size: 16px;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
position: relative;
top: 48px;
display: block;
font-size: 12px;
text-align: center;
color: rgb(40, 40, 41);
font-style: italic;
-moz-transform: matrix( 0.99963252426166, 0, 0, 0.99882633931212, 0, 0);
-webkit-transform: matrix( 0.99963252426166, 0, 0, 0.99882633931212, 0, 0);
-ms-transform: matrix( 0.99963252426166, 0, 0, 0.99882633931212, 0, 0);
font-style: normal;
}
#leftBar {
/*background-color: #030303;*/
box-shadow: 2.996px 0.157px 7.65px 1.35px rgba(40, 40, 41, 0.25);
border-right: solid #EF7440;
border-right-width: 4px;
top: 0px;
bottom: 0px;
left: 0px;
height: 2278px;
position: absolute;
width: 131px;
/*Commented today */
/* opacity: 0.5; */
}
/*
#holder {
width: 700px;
margin-left: 263px;
padding-left: 50px;
margin-top: 10px;
height: 100%;
float: right;
position: fixed;
}
*/
@font-face {
font-family: BEBAS;
src: url("http://webdesigncove.com/fonts/BEBAS___.ttf")
}
h1.logo {
font-size: 26px;
font-style: normal;
font-weight: normal;
letter-spacing: normal;
text-transform: uppercase;
line-height: 1.2em;
letter-spacing: -3px;
color: white;
text-align: center;
padding-top: 10px;
}
h1.postTitle {
font-family: BEBAS, Helvetica, Verdana, Sans-Serif;
}
p {
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-style: normal;
font-weight: normal;
letter-spacing: .28em;
line-height: 1.45em;
}
#navigation {
padding: 0;
margin: 0;
text-align: center;
position: relative;
z-index: 3;
}
#navigation li {
list-style-type: none;
margin-bottom: 5px;
}
#navigation a:link {
font-family: "ITC Avant Garde Gothic";
font-size: 15px;
font-style: normal;
}
#navigation a:visited {
color: rgb(255, 255, 255);
}
#navigation a:hover {
color: #FE5B1F;
}
.copy-right-text {
font: Bold 12px 'Open Sans';
color: #ffffff;
padding-top: 10px;
text-align: center;
}
nav ul {
list-style-type:none;
margin:0;
padding:0;
}
nav ul li {
display:inline-block;
position:relative;
}
nav ul li a {
color: #fff;
text-decoration: none;
cursor: pointer;
padding: 10px 20px;
display: block;
width: 80px;
}
nav ul li a:hover {
background: #00648C;
cursor: pointer;
}
ul.dropdown-content {
/*position: absolute;*/
display: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="top">
<img id="clipimgA1" class="clippedmain" src="https://s28.postimg.org/tkwg9tmdp/homepage-image-1.png" alt="img">
<img class="imgA1" src="https://s28.postimg.org/tkwg9tmdp/homepage-image-1.png">
</div>
<div id="leftBar">
<br />
<svg id="clippedImg" width="0" height="0">
<clipPath id="clipPolygon">
<polygon points="1 100%,131 100%,130 0,0 0">
</polygon>
</clipPath>
</svg>
<nav>
<ul>
<li class="dropdown">
<a href="#">OUR DNA</a>
<ul class="dropdown-content">
<li><a href="#"><i>RISK</i></a></li>
</ul>
</li>
<li class="dropdown">
<a href="#">PROGRAMS</a>
<ul class="dropdown-content">
<li><a href="#"><i>PROFESSIONAL</i></a></li>
<li><a href="#"><i>ADVENTURE SPORT</i></a></li>
<li><a href="#"><i>ENTERTAINMENT</i></a></li>
<li><a href="#"><i>COLLEGIATE</i></a></li>
<li><a href="#"><i>INDIVIDUAL</i></a></li>
<li><a href="#"><i>COMMERCIAL</i></a></li>
</ul>
</li>
<li class="dropdown">
<a href="#">RESEARCH</a>
<ul class="dropdown-content">
<li><a href="#"><i>CORPORATE SURVEY</i></a></li>
<li><a href="#"><i>INDIVIDUAL SURVEY</i></a></li>
</ul>
</li>
<li class="dropdown">
<a href="#">STORIES</a>
</li>
</ul>
</nav>
</div>
<ul class="above">
<li><i class="fa fa-facebook-square"></i></li>
<li><i class="fa fa-twitter-square"></i></li>
<li><i class="fa fa-instagram"></i></li>
</ul>
<a class="login" href="#">Log In |</a>
<a class="signup" href="#">Sign Up</a>
<div class="leftBar-bottom">
</div>
<!-- End Side bar div-->
<div class="company-bio">
<p align="center" style="font-family: Adelle PE">Hello World </p>
<p align="center" style="font-family: Adelle PE">Nice Text! </p>
<p align="center">Hello David</p>
</div>
&#13;
更新:我已从
评论position: absolute
ul.dropdown-content {
/*position: absolute;*/
display: none;
}
它立即实现了你想要的效果