无法在一条水平线上对齐菜单项

时间:2015-01-02 15:10:57

标签: html css-position

enter image description here

最后一项包含3项,第3项包括第1项和第2项。

我无法找到一种方法让所有物品彼此排成一行,然后在其下面做其他东西



@charset "utf-8";
/* CSS Document */

* {
	padding: 0;
	margin-top: 0px;
	margin-right: 0px;
	margin-left: 0px;
	margin-bottom: 0px;
	font-family: 'Lato', sans-serif;
	box-sizing: border-box;
}

.float-right {
  float: right;
}

.fa {
	font-size: .8em;
	font-family: 'FontAwesome';
	line-height: 22px !important;
	margin-right: 2px;
}

dropdown {
	display: inline-block;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

dropdown label, dropdown ul li {
  display: block;
  width: 200px;
  background: #FFFFFF;
  padding: 15px 20px;
}

dropdown label:hover, dropdown ul li:hover {
  background: #e4703e;
  color: white;
  cursor: pointer;
}

dropdown label {
  color: #e4703e;
  border-left: 4px solid #e4703e;
  position: relative;
  z-index: 2;
}

dropdown input {
  display: none;
}

dropdown input ~ ul {
  position: relative;
  visibility: hidden;
  opacity: 0;
  top: -20px;
  z-index: 1;
}

dropdown input:checked + label {
	background: #e4703e;
	color: white;
}

dropdown input:checked ~ ul {
  visibility: visible;
  opacity: 1;
  top: 0;
}

dropdown ul li:nth-child(1) {
  border-left: 4px solid #E74C3C;
}
dropdown ul li:nth-child(1) .fa {
  color: #E74C3C;
}
dropdown ul li:nth-child(1):hover {
  background: #E74C3C;
  color: white;
}
dropdown ul li:nth-child(1):hover .fa {
  color: white;
}

dropdown ul li:nth-child(2) {
  border-left: 4px solid #0072B5;
}
dropdown ul li:nth-child(2) .fa {
  color: #0072B5;
}
dropdown ul li:nth-child(2):hover {
  background: #0072B5;
  color: white;
}
dropdown ul li:nth-child(2):hover .fa {
  color: white;
}

dropdown ul li:nth-child(3) {
  border-left: 4px solid #2C3E50;
}
dropdown ul li:nth-child(3) .fa {
  color: #2C3E50;
}
dropdown ul li:nth-child(3):hover {
  background: #2C3E50;
  color: white;
}
dropdown ul li:nth-child(3):hover .fa {
  color: white;
}

.animate {
  -webkit-transition: all .3s;
  -moz-transition: all .3s;
  -ms-transition: all .3s;
  -ms-transition: all .3s;
  transition: all .3s;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* Chrome and Safari */
  -moz-backface-visibility: hidden;
  /* Firefox */
  -ms-backface-visibility: hidden;
  /* Internet Explorer */
}
@charset "utf-8";
/* CSS Document */

body {
  margin-top: 180px;
  background-color: #112;
  background-color: #0c2d41;
  font-family: roboto, 'helvetica neue', helvetica, arial, sans-serif;
}
.container {
  width: 800px;
  margin: auto;
}
.row {
  position: relative;
  height: 50px;
  z-index: 1;
  clear: both;
  margin-bottom: 30px;
  text-align: center;
}
.row--intro {
	padding-top: 10px;
	font-size: 16px;
	line-height: 28px;
	font-weight: 300;
	color: #fff;
	opacity: 0.4;
	margin-right: 0px;
}
.row--intro span {
  font-size: 11px;
}
.skew-title {
  font-size: 25px;
}
.skew-title span {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 50px;
  margin: auto;
  z-index: 2;
  text-align: center;
  color: #fff;
  font-family: 'roboto condensed';
  font-weight: 700;
  font-size: 35.714285714285715px;
  line-height: 50px;
  -webkit-transform: skewY(-15deg);
      -ms-transform: skewY(-15deg);
          transform: skewY(-15deg);
  -webkit-transform-origin: 0 100%;
      -ms-transform-origin: 0 100%;
          transform-origin: 0 100%;
  -webkit-transition: all 0.2s;
          transition: all 0.2s;
  cursor: default;
}
.skew-title span:after,
.skew-title span:before {
  display: block;
  top: 0;
  left: 0;
  position: absolute;
  background: #185a81;
  height: 50px;
  width: 40px;
  content: ' ';
  z-index: -1;
  -webkit-transition: all 0.2s;
          transition: all 0.2s;
}
.skew-title span:before {
  background: rgba(0,0,0,0.1);
  -webkit-transform: skewY(15deg);
      -ms-transform: skewY(15deg);
          transform: skewY(15deg);
  -webkit-transform-origin: 0 0;
      -ms-transform-origin: 0 0;
          transform-origin: 0 0;
}
.skew-title span:nth-child(even) {
  background-color: #154e70;
  -webkit-transform: skewY(15deg);
      -ms-transform: skewY(15deg);
          transform: skewY(15deg);
  -webkit-transform-origin: 100% 100%;
      -ms-transform-origin: 100% 100%;
          transform-origin: 100% 100%;
}
.skew-title span:nth-child(even):after {
  background-color: #154e70;
}
.skew-title span:nth-child(even):before {
  -webkit-transform-origin: 100% 0;
      -ms-transform-origin: 100% 0;
          transform-origin: 100% 0;
  -webkit-transform: skewY(-15deg);
      -ms-transform: skewY(-15deg);
          transform: skewY(-15deg);
}
.skew-title span.flat {
  -webkit-transform: skewY(0);
      -ms-transform: skewY(0);
          transform: skewY(0);
}
.skew-title span.flat:before {
  -webkit-transform: skewY(0);
      -ms-transform: skewY(0);
          transform: skewY(0);
}
.skew-title span.flat:nth-child(even):after {
  background-color: #185a81;
}
.skew-title span.alt:after {
  background-color: #b94a2c;
}
.skew-title span.alt:nth-child(even):after {
  background-color: #a14026;
}
.skew-title span.alt.flat:nth-child(even):after {
  background-color: #b94a2c;
}

.blueline {
	color: #326c9c;
}

<!DOCTYPE html>
<html><head>

  <meta charset="UTF-8">

  <title>CodePen - Skewed title text</title>

<link href="http://fonts.googleapis.com/css?family=Roboto:400,300,700" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed:700" rel="stylesheet" type="text/css">
<link href="css/skew.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lato:300,400,700,900" rel="stylesheet" type="text/css">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link href="css/dropdown.css" rel="stylesheet" type="text/css">
</head>

<body>

<div class="container">
	<div id="TitleSlogan">
	  <h1 class="row skew-title"> <span dw_span_id="true">J</span><span dw_span_id="true">O</span><span dw_span_id="true">O</span><span dw_span_id="true">S</span><span dw_span_id="true">T</span><span dw_span_id="true">L</span><span dw_span_id="true">E</span><span class="last" dw_span_id="true">K</span> &nbsp; <span class="alt" dw_span_id="true">T</span><span class="alt" dw_span_id="true">E</span><span class="alt" dw_span_id="true">C</span><span class="alt last" dw_span_id="true">H</span></h1>
	  <p class="row row--intro">Making games since 2014!</p>
	</div>
    <div id="dropdown">
    <dropdown>
		<input id="toggle" type="checkbox">
		<label for="toggle" class="animate">Home<i class="fa fa-home float-right"></i></label>
        	<ul class="animate">
				<li class="animate">Processing<i class="fa fa-leaf float-right"></i></li>
			</ul>
	</dropdown><dropdown>
        <input id="toggle2" type="checkbox">
		<label for="toggle2" class="animate">Games<i class="fa fa-gamepad float-right"></i></label>
			<ul class="animate">
				<li class="animate">@Venture<i class="fa fa-leaf float-right"></i></li>
			</ul>
            
	</dropdown><dropdown>
		<input id="toggle3" type="checkbox">
		<label for="toggle3" class="animate">Coding<i class="fa fa-file-text float-right"></i></label>
			<ul class="animate">
				<li class="animate">Codepen<i class="fa fa-codepen float-right"></i></li>
                <li class="animate">Github<i class="fa fa-github float-right"></i></li>
			</ul>
	</dropdown><dropdown>
		<input id="toggle4" type="checkbox">
		<label for="toggle4" class="animate">Contact Me<i class="fa fa-gamepad float-right"></i></label>
			<ul class="animate">
				<li class="animate">Google+<i class="fa fa-leaf float-right"></i></li>
                <li class="animate">Twitter<i class="fa fa-leaf float-right"></i></li>
                <li class="animate">Steam<i class="fa fa-leaf float-right"></i></li>
			</ul>
	</dropdown></div>
</div>

  <script src="http://assets.codepen.io/assets/libs/fullpage/jquery-ab8e840c3dad7ccf2deadb8c40d53bdb.js"></script>

  <script>
    $('.skew-title').children('span').hover(function() {

  var n = $(this).index();
  n++;
  $(this).addClass('flat');


  if ((n % 2 == 0)) {  
    $(this).prev().addClass('flat');
  } else {
    if (!$(this).hasClass('last')) {
      $(this).next().addClass('flat');
    }  
  }

}, function() {

  $('.flat').removeClass('flat');

});
    //@ sourceURL=pen.js
  </script>



</body></html>
&#13;
&#13;
&#13;

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

尝试将display:inline-block;添加到菜单元素中。

更新:添加vertical-align: top;

答案 1 :(得分:0)

添加显示:内联;作为列表项样式

<ol>
    <li>Games</li>
    <li>Coding</li>
    <li>Contact Me</li>
</ol>

<style>
ol{
padding: 20px; 
list-style-type:decimal;
}
ol li {
display: inline;
margin: 0 10px;
padding: 0 10px;
}
</style>

给出这个结果: enter image description here