html - 顶部导航元素未居中

标签 html css

我试图将我的链接居中,但因为我在每个 Angular 落都有社交图标,所以它似乎没有居中。我得出这个结论是因为箭头的左或右位置相同。我怎样才能做到这一点。可以在这里看到实际的代码:

http://95.85.11.40/topnav/

html:

  <header>
    <nav>
      <div class="container">

        <img class="logoimage" src="css/img/messages.png">
    <img class="arrowleft" src="css/img/arrow-left.png">
    <ul>
      <li class="yellow"><a href="index.html">Firefox</a></li>
      <li class="green"><a href="index.html">Chrome</a></li>
      <li class="active"><a href="index.html">Safari</a></li>
      <li class="red"><a href="index.html">Opera</a></li>
      <li class="purple"><a href="index.html">Internet Explorer</a></li>
    </ul>

    <img class="arrowright" src="css/img/arrow-right.png">
                <img class="twitterlink" src="css/img/twitter_32.png">
                <img class="facebooklink" src="css/img/facebook_32.png">





      </div>
    </nav>
  </header>

CSS:

div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, 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,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
  display: block;
}

body {
  line-height: 1;
    margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

ol, ul {
  list-style: none;
}

blockquote, q {
  quotes: none;
}

blockquote:before, blockquote:after,
q:before, q:after {
  content: '';
  content: none;
}

.logoimage {
  height: 36px;
position: absolute;
left: 10px;
}

.facebooklink {
  height: 36px;
position: absolute;
margin-top: 4px;
right: 45px;
height: 28px;
width: 28px;
}

.twitterlink {
  height: 36px;
position: absolute;
margin-top: 4px;
right: 10px;
height: 28px;
width: 28px;
}

.arrowright {
  height: 36px;
position: absolute;
margin-top: 4px;
right: 400px;
height: 28px;
width: 28px;
}

.arrowleft {
  height: 36px;
position: absolute;
margin-top: 4px;
left: 400px;
height: 28px;
width: 28px;
}



body {
  font: 13px/18px 'Lucida Grande', Tahoma, Verdana, sans-serif;
  color: #404040;
  background: #ecedef;
}

.container {
  margin: 0 auto;
  width: 540px;
}



nav {
  height: 36px;
  background: #464b4c;
  border-top: 1px solid #353939;
  border-bottom: 1px solid #2e3131;
  background-image: -webkit-linear-gradient(top, #464b4c, #3f4344);
  background-image: -moz-linear-gradient(top, #464b4c, #3f4344);
  background-image: -o-linear-gradient(top, #464b4c, #3f4344);
  background-image: linear-gradient(to bottom, #464b4c, #3f4344);
  -webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.06);
}
nav a {
  -webkit-transition: 0.1s ease-out;
  -moz-transition: 0.1s ease-out;
  -o-transition: 0.1s ease-out;
  transition: 0.1s ease-out;
  -webkit-transition-property: background-color, line-height;
  -moz-transition-property: background-color, line-height;
  -o-transition-property: background-color, line-height;
  transition-property: background-color, line-height;
}
nav ul {
  float: left;
  border-left: 1px solid #353939;
  border-left: 1px solid rgba(0, 0, 0, 0.2);
  border-right: 1px solid #4d5354;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}
nav li {
  float: left;
}
 nav a {
  display: block;
  padding: 0 20px;
  line-height: 36px;
  color: #ddd;
  text-decoration: none;
  text-shadow: 0 -1px #2e3131;
  border-left: 1px solid #4d5354;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid #353939;
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
nav a:hover {
  background: #4d5354;
  background: rgba(255, 255, 255, 0.05);
}

最佳答案

从箭头中移除 position: absolute 并像这样改变它们的样式

.arrowleft {
    float: left;
    height: 28px;
    margin-top: 4px;
    width: 28px;
}

...

.arrowright {
    float: right;
    height: 28px;
    margin-top: 4px;
    width: 28px;
}

最后从 ul

中删除 float:left

最终结果(在 Firefox 29 上)

enter image description here

关于html - 顶部导航元素未居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23784656/

相关文章:

javascript - 来自非安全页面的安全 xmlhttprequest

html - 更改 <select> HTML 表单的边框颜色

asp.net - asp.net 中图像转发器控件的 css 模板

html - 聊天消息模板

jquery - 是什么导致布局中断?尝试做一个水平布局的网站

css - 如何仅使用 CSS 动态改变图像的色调?

javascript - 防止 parent sibling 的事件在javascript中触发

html - 如何在html中制作一个大小不变的表格

javascript - renderer.setSize 按屏幕百分比计算? (三.js)

javascript - HTML 页面的打印问题