html - float 图像的CSS对齐

标签 html css

这是问题的一个例子http://jsfiddle.net/nggrj1zt/4/ . 图片和标题是随机生成的,所以不能单独应用样式

这是html

<div id="wrapper">
   <div class="specialsticky">
      <img src="img1" alt="first image">
      <div class="mast-screen" style="opacity: 0.5;"></div>
      <div class="mast-screen1">
         <h1 class="mast-header"><a href="#">This the title </a></h1>
      </div>
   </div>
   <div style="clear:both"></div>


   <div class="specialsticky">
      <img src="img2" alt="second image"> 
      <div class="mast-screen" style="opacity: 0.5;"></div>
      <div class="mast-screen1">
        <h1 class="mast-header"><a href="#">This the title </a></h1>
      </div>
   </div>
   <div style="clear:both"></div>

   <div class="specialsticky">
      <img src="img3" alt="third image">
      <div class="mast-screen" style="opacity: 0.5;"></div>
      <div class="mast-screen1">
      <h1 class="mast-header"><a href="#">This the title </a></h1>
      </div>
    </div>
    <div style="clear:both"></div>
</div>

图片已对齐,但字幕和报头需要与其各自的图片对齐。当我尝试使用相对定位时,图像的对齐方式被打乱了。

最佳答案

position:relative 应用于 .specialsticky。当前 .mast-screen.mast-screen1 相对于视口(viewport)定位。

Have an example!

CSS

.specialsticky {
    position: relative;
}

Here is a simplified example具有百分比高度和过渡悬停状态。

关于html - float 图像的CSS对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25494095/

相关文章:

jquery - 如何使我的菜单的下拉部分在移动 View 中切换?

javascript - Google PageSpeed Insights 问题 - 优先考虑可见内容

html - 有什么办法可以防止手机邮件客户端自动强制邮件为 "mobile-friendly"格式?

html - select 的框透明背景在 Chrome 中是否有效?

javascript - document.querySelectorAll 出现问题; a[href=]' 不是有效的选择器

html - 调整 td 的宽度使行宽均匀

css - 'letterbox' Android 平板电脑的响应式设计

html - Bootstrap 4 导航栏在 div 内打开

html - CSS 保留纵横比但填充父 div

html - 悬停时图像 map 品牌 Logo 更改