如何使元素内边距最大水平覆盖其 <div>

我正在尝试设计一个下拉菜单,其中菜单的子项更改颜色(绿色),但该项目不会扩展以水平覆盖所有框大小,而使其余部分保持原始颜色。


谢谢你!


HTML文档


<!doctype html>

<html>

    <head>

        <meta charset="utf-8">

        <link rel="stylesheet" href="stylesheet.css">

        <title>Home</title>

    </head>

    <body>

    <div id="container">

        <header>

        <img src="jarir.svg">

        <div id="search"><input></div>

    </header>

    <nav>

    <div class="dropdown">

    <a>All Catgories</a>

    <div class="dropdown_content">

            <a>Link1</a>

            <a>Link2</a>

            <a>Link3</a> 

    </div>


    </div> <!-- dropdown-->

     <a>Shop by Brand</a> <a>Online Exclusive</a>

    </nav>

    </div> <!-- container-->

    </body>

</html>

CSS


#container{}

img{

    width: 130px;

    height: 45px;

}

#search, #search input{

    display: inline-block;

    position: absolute;

    margin: auto;

    margin: 5px 10px;

    width:500px;

    max-width: 500px;

    min-width: 200px;

    background-color: lightgray;

}

nav a{

    margin-right: 30px;

    padding: 10px;

    float:left;

    border-bottom: 0.7mm solid red;

}

nav a:hover{

    border-bottom: 1.2mm solid #3A44F8;

}

.dropdown{

    position: relative;

    display: inline-block;

    float: left;

}<!-- -->

.dropdown:hover .dropdown_content {

    display: block;

    border-bottom: 0px;


}

.dropdown_content a{border-bottom: 0px;}

.dropdown:hover{

    background-color:Blue;

    color: red;

}

.dropdown_content a:hover{ 

    background-color:green;

    color: yellow;

    border: 0px;

    display: block;

}

.dropdown_content {

    display: none;

    position:absolute;

    top: 35px;

    background-color:#f7f7f7;

    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); 

    z-index: 1;

    list-style-type: none;

    color: black;

}


白板的微信
浏览 68回答 1
1回答

慕无忌1623718

你可以试试这个代码。有一些 CSS 更改。 喜欢.dropdown_content a{border-bottom: 0px;display: block;width: 100%;box-sizing: border-box;}#container{}img{&nbsp; &nbsp; width: 130px;&nbsp; &nbsp; height: 45px;}#search, #search input{&nbsp; &nbsp; display: inline-block;&nbsp; &nbsp; position: absolute;&nbsp; &nbsp; margin: auto;&nbsp; &nbsp; margin: 5px 10px;&nbsp; &nbsp; width:500px;&nbsp; &nbsp; max-width: 500px;&nbsp; &nbsp; min-width: 200px;&nbsp; &nbsp; background-color: lightgray;}nav a{&nbsp; &nbsp; margin-right: 30px;&nbsp; &nbsp; padding: 10px;&nbsp; &nbsp; float:left;&nbsp; &nbsp; border-bottom: 0.7mm solid red;}nav a:hover{&nbsp; &nbsp; border-bottom: 1.2mm solid #3A44F8;}.dropdown{&nbsp; &nbsp; position: relative;&nbsp; &nbsp; display: inline-block;&nbsp; &nbsp; float: left;}<!-- -->.dropdown:hover .dropdown_content {&nbsp; &nbsp; display: block;&nbsp; &nbsp; border-bottom: 0px;}.dropdown_content a{border-bottom: 0px;display: block;width: 100%;box-sizing: border-box;}.dropdown:hover{&nbsp; &nbsp; background-color:Blue;&nbsp; &nbsp; color: red;}.dropdown_content a:hover{&nbsp;&nbsp; &nbsp; background-color:green;&nbsp; &nbsp; color: yellow;&nbsp; &nbsp; border: 0px;}.dropdown_content {&nbsp; &nbsp; display: none;&nbsp; &nbsp; position:absolute;&nbsp; &nbsp; top: 35px;&nbsp; &nbsp; background-color:#f7f7f7;&nbsp; &nbsp; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);&nbsp;&nbsp; &nbsp; z-index: 1;&nbsp; &nbsp; list-style-type: none;&nbsp; &nbsp; color: black;}<!DOCTYPE html><html>&nbsp; <head>&nbsp; &nbsp; <meta charset="utf-8" />&nbsp; &nbsp; <link rel="stylesheet" href="stylesheet.css" />&nbsp; &nbsp; <title>Home</title>&nbsp; </head>&nbsp; <body>&nbsp; &nbsp; <div id="container">&nbsp; &nbsp; &nbsp; <header>&nbsp; &nbsp; &nbsp; &nbsp; <img src="jarir.svg" />&nbsp; &nbsp; &nbsp; &nbsp; <div id="search"><input /></div>&nbsp; &nbsp; &nbsp; </header>&nbsp; &nbsp; &nbsp; <nav>&nbsp; &nbsp; &nbsp; &nbsp; <div class="dropdown">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a>All Catgories</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="dropdown_content">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a>Link1</a> <a>Link2</a> <a>Link3</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <!-- dropdown -->&nbsp; &nbsp; &nbsp; &nbsp; <a>Shop by Brand</a> <a>Online Exclusive</a>&nbsp; &nbsp; &nbsp; </nav>&nbsp; &nbsp; </div>&nbsp; &nbsp; <!-- container -->&nbsp; </body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5