简体   繁体   English

如何调整 HTML 导航栏图标的大小

[英]How to resize HTML navbar icon

I have an image that I'm using as the home button for a navbar on a website.我有一张图片用作网站上导航栏的主页按钮。 I want the image height to exceed the height of the navbar (so that it hangs over the bottom of the navbar).我希望图像高度超过导航栏的高度(使其悬在导航栏的底部)。 I tried setting the max-height for the navbar to half of the height for the image/home button, but it just crops the image instead of allowing it to overrun the bar.我尝试将导航栏的最大高度设置为图像/主页按钮高度的一半,但它只是裁剪图像而不是让它超出栏。 How do I style it so that my image/button can be larger than the navbar?如何设置样式以使我的图像/按钮可以大于导航栏?

 <link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/> <div class="w3-bar w3-black w3-card-4 w3-large" style="max-height: 4em;"> <a href="/home"> <img src="{% static 'myProject/images/Logo_nobg.png' %}" style="width: 7em; height: 7em; background: transparent; z-index: 15;"> </a> <div class="w3-right w3-hide-small" style="display: flex; justify-content: right; align-items: center; height: 75px; margin-right: 10px; font-family: Impact, sans-serif; font-size: 1.25em;"> <div class="w3-dropdown-hover"> <button class="w3-button">Services</button> <div class="w3-dropdown-content w3-bar-block w3-card-4"> <a href="/coaching#coach" class="w3-bar-item w3-button w3-white">Coaching</a> <a href="/coaching#rental" class="w3-bar-item w3-button w3-white">Rentals</a> <a href="/coaching#pricing" class="w3-bar-item w3-button w3-white">Packages and Pricing</a> </div> </div> <a href="/sales" class="w3-bar-item w3-button">Sales</a> <a href="/info" class="w3-bar-item w3-button">FAQ</a> <a href="/contact" class="w3-bar-item w3-button">Contact</a> </div> </div> </div>

Your code uses the w3schools design system and for the .w3-bar class it uses overflow hidden, so you'll never be able to move the logo out of there unless you override it.您的代码使用 w3schools 设计系统,对于 .w3-bar 类,它使用溢出隐藏,因此除非您覆盖它,否则您将永远无法将徽标移出那里。

That's what I've done in the code example is override the overflow hidden then use relative position on the containing div then I was able to use absolute positioning on the logo (I used a demo logo so you can see the effect) to move it 15px from the top and left.这就是我在代码示例中所做的是覆盖隐藏的溢出然后在包含的 div 上使用相对位置然后我能够在徽标上使用绝对定位(我使用了演示徽标,因此您可以看到效果)来移动它距离顶部和左侧 15 像素。

Feel free to edit to suit your needs.随意编辑以满足您的需求。

 .relative { position: relative; } .logo-absolute { position: absolute; top: 15px; left: 15px; } .w3-bar { overflow: visible !important; }
 <link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/> <div class="relative w3-bar w3-black w3-card-4 w3-large" style="max-height: 4em;"> <a href="/home"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/W3Schools_logo.svg/512px-W3Schools_logo.svg.png" style="width: 7em; height: 7em; background: transparent; z-index: 15;" class="logo-absolute"> </a> <div class="w3-right w3-hide-small" style="display: flex; justify-content: right; align-items: center; height: 75px; margin-right: 10px; font-family: Impact, sans-serif; font-size: 1.25em;"> <div class="w3-dropdown-hover"> <button class="w3-button">Services</button> <div class="w3-dropdown-content w3-bar-block w3-card-4"> <a href="/coaching#coach" class="w3-bar-item w3-button w3-white">Coaching</a> <a href="/coaching#rental" class="w3-bar-item w3-button w3-white">Rentals</a> <a href="/coaching#pricing" class="w3-bar-item w3-button w3-white">Packages and Pricing</a> </div> </div> <a href="/sales" class="w3-bar-item w3-button">Sales</a> <a href="/info" class="w3-bar-item w3-button">FAQ</a> <a href="/contact" class="w3-bar-item w3-button">Contact</a> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM