html - CSS:将 img 相对于 div 对齐

标签 html css tumblr

我对 HTML 和 CSS 比较陌生,我正在尝试格式化网页。
我想将四个图像对齐到一个 input div。可以看到页面here ,四个社交媒体图标。我希望它们一个接一个地排成一排,与上面的搜索栏对齐。那么喜欢网页左侧的中心吗?

这是 4 张图片的 HTML:

<div class="social-icons group"> 
    <a href="https://www.facebook.com/asbreckenridge" title="" target="_blank"><img src="http://www.iconsdb.com/icons/download/gray/facebook-24.jpg"></a>
    <a href="http://twitter.com/{text:Twitter Username}" title="" target="_blank"><img src="http://www.iconsdb.com/icons/download/gray/twitter-24.jpg"></a>
    <a href="https://github.com/AndrewSB" title="" target="_blank"><img src="http://www.iconsdb.com/icons/download/gray/github-6-24.jpg"></a>
    <a href="mailto:asbreckenridge@me.com?Subject=Contact%From%Blog"><img src="http://www.iconsdb.com/icons/download/gray/new-post-16.jpg"></a>
</div>`

和 CSS

body header .social-icons{font-size:20px;float:center;list-style:none;display:block;margin:0 5px 15px;width:24px;}
body header .social-icons a {color:#4f555b;display:block;opacity:0.8;text-decoration:none}

最佳答案

您似乎想要以下内容:

元素 .social-icons 不再 float ,宽度更改为 100% 以便为子元素留出水平空间。子 a 元素从 display:block 更改为 display:inline-block

body header .social-icons {
    display: block;
    width: 100%;
    text-align: center;
}

body header .social-icons a {
    color: #4f555b;
    opacity: 0.8;
    text-align: center;
    text-decoration: none;
    display: inline-block;
}

关于html - CSS:将 img 相对于 div 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21213378/

相关文章:

html - Tumblr .permalink-page 自定义 CSS 不缩放内容

html - 用文本链接替换图像按钮

html - 具有透明内容背景的剪辑路径语音气泡

html - 当使用 "vw"作为大小指标时容器停止​​缩小时字体大小继续缩小。为什么?

jquery - 日期选择器的麻烦

html - 我的 tumblr 主题内容与侧边栏重叠

javascript - HTML 工作日历

html - 如何使用ajax设置图片的src?

javascript - Grails — CSS 和 JavaScript 缓存

javascript - Tumblr 是否在其主题中使用 Knockout 或其他 JS 实用程序