背景颜色仅在顶部

Posted

技术标签:

【中文标题】背景颜色仅在顶部【英文标题】:Background color is only on top 【发布时间】:2021-12-10 05:11:15 【问题描述】:

我需要你的帮助。我认为一切都很好,但它不起作用。在顶部和末端只有深蓝色的矩形。导航菜单和他的滑块有问题吗?我认为没有任何阻挡背景颜色的对象,我没有任何想法。你能帮我解决这个问题吗?感谢您的回复!

 <head>
    
<link rel="icon" href="/minimenu.png">
 </head>
 <body style="background-color:darkblue;"><div class="area"></div><nav class="main-menu"><img src="https://i.ibb.co/xC42G9x/f19ada7376b147df815f4dc7438317e0-5.png"   >
           <ul>
               <li>
                   <a href="/welcome.php">
                      
                     <i class="fa fa-home fa-2x"></i>
                       <span class="nav-text">
                           Home
                       </span>
                   </a>
                 
               </li>
               <li class="has-subnav">
                   <a href="#">
                       <i class="fa fa-book fa-2x"></i>
                       <span class="nav-text">
                           Homework
                       </span>
                 </a>
               </li>
               <li class="has-subnav">
                   <a href="#">
                      <i class="fa fa-list fa-2x"></i>
                       <span class="nav-text">
                       Grades    
                       </span>
                   </a>
                   
               </li>
               <li class="has-subnav">
                   <a href="#">
                      <i class="fa fa-table fa-2x"></i>
                       <span class="nav-text">
                           Timetable
                       </span>
                   </a>
                  
               </li>
               <li>
                   <a href="#">
                       <i class="fa fa-leanpub fa-2x"></i>
                       <span class="nav-text">
                           Learning
                       </span>
                   </a>
               </li>
               <li>
                   <a href="#">
                       <i class="fa fa-gamepad fa-2x"></i>
                       <span class="nav-text">
                           Games
                       </span>
                   </a>
               </li>
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
             <p hidden>TU SA ZACINA SUBMENU</p>
               <li>
                  <a href="#">
                      <i class="fa fa-bars fa-2x"></i>
                       <span class="nav-text">
                           Submenu 1
                       </span>
                   </a>
               </li>
               <li>
                  <a href="#">
                       <i class="fa fa-bars fa-2x"></i>
                       <span class="nav-text">
                           Submenu 2
                       </span>
                   </a>
               </li>
             <p hidden>TU SA KONCI SUBMENU</p>  
           </ul>

           <ul class="logout">
               <li>
                  <a href="/index.php">
                        <i class="fa fa-sign-out fa-2x"></i>
                       <span class="nav-text">
                           Logout
                       </span>
                   </a>
               </li>  
           </ul>
       </nav>
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  
 </body>
   </html>
   <style>@import url(//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css);

@import url(https://fonts.googleapis.com/css?family=Titillium+Web:300);
.fa-2x 
font-size: 2em;

.fa 
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size:20px;



.main-menu:hover,nav.main-menu.expanded 
width:250px;
overflow:visible;


.main-menu 
background:darkblue;
border-right:1px solid #e5e5e5;
position:absolute;
top:0;
bottom:0;
height:100%;
left:0;
width:60px;
overflow:hidden;
-webkit-transition:width .05s linear;
transition:width .05s linear;
-webkit-transform:translateZ(0) scale(1,1);
z-index:1000;


.main-menu>ul 
margin:7px 0;


.main-menu li 
position:relative;
display:block;
width:250px;


.main-menu li>a 
position:relative;
display:table;
border-collapse:collapse;
border-spacing:0;
color:#999;
font-family: arial;
font-size: 14px;
text-decoration:none;
-webkit-transform:translateZ(0) scale(1,1);
-webkit-transition:all .1s linear;
transition:all .1s linear;
 


.main-menu .nav-icon 
position:relative;
display:table-cell;
width:60px;
height:36px;
text-align:center;
vertical-align:middle;
font-size:18px;


.main-menu .nav-text 
position:relative;
display:table-cell;
vertical-align:middle;
width:190px;
 font-family: 'Titillium Web', sans-serif;


.main-menu>ul.logout 
position:absolute;
left:0;
bottom:0;


.no-touch .scrollable.hover 
overflow-y:hidden;


.no-touch .scrollable.hover:hover 
overflow-y:auto;
overflow:visible;


a:hover,a:focus 
text-decoration:none;


nav 
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
-o-user-select:none;
user-select:none;


nav ul,nav li 
outline:0;
margin:0;
padding:0;

.main-menu li:hover>a,nav.main-menu li.active>a,.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus,.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus,.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,.dashboard-page nav.dashboard-menu ul li.active a 
color:#fff;
background-color:#5fa2db;

.area 
float: left;
background: #e2e2e2;
width: 100%;
height: 100%;

@font-face 
 font-family: 'Titillium Web';
 font-style: normal;
 font-weight: 300;
 src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');

</style>```   

【问题讨论】:

我认为这只是你的主菜单 img,看看吧! 【参考方案1】:
<head>
    
    <link rel="icon" href="/minimenu.png">
     </head>
     <body style="background-color:darkblue;"><div class="area"></div><nav class="main-menu"><img src="https://i.ibb.co/xC42G9x/f19ada7376b147df815f4dc7438317e0-5.png"   >
               <ul>
                   <li>
                       <a href="/welcome.php">
                          
                         <i class="fa fa-home fa-2x"></i>
                           <span class="nav-text">
                               Home
                           </span>
                       </a>
                     
                   </li>
                   <li class="has-subnav">
                       <a href="#">
                           <i class="fa fa-book fa-2x"></i>
                           <span class="nav-text">
                               Homework
                           </span>
                     </a>
                   </li>
                   <li class="has-subnav">
                       <a href="#">
                          <i class="fa fa-list fa-2x"></i>
                           <span class="nav-text">
                           Grades    
                           </span>
                       </a>
                       
                   </li>
                   <li class="has-subnav">
                       <a href="#">
                          <i class="fa fa-table fa-2x"></i>
                           <span class="nav-text">
                               Timetable
                           </span>
                       </a>
                      
                   </li>
                   <li>
                       <a href="#">
                           <i class="fa fa-leanpub fa-2x"></i>
                           <span class="nav-text">
                               Learning
                           </span>
                       </a>
                   </li>
                   <li>
                       <a href="#">
                           <i class="fa fa-gamepad fa-2x"></i>
                           <span class="nav-text">
                               Games
                           </span>
                       </a>
                   </li>
                 <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
                 <p hidden>TU SA ZACINA SUBMENU</p>
                   <li>
                      <a href="#">
                          <i class="fa fa-bars fa-2x"></i>
                           <span class="nav-text">
                               Submenu 1
                           </span>
                       </a>
                   </li>
                   <li>
                      <a href="#">
                           <i class="fa fa-bars fa-2x"></i>
                           <span class="nav-text">
                               Submenu 2
                           </span>
                       </a>
                   </li>
                 <p hidden>TU SA KONCI SUBMENU</p>  
               </ul>
    
               <ul class="logout">
                   <li>
                      <a href="/index.php">
                            <i class="fa fa-sign-out fa-2x"></i>
                           <span class="nav-text">
                               Logout
                           </span>
                       </a>
                   </li>  
               </ul>
           </nav>
       <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      
     </body>
       </html>
       <style>@import url(//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css);
    @import url(https://fonts.googleapis.com/css?family=Titillium+Web:300);
    .fa-2x 
    font-size: 2em;
    
    .fa 
    position: relative;
    display: table-cell;
    width: 60px;
    height: 36px;
    text-align: center;
    vertical-align: middle;
    font-size:20px;
    
    

    .main-menu:hover,nav.main-menu.expanded 
    width:250px;
    overflow:visible;
    
    
    .main-menu 
    background:darkblue;
    border-right:1px solid #e5e5e5;
    position:absolute;
    top:0;
    bottom:0;
    height:100%;
    left:0;
    width:60px;
    overflow:hidden;
    -webkit-transition:width .05s linear;
    transition:width .05s linear;
    -webkit-transform:translateZ(0) scale(1,1);
    z-index:1000;
    
    
    .main-menu>ul 
    margin:7px 0;
    
    
    .main-menu li 
    position:relative;
    display:block;
    width:250px;
    
    
    .main-menu li>a 
    position:relative;
    display:table;
    border-collapse:collapse;
    border-spacing:0;
    color:#999;
    font-family: arial;
    font-size: 14px;
    text-decoration:none;
    -webkit-transform:translateZ(0) scale(1,1);
    -webkit-transition:all .1s linear;
    transition:all .1s linear;
     
    
    
    .main-menu .nav-icon 
    position:relative;
    display:table-cell;
    width:60px;
    height:36px;
    text-align:center;
    vertical-align:middle;
    font-size:18px;
    
    
    .main-menu .nav-text 
    position:relative;
    display:table-cell;
    vertical-align:middle;
    width:190px;
     font-family: 'Titillium Web', sans-serif;
    
    
    .main-menu>ul.logout 
    position:absolute;
    left:0;
    bottom:0;
    
    
    .no-touch .scrollable.hover 
    overflow-y:hidden;
    
    
    .no-touch .scrollable.hover:hover 
    overflow-y:auto;
    overflow:visible;
    
    
    a:hover,a:focus 
    text-decoration:none;
    
    
    nav 
    -webkit-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    -o-user-select:none;
    user-select:none;
    
    
    nav ul,nav li 
    outline:0;
    margin:0;
    padding:0;
    
    .main-menu li:hover>a,nav.main-menu li.active>a,.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus,.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus,.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,.dashboard-page nav.dashboard-menu ul li.active a 
    color:#fff;
    background-color:#5fa2db;
    
    .area 
    float: left;
    background: #00008B;
    width: 100%;
    height: 100%;
    
    @font-face 
     font-family: 'Titillium Web';
     font-style: normal;
     font-weight: 300;
     src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');
    
    </style>

只需从(班级区域)更改背景颜色并选择您想要的颜色,一切都会好起来的

之前

    .area 
    float: left;
    background: #e2e2e2;
    width: 100%;
    height: 100%;
    

之后

    .area 
    float: left;
    background: #00008B;
    width: 100%;
    height: 100%;
    

【讨论】:

【参考方案2】:

这是你想做的吗 I created an example for you

<head>
    
<link rel="icon" href="/minimenu.png">
 </head>
 <body><div class="area"></div><nav class="main-menu"><img src="https://i.ibb.co/xC42G9x/f19ada7376b147df815f4dc7438317e0-5.png"   >
           <ul style="background-color:darkblue;">
               <li>
                   <a href="/welcome.php">
                      
                     <i class="fa fa-home fa-2x"></i>
                       <span class="nav-text">
                           Home
                       </span>
                   </a>
                 
               </li>
               <li class="has-subnav">
                   <a href="#">
                       <i class="fa fa-book fa-2x"></i>
                       <span class="nav-text">
                           Homework
                       </span>
                 </a>
               </li>
               <li class="has-subnav">
                   <a href="#">
                      <i class="fa fa-list fa-2x"></i>
                       <span class="nav-text">
                       Grades    
                       </span>
                   </a>
                   
               </li>
               <li class="has-subnav">
                   <a href="#">
                      <i class="fa fa-table fa-2x"></i>
                       <span class="nav-text">
                           Timetable
                       </span>
                   </a>
                  
               </li>
               <li>
                   <a href="#">
                       <i class="fa fa-leanpub fa-2x"></i>
                       <span class="nav-text">
                           Learning
                       </span>
                   </a>
               </li>
               <li>
                   <a href="#">
                       <i class="fa fa-gamepad fa-2x"></i>
                       <span class="nav-text">
                           Games
                       </span>
                   </a>
               </li>
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
             <p hidden>TU SA ZACINA SUBMENU</p>
               <li>
                  <a href="#">
                      <i class="fa fa-bars fa-2x"></i>
                       <span class="nav-text">
                           Submenu 1
                       </span>
                   </a>
               </li>
               <li>
                  <a href="#">
                       <i class="fa fa-bars fa-2x"></i>
                       <span class="nav-text">
                           Submenu 2
                       </span>
                   </a>
               </li>
             <p hidden>TU SA KONCI SUBMENU</p>  
           </ul>

           <ul class="logout">
               <li>
                  <a href="/index.php">
                        <i class="fa fa-sign-out fa-2x"></i>
                       <span class="nav-text">
                           Logout
                       </span>
                   </a>
               </li>  
           </ul>
       </nav>
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  
 </body>
   </html>
   <style>@import url(//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css);

@import url(https://fonts.googleapis.com/css?family=Titillium+Web:300);
.fa-2x 
font-size: 2em;

.fa 
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size:20px;



.main-menu:hover,nav.main-menu.expanded 
width:250px;
overflow:visible;


.main-menu 
background:darkblue;
border-right:1px solid #e5e5e5;
position:absolute;
top:0;
bottom:0;
height:100%;
left:0;
width:60px;
overflow:hidden;
-webkit-transition:width .05s linear;
transition:width .05s linear;
-webkit-transform:translateZ(0) scale(1,1);
z-index:1000;


.main-menu>ul 
margin:7px 0;


.main-menu li 
position:relative;
display:block;
width:250px;


.main-menu li>a 
position:relative;
display:table;
border-collapse:collapse;
border-spacing:0;
color:#999;
font-family: arial;
font-size: 14px;
text-decoration:none;
-webkit-transform:translateZ(0) scale(1,1);
-webkit-transition:all .1s linear;
transition:all .1s linear;
 


.main-menu .nav-icon 
position:relative;
display:table-cell;
width:60px;
height:36px;
text-align:center;
vertical-align:middle;
font-size:18px;


.main-menu .nav-text 
position:relative;
display:table-cell;
vertical-align:middle;
width:190px;
 font-family: 'Titillium Web', sans-serif;


.main-menu>ul.logout 
position:absolute;
left:0;
bottom:0;


.no-touch .scrollable.hover 
overflow-y:hidden;


.no-touch .scrollable.hover:hover 
overflow-y:auto;
overflow:visible;


a:hover,a:focus 
text-decoration:none;


nav 
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
-o-user-select:none;
user-select:none;


nav ul,nav li 
outline:0;
margin:0;
padding:0;

.main-menu li:hover>a,nav.main-menu li.active>a,.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus,.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus,.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,.dashboard-page nav.dashboard-menu ul li.active a 
color:#fff;
background-color:#5fa2db;

.area 
float: left;
background: #e2e2e2;
width: 100%;
height: 100%;

@font-face 
 font-family: 'Titillium Web';
 font-style: normal;
 font-weight: 300;
 src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');

</style>

【讨论】:

以上是关于背景颜色仅在顶部的主要内容,如果未能解决你的问题,请参考以下文章

CSS:仅在边距内的背景颜色

在背景图像顶部提供颜色

如何使背景图像顶部的透明背景颜色移至底部?

UIView背景颜色和顶部透明png

如何在颤动中使设备顶部面板(状态栏)具有与 AppBar 相同的背景颜色?

仅在图形的一个区域上更改背景颜色[重复]