本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

页面两侧垂直对齐的 div

发布于2023-11-12 16:48     阅读(1009)     评论(0)     点赞(25)     收藏(0)


我们将 Web 应用程序的精简版本作为 iframe 嵌入到第三方页面中。我想要一个底部“工具栏”,包含 2 个链接,其中一个是纯文本,另一个是我们公司徽标,以文本开头。我希望这两个链接位于相对的角落,并与包含的工具栏 div 的中间垂直对齐。使用这种方法,这是我到目前为止所得到的Fiddle

<div id="main-app"></div>

<div id="my-footer">
  <span id="full-link" class="assert-position"><a href="https://url.to.webapp" target="_blank" class="assert-position">View full size</a> </span> <div id="filler" class="assert-position"></div> Powered by
  <a href="http://www.company-landing-page.co.uk" target="_blank" class="assert-position"> <img src="/images/my-company_logo.png"/></a>
</div>
<style>
     *{
       margin: 0;
       padding: 0;
     }

      html, body {
        height: 100%;
      }

      #main-app {
          height: 90%;
          width: 100%;
      }

      #my-footer {
        height: 10%;
        width: 100%;
        background-color: #0f0f0f;
        color: #FFF;
        text-align: right;
        font-family: Tahoma, Arial, "sans-serif"
      }

      #full-link {
        float: left;
        text-align: left;
        font-family: Tahoma, Arial, "sans-serif";
        font-size: small;
        color: #FFF;
      }

      #filler {
        height: 100%;
      }

      #my-footer img{

        margin: 3px;
      }

      .assert-position{
        display: inline-block;
        vertical-align: middle;
      }

      #full-link a:visited{
        color: #FFF
       }
</style>

问题是,我所做的一切尝试使左侧的链接正确垂直对齐(因为文本与图像对齐)要么什么也不做,要么破坏水平对齐。因为我不控制甚至不知道嵌入的 iframe 有多大,所以任何固定像素数(例如使用position:absolute)的东西都是正确的。我确信这应该很容易,但作为一名后端开发人员,我内心深处正在为此抓狂。另外,我宁愿避免使用任何第三方库(例如 bootstrap),因为我的主应用程序不使用它们,并且我不希望现有依赖项中的任何全局设置被覆盖。


解决方案


演示: http: //jsfiddle.net/kbjycez2/68/

要将链接垂直居中对齐,您需要为#my-footer元素提供行高。

我使用 Flex 模型将链接左右对齐。

以下代码片段可能适合您:

* {
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

#main-app {
  height: 90%;
  width: 100%;
}

#my-footer {
  height: 10%;
  width: 100%;
  background-color: #0f0f0f;
  color: #FFF;
  display: flex;
  font-family: Tahoma, Arial, "sans-serif";
  justify-content: space-between;
  line-height: calc(10vh);
}

#my-footer img {
  vertical-align: middle;
}

#full-link a:visited {
  color: #FFF
}
<div id="main-app"></div>

<div id="my-footer">
  <div>
    <a href="https://url.to.webapp">View Full Size</a>
  </div>
  <div>
    <span>Powered By </span>
    <a href="http://www.company-landing-page.co.uk"><img src="/images/my-company_logo.png" /></a>
  </div>
</div>




所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.qianduanheidong.com/blog/article/532549/77a05e646ac5c6bf2cfa/

来源:前端黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

25 0
收藏该文
已收藏

评论内容:(最多支持255个字符)