html - 奇怪的 css 行为 - 图像内联不在下方

标签 html css layout

我的网站页脚有一个 Twitter/Facebook 标志。

我的页面代码是:

<div class="layout-cell" style="width: 50%">
  <a href="https://www.facebook.com/pages/mysite/" target="_blank" class="facebook-tag-icon"></a>
  <a href="https://www.twitter.com/mysite" target="_blank" class="twitter-tag-icon"></a>
</div>

我的 CSS 是:

.facebook-tag-icon {
background:  url('mysite.co.uk/fb-off.png') no-repeat scroll;
min-height:32px;
min-width:32px;
display: block;
margin: 5px;
float: right;
}

.facebook-tag-icon:hover {
background:  url('http://mysite.co.uk/fb_on.png') no-repeat scroll;
}

.twitter-tag-icon {
background:  url('http://mysite.co.uk/twitter_off.png') no-repeat scroll;
min-height:32px;
min-width:32px;
display: block;
margin: 5px;
float: right;
}

.twitter-tag-icon:hover
{
background:  url('http://mysite.co.uk/twitter_on.png') no-repeat scroll;
}

我希望我的 Facebook 图标显示在我的 Twitter 图标之上,但是它们目前并排显示在同一行上...如何让它们相互重叠显示?

最佳答案

clear: both; 添加到 twitter 图标:

.facebook-tag-icon {
background:  url('https://www.gravatar.com/avatar/87941b98d114974b269cd65f361b605b?s=32&d=identicon&r=PG&f=1') no-repeat scroll;
min-height:32px;
min-width:32px;
display: block;
margin: 5px;
float: right;
}

.twitter-tag-icon {
background:  url('https://www.gravatar.com/avatar/87941b98d114974b269cd65f361b605d?s=32&d=identicon&r=PG&f=1') no-repeat scroll;
min-height:32px;
min-width:32px;
display: block;
margin: 5px;
float: right;
clear: both;
}
<div class="layout-cell" style="width: 50%">
  <a href="https://www.facebook.com/pages/mysite/" target="_blank" class="facebook-tag-icon"></a>
  <a href="https://www.twitter.com/mysite" target="_blank" class="twitter-tag-icon"></a>
</div>

关于html - 奇怪的 css 行为 - 图像内联不在下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26350863/

相关文章:

html - 将样式作为显示 block 后不起作用

html - 如何使用CSS对齐表格

html - CSS 中一个 div 或表格的两个滚动条

Android - 状态栏阻止全屏

jquery - 如何为 Ipad 创建一个始终 float 在顶部的 div 而没有问题?

html - 在 SQL Server 中使用存储过程从数据库中获取数据

javascript - HTML5 Canvas 上的图像仅出现一帧

css - 如何在 Flex 应用程序运行时加载并应用 CSS 样式表?

android - 如何在 Android 上将自定义 View 居中?

android - 如何在没有 fragment 的情况下共享 Activity 之间的通用布局