2016-08-05 51 views
2

我使用具有固定位置的視頻標記作爲頁面頂部的背景。現在我想在它下面放置一個列表,但是我的列表沒有很好的定位,而是有一個絕對的位置。我不知道我的代碼錯在哪裏。如何在頁面的視頻背景下放置一個列表?

我能做些什麼來解決這個問題?

* { 
 
    border: 0; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
a { 
 
    text-decoration: none; 
 
    color: white; 
 
} 
 
ul { 
 
    list-style-type: none; 
 
} 
 
.mymenu { 
 
    float: left 
 
} 
 
.mymenu > li { 
 
    background-color: #ff9933; 
 
    float: left; 
 
    height: 60px; 
 
    line-height: 60px; 
 
    text-align: center; 
 
    padding: 0 80px; 
 
} 
 
.mymenu li:hover { 
 
    background: #e62e00; 
 
    cursor: pointer; 
 
} 
 
.mymenu li ul { 
 
    position: absolute; 
 
    left: 415px; 
 
    display: none 
 
} 
 
.mymenu li ul li { 
 
    background-color: #ff6600; 
 
    float: left; 
 
    padding: 0 42px; 
 
    left: 0; 
 
} 
 
.mymenu li:hover ul { 
 
    display: block; 
 
} 
 
/*==================================*/ 
 

 
.myvideo { 
 
    position: fixed; 
 
    height: 100%; 
 
    width: 100%; 
 
    z-index: -10; 
 
    overflow: hidden; 
 
    top: 0; 
 
    left: 0; 
 
} 
 
.myvideo video { 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    min-height: 100%; 
 
    min-width: 100%; 
 
} 
 
.myvideo .mycontent { 
 
    position: absolute; 
 
    height: 100%; 
 
    width: 100%; 
 
    color: #fff; 
 
    background: rgba(0, 0, 0, .2) 
 
} 
 
.clear { 
 
    clear: both; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8"> 
 
    <link rel="stylesheet" href="css/style.css"> 
 
    <title>Document</title> 
 
</head> 
 

 
<body> 
 
    <div class="myvideo"> 
 
    <video autoplay loop muted> 
 
     <source src="video/Vue%20Js%20Tutorial%20Intro%20with%20TodoList%20-%203%20For%20loops%20and%20if.mp4"> 
 
    </video> 
 
    <div class="mycontent"> 
 
     <h1>welcome</h1> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, obcaecati.</p> 
 
    </div> 
 
    </div> 
 
    <div class="clear"></div> 
 
    <ul class="menu2"> 
 
    <li><a href="#">section 1</a> 
 
    </li> 
 
    <li><a href="#">section 2</a> 
 
    </li> 
 
    <li><a href="#">section 3</a> 
 
    </li> 
 
    <li><a href="#">section 4</a> 
 
    </li> 
 
    <li><a href="#">section 5</a> 
 
    </li> 
 
    </ul> 
 
</body> 
 

 
</html>

回答

1

這是因爲.mycontent是絕對定位.myvideo專區內。嘗試重組HTML像這樣:

<body> 
    <div class="myvideo"> 
    <video autoplay loop muted> 
     <source src="video/Vue%20Js%20Tutorial%20Intro%20with%20TodoList%20-%203%20For%20loops%20and%20if.mp4"> 
    </video> 
    </div> 
    <div class="mycontent"> 
    <h1>welcome</h1> 
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, obcaecati.</p> 
    <div class="clear"></div> 
    <ul class="menu2"> 
     <li><a href="#">section 1</a> 
     </li> 
     <li><a href="#">section 2</a> 
     </li> 
     <li><a href="#">section 3</a> 
     </li> 
     <li><a href="#">section 4</a> 
     </li> 
     <li><a href="#">section 5</a> 
     </li> 
    </ul> 
    </div> 
</body> 

在你原來的HTML,它實際上具有絕對定位,不就行了.mycontent