我正在尝试创建一个导航菜单,在项目悬停时显示边框。虽然它目前看起来很好,但当其中一个项目悬停时,其他菜单项会被推开。我怎么会让他们留下来?
我尝试了一些在这里得到解决的方法,但没有一种方法有效 我在下面写了一个小提琴。
nav {
float: left;
width: 100%;
}
ul {
float: left;
list-style:none;
padding: 0;
position: relative;
left: 50%;
text-align: center;
}
ul li {
display: block;
float: left;
list-style: none;
position: relative;
right: 50%;
margin: 0px 0px 0px 1px;
padding: 5px 40px;
color: white;
line-height: 1.3em;
}
li a:hover {
border: solid 1px black;
padding: 5px 10px;
}
a {
color: black;
font-family: 'Quicksand', sans-serif;
text-decoration: none;
}
<nav>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT</a></li>
<li><a href="#">MUSIC</a></li>
<li><a href="#">STORE</a></li>
<li><a href="#">LIVE</a></li>
<li><a href="#">CONTACT</a></li>
</ul>
</nav>
答案 0 :(得分:5)
因为您在悬停时添加了填充。将填充从悬停移动到锚点。
li a:hover {
border: solid 1px black;
}
a {
color: black;
font-family: 'Quicksand', sans-serif;
text-decoration: none;
border: solid 1px transparent;
padding: 5px 10px;
}
答案 1 :(得分:3)
移动padding属性来自&#39; li a:hover&#39;到&#39; a&#39;。
<ng-template #template>
<div class="modal-header">
<h4 class="modal-title pull-left">{{modaldata.i.i}}</h4>
<button type="button" class="close btn pull-right" aria-label="Close" (click)="modalRef2.hide()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<mat-card style="margin: 0; ">
<img height="400px" style="width: 110%" mat-card-image [src]="modaldata.i.t || '../../assets/images/noimage.png'">
<mat-card-footer class="row">
<h4>Extra prep. time: 1hr</h4>
<ng-select [allowClear]="true" [items]="items" [disabled]="disabled" (data)="refreshValue($event)" (selected)="selected($event)"
(removed)="removed($event)" (typed)="typed($event)" placeholder="No Date selcted">
</ng-select>
<div *ngFor="let item of list ">
<h4 class="col">{{item.n}}</h4>
<app-dropdowns #child class="col" [listdata]="item"></app-dropdowns>
</div>
<button *ngIf="switch" (click)="productSaveInCart()" type="button" class="col matbuton " mat-button>
ADD to Cart
</button>
</mat-card-footer>
</mat-card>
</div>
</ng-template>