居中100%宽度<ul>

时间:2016-12-03 09:16:08

标签: html css

最近我已经制作了导航按钮,可以在点击时切换下拉菜单,不幸的是我用px单位制作它们,结果菜单在放大到{{1}时会保持不变} width,因为我已经完成它以适合2000px宽度的中心。

我也认为我已经把它变得非常硬编码并且很难调查,所以我会解释重要的部分。

说明:

首先,我没有使用1200px容器启动菜单,我用div直接启动它:

ul

然后在这个<ul class="down-bar" style="list-style:hidden">里面我创建了ul容器,其中包含3个元素:

<div class="dropdown">

另请注意,<ul class="down-bar" style="list-style:hidden"> <div class="dropdown"> <input type="checkbox" value="drop" id="drop-1" class="dropper"> <li><label class="down-nav" id="down-nav-1" for="drop-1" style="text-decoration:none">Knives <b class="caret"> &#9660;</b></label></li> <div class="dropdown-menu"> <a href="#" class="Text1"><label class="m9_bayonet" style="width:30px;height:30px;position:absolute;top:5px;left:5px;cursor:pointer;"></label>M9 Bayonet</a> <a href="#" class="Text1"><label class="karambit" style="width:30px;height:30px;position:absolute;left:5px;top:59px;cursor:pointer;"></label>Karambit</a> <a href="#" class="Text1"><label class="bayonet" style="width:30px;height:30px;position:absolute;left:5px;top:116px;cursor:pointer;"></label>Bayonet</a> <a href="#" class="Text1"><label class="butterfly" style="width:30px;height:30px;position:absolute;left:5px;top:170px;cursor:pointer;"></label>Butterfly Knife</a> <a href="#" class="Text1"><label class="flip" style="width:30px;height:30px;position:absolute;left:5px;top:225px;cursor:pointer;"></label>Flip Knife</a> <a href="#" class="Text1"><label class="falchion" style="width:30px;height:30px;position:absolute;left:5px;top:280px;cursor:pointer;"></label>Falchion Knife</a> <a href="#" class="Text1"><label class="gut" style="width:30px;height:30px;position:absolute;left:5px;top:334.5px;cursor:pointer;"></label>Gut Knife</a> <a href="#" class="Text1"><label class="shadow" style="width:30px;height:30px;position:absolute;left:5px;top:390px;cursor:pointer;"></label>Shadow Daggers</a> <a href="#" class="Text1"><label class="huntsman" style="width:30px;height:30px;position:absolute;left:5px;top:444px;cursor:pointer;"></label>Huntsman Knife</a> <a href="#" class="Text1"><label class="bowie" style="width:30px;height:30px;position:absolute;left:5px;top:498.5px;cursor:pointer;"></label>Bowie Knife</a> </div> </div> 课程仅用于测试,我不会使用它。

所以这是单个导航的css和html的结果:

&#13;
&#13;
Text1
&#13;
.down-bar {
  position: absolute;
  display: block;
  z-index: 1;
  list-style-type: none;
  top: 39px;
  margin: none;
  padding: none;
  background-color: black;
  height: 55px;
  min-width: 1200px;
  width: 100%;
  padding: 0px 0px 0px 12.5%;
}
.down-nav {
  display: block;
  position: absolute;
  z-index: 1;
  font-size: 105%;
  top: 17px;
  left: 200px;
  color: white;
  font-family: 'Lato';
  cursor: pointer;
  transition: all 0.1s ease;
  -moz-transition: all 0.1s ease;
}
.down-nav:hover {
  color: white;
  border: solid 3px gray;
  background-color: gray;
  border-radius: 10px;
  font-family: 'Lato';
}
.down-nav li {
  display: inline-block;
}
.caret {
  font-size: 20%;
}
.dropdown {
  display: inline-block;
  float: left;
  padding-top: 0em;
  transition: 0.1s ease-in;
  margin-top: 53.4px;
  white-space: nowrap;
}
.dropdown-menu {
  position: absolute;
  display: none;
  left: 200px;
  width: 164px;
  background-color: black;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 99;
  list-style-type: none;
  transition: 0.1s ease-in;
}
.dropdown-menu a {
  color: white;
  text-align: center;
  font-size: 0.9em;
  padding: 8% 0px 15% 0%;
  padding-right: 10%;
  text-decoration: none;
  display: block;
  list-style-type: none;
  white-space: nowrap;
  margin-left: 0%;
  text-indent: 4%;
  font-family: 'Lato';
}
.dropdown-menu a:hover {
  background-color: gray;
}
.dropper {
  display: none;
  visibility: hidden;
}
#drop-1:checked ~ .dropdown-menu {
  display: block;
  z-index: 99;
}
#drop-1:checked ~ li #down-nav-1 {
  border: solid 3px gray;
  background-color: gray;
  border-radius: 10px;
}
&#13;
&#13;
&#13;

代码:

所有7个导航按钮都是相同的,你可以看到完整的网站here(请尝试按比例缩小和向上,同时请确保我为jsfiddle兼容性更改了一些内容,<ul class="down-bar" style="list-style:hidden"> <div class="dropdown"> <input type="checkbox" value="drop" id="drop-1" class="dropper"> <li><label class="down-nav" id="down-nav-1" for="drop-1" style="text-decoration:none">Knives <b class="caret"> &#9660;</b></label></li> <div class="dropdown-menu"> <a href="#" class="Text1"><label class="m9_bayonet" style="width:30px;height:30px;position:absolute;top:5px;left:5px;cursor:pointer;"></label>M9 Bayonet</a> <a href="#" class="Text1"><label class="karambit" style="width:30px;height:30px;position:absolute;left:5px;top:59px;cursor:pointer;"></label>Karambit</a> <a href="#" class="Text1"><label class="bayonet" style="width:30px;height:30px;position:absolute;left:5px;top:116px;cursor:pointer;"></label>Bayonet</a> <a href="#" class="Text1"><label class="butterfly" style="width:30px;height:30px;position:absolute;left:5px;top:170px;cursor:pointer;"></label>Butterfly Knife</a> <a href="#" class="Text1"><label class="flip" style="width:30px;height:30px;position:absolute;left:5px;top:225px;cursor:pointer;"></label>Flip Knife</a> <a href="#" class="Text1"><label class="falchion" style="width:30px;height:30px;position:absolute;left:5px;top:280px;cursor:pointer;"></label>Falchion Knife</a> <a href="#" class="Text1"><label class="gut" style="width:30px;height:30px;position:absolute;left:5px;top:334.5px;cursor:pointer;"></label>Gut Knife</a> <a href="#" class="Text1"><label class="shadow" style="width:30px;height:30px;position:absolute;left:5px;top:390px;cursor:pointer;"></label>Shadow Daggers</a> <a href="#" class="Text1"><label class="huntsman" style="width:30px;height:30px;position:absolute;left:5px;top:444px;cursor:pointer;"></label>Huntsman Knife</a> <a href="#" class="Text1"><label class="bowie" style="width:30px;height:30px;position:absolute;left:5px;top:498.5px;cursor:pointer;"></label>Bowie Knife</a> </div> </div>没有必要那里。)。

问题:

我可以做些什么来集中我的导航?做有什么比较好的方式吗?谢谢! (Full Code

0 个答案:

没有答案