我有一个网站徽标,它位于菜单下,无论浏览网站的大小如何,我都希望两者都延伸到屏幕的边缘。对于图像,我尝试了很多方法,包括宽度:100%和背景:封面;把它带到外面等等。
菜单的html代码:
.navbar {
width: 100%;
background-color: #555;
overflow: auto;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: green;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
<a class="active" href="home.php"><i class="fas fa-home"></i> Home</a>
<a href="gallery.php"><i class="fas fa-images"></i> Gallery</a>
<a href="waitingpage.html"><i class="fas fa-blog"></i> Blog</a>
<a href="contact.php"><i class="fas fa-envelope"></i> Contact</a>
</div>
位于菜单下的图像徽标都不会延伸到屏幕的边缘: html:
<div class="row">
<div class="grid-full">
<a href="Index.html"><img class="Logo" src="Images/logo3.png" alt="Website Logo"></a>
</div>
</div>
在CSS中,Logo
类已经一无所有了。如果那里有人可以帮助将菜单和图像扩展到屏幕的最边缘,我将非常感激。
答案 0 :(得分:2)
尝试使用以下代码。希望对您有用。
body{
margin:0;
}
.navbar {
width: 100%;
background-color: #555;
overflow: auto;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: green;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
.row{
width: 100%;
background-color: #ccc;
text-align:center;
}
.row img{
object-fit: cover;
max-width: 100%;
}
<div class="navbar">
<a class="active" href="home.php"><i class="fas fa-home"></i> Home</a>
<a href="gallery.php"><i class="fas fa-images"></i> Gallery</a>
<a href="waitingpage.html"><i class="fas fa-blog"></i> Blog</a>
<a href="contact.php"><i class="fas fa-envelope"></i> Contact</a>
</div>
<div class="row">
<div class="grid-full">
<a href="Index.html"><img class="Logo" src="https://dummyimage.com/600x400/000/fff" alt="Website Logo"></a>
</div>
</div>
答案 1 :(得分:1)
我已经把它放进了密码笔中,但是我不确定要拉伸的确切含义是什么,因为拉伸“徽标”会有点奇怪。
我用它来定位您的div.row以使其在DOM的视图宽度的100%范围内拉伸-可以在徽标上使用或测试相同的属性,但是由于这是本地文件,因此无法对其进行测试。
.row {
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid red;
}
(边界就在那里显示出它占据了整个宽度)
答案 2 :(得分:0)
如果要将导航栏显示为整页,则需要添加:
@Test
void messageTest(@Mock Messages msg1) {
Set<String> res = new HashSet<>();
res.add("1");
res.add("2");
Mockito.lenient().when(msg1.getKeys()).thenReturn(res);
// ...
我希望这就是你的意思。有了图像,我不禁看到它是本地路径。