html - CSS:使用上边距定位元素

标签 html css

ETA:感谢大家的帮助!这些都很好用。非常感谢您的宝贵时间!

我正在编写一份时事通讯(实时预览 here 和我的目标 here )并试图让导航按钮(“加入 Meet Learn 支持”)位于 Logo 的中间位置。当我在 navButtons 类中尝试 top-margin 时,我没有看到任何成功。我怀疑这是一个显示问题,但我不确定 --- 从 inline 更改为 inline-block 并没有真正帮助。

<!DOCTYPE html>
<html>
<head>
<title>The Leaflet</title>

<style>


div
{
    display: inline;
}

a
{
    text-decoration: none;
}
p
{
    text-align:left;
    margin-left: 130px;
    margin-right: 130px;
    max-width: 600px;

}

#logo /* This sets the width for the New Leaf logo at the top. This should not change.*/
{
    position:relative;
}

#navButtons
{
 position:relative;
 right:-240px;
}

#announcementImage
{
    margin-left: 120px;
    margin-right: 120px;
}


a.joinButton
{
    margin-left:40%;
    color:white;
    background-color: #f7853e;
    font-size: 30px;

}

a.navButton
{
    color:#494541;
    font-size: 22px;

}

</style>
</head>
<body>

<div id="logo"> <! --- Sets up the logo --->
<img src ="images/NLNewsletterLogo.png">
</div>

<div id="nav buttons"> <! --- Navigation Bar--->
<a class = "joinButton" href="url">Join</a>
<a class = "navButton" href="url">  Meet  </a>
<a class = "navButton" href="url">Learn  </a>
<a class = "navButton" href="url">Support  </a>
</div>

<br>
<br>
<br>
<br>
<br>

<div id ="announcementImage"><! --- Lead Image-->
<img src="images/announcementGraphic.png">
</div>

<div id = "announcementText">
<p>Thrive Week is in full swing here at the Leaf. So far, we've had Sharon Perry, head of the State
College Area School District Career Center, help participants identify which of 34 traits,
including the special quality of woo, are strengths they employ in various settings so they can
work smarter. Then Anna Gokieli, owner of Tru Meditation and Yoga, got us staying present and 
peaceful even in situations that often trigger stress. Will Snyder brought it home last night by 
showing how making art and making money don't have to conflict.

Have a comment on a workshop you've attended or a session you'd like to see in our remaining 
Design and Launch weeks? Galen would love to hear from you!</p>

</div>
</body>

最佳答案

试试这个

#logo {
    display: inline-block;
    vertical-align: middle;
}

#nav {
    display: inline-block;
    vertical-align: middle;
    width: 100%;
}

关于html - CSS:使用上边距定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482461/

相关文章:

javascript - 将 jquery 动画还原为原始 css 状态

html - Bootstrap 导航栏,在菜单图标旁边的右侧和左侧带有元素

php - codeigniter 只能加载 index(),不能加载任何其他方法

javascript - 未应用新高度的情况。我看不到

javascript - gh-pages 在搜索资源时忽略元素目录?

javascript - 仅在页面重新加载后触发 jQuery 输入事件

javascript - 设置新单元格值时保留格式(Google 电子表格)

javascript - Skrollr,在方向改变时翻转图像

html - 滚动条导致 Microsoft Edge 中的表格未对齐

JavaScript 滚动菜单