简体   繁体   English

如何使用css使标题粘

[英]how to make header sticky using css

I want to make a sticky header in my website. 我想在我的网站上贴一个标头。 I am trying following CSS but when I use the CSS below, My logo gets zoomed out when viewed on a mobile device. 我正在尝试遵循CSS,但是当我使用下面的CSS时,在移动设备上查看时,我的徽标会缩小。

URL of the website : http://gomodemo.se/port73/ 网站网址: http : //gomodemo.se/port73/

CSS CSS

@media only screen and (max-width: 768px){

    header{
        position: fixed !important;
        top: 0px;
    }

});

I do not have any issue on the desktop but on a mobile device, the logo gets zoom out.When I click on hamburger menu in the mobile device the logo gets zoom out. 我在台式机上没有任何问题,但是在移动设备上,徽标会缩小。当我在移动设备上单击汉堡包菜单时,徽标会缩小。 Not only logo my header section gets zoom out. 不仅徽标我的标题部分会缩小。 Please help me to resolve the issue. 请帮助我解决问题。 Thank you 谢谢

try this one: 试试这个:

.logo img {
    height: 88px;
    width: 72%;
}

在此处输入图片说明

When styling your logo, be sure to use percentage instead of pixels. 在设计徽标样式时,请务必使用百分比而不是像素。

When using pixels, you are setting the position and size of your logo native to your resolution - causing it to look zoomed when viewed from a different resolution (because your mobile device might have a higher resolution). 使用像素时,您要设置分辨率固有的徽标的位置和大小-使其从其他分辨率观看时看起来会缩放(因为您的移动设备可能具有更高的分辨率)。 If someone who has a higher resolution views your website, there is an area which you have not covered because of the additional pixels on the resolution. 如果分辨率较高的人浏览了您的网站,则由于分辨率上的像素增加,您可能无法覆盖该区域。

I advice you to use height value in Percentage. 我建议您使用百分比中的高度值。 And don't use important unless you don't have another options. 并且除非您没有其他选择,否则不要使用重要的。

You can use below code: 您可以使用以下代码:

@media screen and (min-device-width: 768px) and (max-device-width: 1200px) { 
.logo img {
    margin-top: -10%;
    max-height: 50%;
     }
}

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

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