html - 如何将我的 Logo 图像水平和垂直居中到 CSS 中的另一个 div?

标签 html css navigation graphical-logo

我需要帮助定位 Logo 水平居中。它还需要在我的链接 div 的顶部垂直居中。有人可以帮助我吗?

我希望我的 Logo 看起来像这样: enter image description here

下面是我的 HTML 和 CSS:

HTML - http://codebin.org/view/199faa14

<div id="container">

      <div id="logo">
      <img src="images/images/logo.gif" />
      </div>

      <div id="navigation">
      navigation
      </div>

      <div id="header">
      </div>

      <div id="line">
      </div>

      <div id="content">
      content
      </div>

    </div>

CSS - http://codebin.org/view/dda88d94

body {
background: url(../images/images/bg_page.gif) center center;
}

#container {
width: 940px;
margin: 0 auto;
}

    #header {
    height: 281px;
    background: url(../images/home/header.gif) top center;
    position: relative;
    }

    #logo {
    position: absolute;
    z-index: 2;
    top: 0px
    height: 214px;
    margin: 10px auto 0 auto;
    }

    #navigation {
    position: relative;
    height: 40px;
    background: #fff;
    margin-top: 100px
    }

    #content {
    height: 541px;
    background: url(../images/home/bg_body.png) top center;
    position: relative;
    }

    #line {
    height: 4px;
    background: url(../images/home/line.gif) top center;
    position: relative;
    }

最佳答案

在使用 javascript 之前尝试这样的事情!

.center {
width: 300px;
height: 300px;
position: absolute;
left: 50%;
top: 50%; 
margin-left: -150px;
margin-top: -150px;
}

或者这个!

.image_container {
   width: 300px;
   height: 300px;
   background: #eee;
   text-align: center;
   line-height: 300px;
 }

.image_container img {
   vertical-align: middle;
 }

关于html - 如何将我的 Logo 图像水平和垂直居中到 CSS 中的另一个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16884872/

相关文章:

java - 从受密码保护的网页下载 pdf

javascript - 使必填字段提示出现在 onclick=confirm() 提示之前

jquery - jQuery 插件所需的 CSS 定位帮助 - 提供的 jsfiddle 示例

javascript - Fullpage.js 只能在本地工作?

navigation - ExpressionEngine 2 中的动态导航

html - 垂直居中,但在窗口缩小时也保持顶部和底部粘性

javascript - 无法使用 jQuery 滑动 div

jquery - 如何创建一个在滚动时跟随并添加 Logo 的导航栏?

css - 自动调整 Web 应用程序的高度和宽度

flutter - Flutter BottomNavigationBar在顶部发光吗?