简体   繁体   English

无法将面板div居中

[英]can't center panel div inside of

so i'm trying to make the red div (panel) center within the black background of the div at the bottom of the page, while haveing the font awesome logo in them and make the whole red div a button, rather than just the icon. 因此,我试图在页面底部使div的黑色背景位于红色div(面板)的中心,同时使字体中有超棒的徽标,并使整个红色div成为按钮,而不仅仅是图标。 I have searched for an answer but can not find, any help is greatly appreciated. 我已经找到了答案,但是找不到,非常感谢您的帮助。

 body { width: 100%; padding: 0; margin: 0; } body, html { background: fixed; background-image: url("../img/pineapple-1704339_1920"); background-repeat: no-repeat; background-position: center; background-size: cover; background-color: grey; height: 95.8vh; } .text-box { text-align: center; } .panel { text-align: center; padding: 7vh; border-radius: 20px 20px 20px; background-color: red; height: calc(100% - 80px); } /*==============================================================================evrythang==*/ .hero { height: 75%; width: 100%; } .hero-title { text-align: center; margin-top: 0; padding-top: 10%; color: white; } /*==============================================================================hero section==*/ .external-sites { height: 25%; width: 100%; background-color: black; } /*==============================================================================external sites==*/ .work-flex { display: flex; justify-content: center; align-items: center; } .sites { display: flex; justify-content: space-between; align-items: stretch; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="footer"> <div class="container-fluid external-sites"> <div class="row"> <div class="col-md-4"> <div class="panel"> <a href="#" target="_blank"><i class="fa fa-linkedin fa-5x" style="color:blue"></i></a> </div> </div> <div class="col-md-4"> <div class="panel"> <i aria-hidden="true" class="fa fa-html5 fa-5x fa-center"></i> </div> </div> <div class="col-md-4"> <div class="panel"> <a href="#" target="_blank"><i class="fa fa-github-square fa-5x" style="color:green"></i></a> </div> </div> </div> </div> </div> 

If I get your idea about what you want to do - here is a snippet of code that does what I think you want. 如果我对您要做什么有个想法-这是一段代码,它可以满足我的需求。 It looks like you didn't have the middle panel configured as a link, so I didn't do that, but moved the anchor tag to enclose your .panel div. 看来您没有将中间面板配置为链接,所以我没有这样做,但移动了定位标记以包围.panel div。 Also tweaked the CSS to make your panel div settings more specific so that the settings for background-color would be used. 还调整了CSS,使您的面板div设置更加具体,以便使用background-color的设置。 And included the font-awesome CSS link. 并包括字体真棒的CSS链接。

 body { width: 100%; padding: 0; margin: 0; } body, html { background: fixed; background-image: url("../img/pineapple-1704339_1920"); background-repeat: no-repeat; background-position: center; background-size: cover; background-color: grey; height: 95.8vh; } .text-box { text-align: center; } div.col-md-4 .panel { text-align: center; padding: 7vh; border-radius: 20px 20px 20px; background-color: red; height: calc(100% - 80px); } .hero { height: 75%; width: 100%; } .hero-title { text-align: center; margin-top: 0; padding-top: 10%; color: white; } .external-sites { height: 25%; width: 100%; background-color: black; } .work-flex { display: flex; justify-content: center; align-items: center; } .sites { display: flex; justify-content: space-between; align-items: stretch; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <div class="footer"> <div class="container-fluid external-sites"> <div class="row"> <div class="col-md-4"> <a href="#" target="_blank"> <div class="panel"> <i class="fa fa-linkedin fa-5x" style="color:blue"></i> </div> </a> </div> <div class="col-md-4"> <div class="panel"> <i aria-hidden="true" class="fa fa-html5 fa-5x fa-center"></i> </div> </div> <div class="col-md-4"> <a href="#" target="_blank"> <div class="panel"> <i class="fa fa-github-square fa-5x" style="color:green"></i> </div> </a> </div> </div> </div> </div> 

I think you are trying to make red panel vertically center along with font awesome icons, so try this css 我认为您正在尝试使红色面板与字体真棒图标一起垂直居中,因此请尝试使用此CSS

.panel {
    text-align: center;
    padding: 7vh;
    border-radius: 20px 20px 20px;
    background-color: red;
     height: calc(100% - 80px);
    margin: 5vh;
}
.panel a {
    display: block;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

<div class="footer">
  <div class="container-fluid external-sites">
    <div class="row">
      <div class="col-md-4">
        <div class="panel">
          <a href="#" target="_blank"><i class="fa fa-linkedin fa-5x" style="color:blue"></i></a>
        </div>
      </div>
      <div class="col-md-4">
        <div class="panel">
          <a href="#" target="_blank"><i aria-hidden="true" class="fa fa-html5 fa-5x fa-center"></i></a>
        </div>
      </div>
      <div class="col-md-4">
        <div class="panel">
          <a href="#" target="_blank"><i class="fa fa-github-square fa-5x" style="color:green"></i></a>
        </div>
      </div>
    </div>
  </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM