鍍金池/ 問答/HTML/ 元素有高度 但是css設(shè)置背景色不顯示

元素有高度 但是css設(shè)置背景色不顯示

* {
  margin: 0;
  padding: 0;
}

body, html {
  width: 100%;
  height: 100%;
}

//字體圖標(biāo) start
@font-face {
  font-family: 'm';
  src: url('../fonts/3M.eot?k5ywnw');
  src: url('../fonts/3M.eot?k5ywnw#iefix') format('embedded-opentype'),
  url('../fonts/3M.ttf?k5ywnw') format('truetype'),
  url('../fonts/3M.woff?k5ywnw') format('woff'),
  url('../fonts/3M.svg?k5ywnw#3M') format('svg');
  font-weight: normal;
  font-style: normal;
}

[class^="m-"], [class*=" m-"] {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'm' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;

  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.m-binding:before {
  content: "\e900";
}

.m-level:before {
  content: "\e901";
}

.m-swiper:before {
  content: "\e902";
}

.m-integral:before {
  content: "\e903";
}

.m-remind:before {
  content: "\e904";
}

.m-account2:before {
  content: "\e905";
}

.m-success:before {
  content: "\e906";
}

.m-authcode:before {
  content: "\e907";
}

.m-password:before {
  content: "\e908";
}

.m-account:before {
  content: "\e909";
}

//字體圖標(biāo) end

//字體顏色 start
.text-nav {
  color: #181818;
}

.text-hearder {
  color: #333333;
}

.text-placeholder {
  color: #cdcdcd;
  font-size: 16px;
}

.text-dark {
  color: #606060;
}

.text-white {
  color: #ffffff;
}

.text-dominant {
  color: #a6b8c7
}

//字體顏色 end

//字體大小 start
.text-m {
  font-size: 24px;
}

.text-s {
  font-size: 12px;
}

//字體大小 end

.page-flex {
  display: flex;
}

.page-header {
  height: 50px;
  align-items: center;
}

.img-responsive {
  width: 100%;
}

.text-center {
  text-align: center;
}

.pull-left {
  float: left;
}

.pull-right {
  float: right;
}

.pt15 {
  padding-top: 15px;
}

.pb15 {
  padding-bottom: 15px;
}

.mt30 {
  margin-top: 30px;
}

.page-header.login .logo, .page-header.register .logo {
  height: 20px;
  padding: 0px 10px;
  position: absolute;
}

.page-header.index .logo {
  height: 20px;
  padding: 0px 10px;
}

.page-header.index p:nth-child(3) {
  position: absolute;
  right: 10px;
}

.container {
  padding: 0 35px;
}

.weui-cell {
  padding-left: 0;
}

.weui-cell:before, .weui-cells:before, .weui-cells:after {
  border: none;
}

//login start
.weui-label {
  width: 45px;
}

.input {
  border-bottom: 2px solid #cdcdcd;
  > img {
    height: calc(100% + 2px);
  }
}

.forgotPadssword {
  color: #606060;
  text-decoration: underline;
}

.regeister-remind {
  width: 54%;
  margin-left: 23%;
  text-align: center;
  display: table;
  align-items: center;
  vertical-align: middle;
  .weui-btn, p {
    display: inline-block;
    display: table-cell;
    font-size: 14px;
  }
}

.text-supplement > a {
  color: #ff0000;
  text-decoration: underline;
}

.login-remind {
  width: 36%;
  text-align: center;
  display: table;
  align-items: center;
  vertical-align: middle;
  .weui-btn, p {
    display: inline-block;
    display: table-cell;
    font-size: 14px;
  }
}

.btn {
  color: #94a7b7;
  border: 1px solid #94a7b7;
  line-height: 2;
}

.fill-btn {
  background: #a6b8c7;
}

.shade-success {
  background: rgba(0, 0, 0, .8);
  z-index: 2;
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  .box {
    position: absolute;
    width: 90%;
    height: 34%;
    top: 26%;
    left: 5%;
    background: #fff;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    i {
      font-size: 56px;
    }
    a {
      width: 80%;
      margin-left: 10%;
    }
  }
}

//login end

//index start
.weui-navbar + .weui-tab__bd {
  padding-top: 0px;
}

.weui-navbar {
  bottom: 0;
  top: auto;
  background-color: #fff;
  .weui-navbar__item.weui-bar__item--on, .weui-navbar__item {
    color: #181818;
    font-size: 18px;
    background-color: #fff;
    padding: 0;
    margin: 13px 0;
    border-right: 1px solid #e0e0e0
  }
}
.weui-tab__bd .weui-tab__bd-item.weui-tab__bd-item--active{
  display: flex;
  flex-direction: column;
}
.panel {
  padding: 0 10px;
  width: 100%;
  display: -webkit-box;
  box-sizing: border-box;
  overflow: hidden;
  a{
    display: block;
  }
  .link-activity {
    background-color: #c5c9cc;
    width: 50%;
    height: 86%;
    float: left;
    padding-right: 5px;
  }
  .r{
    float: right;
    width: 50%;
    height: 86%;
    .link-exchange {
      background: #cec4c6;
      width: 100%;
      height: 50%;
      float: left;
    }
    .link-userinfo {
      background: #c5d0ca;
      width: 100%;
      height: 50%;
      float: left;
    }
  }

}

//index end
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport"
          content="width=device-width,user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="assets/css/jquery-weui.min.css">
    <link rel="stylesheet" href="assets/css/weui.min.css">
    <link rel="stylesheet" href="assets/css/style.min.css">

</head>
<body>
<!-- 容器 -->
<div class="weui-tab">
    <div class="weui-navbar">
        <a class="weui-navbar__item weui-bar__item--on" href="#tab1">
            首頁
        </a>
        <a class="weui-navbar__item" href="#tab2">
            活動(dòng)
        </a>
        <a class="weui-navbar__item" href="#tab3">
            我的
        </a>
        <a class="weui-navbar__item" href="#tab4">
            意見反饋
        </a>
    </div>
    <div class="weui-tab__bd">
        <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active weui-flex">
            <div class="page-header weui-flex index">
                <img class="logo" src="assets/images/logo.png">
                <p class="text-hearder">您好: <span>張鑫</span></p>
                <p class="pull-right">可用積分:<span>600</span></p>
            </div>
            <div class="page-banner">
                <img class="img-responsive" src="assets/images/banner-index.jpg">
            </div>
            <div class="panel weui-flex__item">
               <a href="javascript:;" class="link-activity"></a>
                <div class="r">
                    <a href="javascript:;" class="link-exchange"></a>
                    <a href="javascript:;" class="link-userinfo"></a>
                </div>

            </div>
        </div>
        <div id="tab2" class="weui-tab__bd-item">
            <h1>活動(dòng)</h1>
        </div>
        <div id="tab3" class="weui-tab__bd-item ">
            <h1>我的</h1>
        </div>
        <div id="tab4" class="weui-tab__bd-item">
            <h1>意見反饋</h1>
        </div>
    </div>
</div>


<script src="assets/js/jquery-2.1.4.js"></script>
<script src="assets/js/fastclick.js"></script>
<script src="assets/js/jquery-weui.min.js"></script>
</body>
</html>

clipboard.png

現(xiàn)在a元素都是有大小的但是背景色不顯示是為什么

clipboard.png

clipboard.png

回答
編輯回答
使勁操

跑了下你的代碼,link-userinfo 沒有顯示,是因?yàn)?,未設(shè)置float
https://jsfiddle.net/zwwill/3...
-----補(bǔ)充
注意看panel類里面的overflow:hidden; display:-webkit-box;并且高度未設(shè)置即為auto,此時(shí)的panel內(nèi)a便標(biāo)簽有設(shè)置為float:left 那么 float一旦設(shè)置,原生將“脫離”文檔流,即不在占用panel的空間,此時(shí)即使a便簽有高度也無法“撐開“ panel,因?yàn)?panel 設(shè)置了 hidden 屬性,所有被隱藏了,但是,當(dāng)overflow:hidden;display:block;同時(shí)存在時(shí),會(huì)重新計(jì)算panel的大小

解決方案有多種,簡單清除 a 便簽的浮動(dòng),或者 display:block;較為方便

2017年7月7日 17:05