2016-11-25 43 views
1

我试图让徽标响应并在小屏幕和大屏幕上保持相同的比例。但是,标识在笔记本电脑上的全分辨率下过大,但在较小的屏幕上接近正确尺寸。任何关于如何修复图像大小的帮助表示赞赏。哦,请不要告诉我使用bootstrap或任何框架!HTML5 CSS3 Logo和NavBar Responsive(NO BOOTSTRAP !!)

Click here for cookies!

/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */ 
 
function myFunction() { 
 
    var x = document.getElementById("myTopnav"); 
 
    if (x.className === "topnav") { 
 
    x.className += " responsive"; 
 
    } else { 
 
    x.className = "topnav"; 
 
    } 
 
}
html, 
 
body { 
 
    margin: 0px; 
 
    padding: 0px; 
 
    height: 100%; 
 
    border: 2px blue solid; 
 
} 
 
#logo { 
 
    display: block; 
 
    width: 35%; 
 
    float: left; 
 
    border-style: 2px green solid; 
 
    border: 2px red solid; 
 
} 
 
/* Remove margins and padding from the list, and add a black background color */ 
 

 
ul.topnav { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: #333; 
 
} 
 
/* Float the list items side by side */ 
 

 
ul.topnav li { 
 
    float: left; 
 
} 
 
/* Style the links inside the list items */ 
 

 
ul.topnav li a { 
 
    display: inline-block; 
 
    color: #f2f2f2; 
 
    text-align: center; 
 
    padding: 14px 16px; 
 
    text-decoration: none; 
 
    transition: 0.3s; 
 
    font-size: 17px; 
 
} 
 
/* Change background color of links on hover */ 
 

 
ul.topnav li a:hover { 
 
    background-color: #555; 
 
} 
 
/* Hide the list item that contains the link that should open and close the topnav on small screens */ 
 

 
ul.topnav li.icon { 
 
    display: none; 
 
} 
 
/* When the screen is less than 680 pixels wide, hide all list items, except for the first one ("Home"). Show the list item that contains the link to open and close the topnav (li.icon) */ 
 

 
@media screen and (max-width: 680px) { 
 
    ul.topnav li:not(:first-child) { 
 
    display: none; 
 
    } 
 
    ul.topnav li.icon { 
 
    float: right; 
 
    display: inline-block; 
 
    } 
 
} 
 
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens */ 
 

 
@media screen and (max-width: 680px) { 
 
    ul.topnav.responsive { 
 
    position: relative; 
 
    } 
 
    ul.topnav.responsive li.icon { 
 
    position: absolute; 
 
    right: 0; 
 
    top: 0; 
 
    } 
 
    ul.topnav.responsive li { 
 
    float: none; 
 
    display: inline; 
 
    } 
 
    ul.topnav.responsive li a { 
 
    display: block; 
 
    text-align: left; 
 
    } 
 
}
<title> 
 

 

 

 
    Archery Club</title> 
 

 
<body> 
 

 
    <!--Defines a header for a document or a section--> 
 
    <header> 
 
    </header> 
 

 
    <!--Defines a container for navigation links--> 
 
    <nav> 
 
    <ul class="topnav" id="myTopnav"> 
 
     <img id="logo" src="https://res.cloudinary.com/durjwdzkx/image/upload/v1480113900/IMG001_kwt1of.png" /> 
 
     <li><a href="#">Home</a> 
 
     </li> 
 
     <li><a href="#">About</a> 
 
     </li> 
 
     <li><a href="#">Contact</a> 
 
     </li> 
 
     <li><a href="#">Location</a> 
 
     </li> 
 
     <li><a href="#">Competitions</a> 
 
     </li> 
 
     <li class="icon"> 
 
     <a href="javascript:void(0);" onclick="myFunction()">&#9776;</a> 
 
     </li> 
 
    </ul> 
 

 
    </nav> 
 

 

 
    <!-- Defines a footer for a document or a section--> 
 
    <footer> 
 
    Site by: Me &copy; 2016 
 
    </footer> 
 

 
</body>

+0

也许徽标尺寸太大而无法启动? –

+0

@AlekseiMaide典型的标志尺寸是什么尺寸? – Konahrik16

+0

网络上的图像不应大于它们需要的宽度:)带宽/加载时间等等,图像的大小应该尽可能大,以便在不牺牲质量的情况下以最大预期分辨率显示图像。 –

回答

0

的事实,图像显然是偏大还是先调整图像中的任何图像编辑软件来看

<img id="logo" src=""> 

CSS:

#logo { 
width: %; //whatever percentage you find most appropriate 
} 

但请记住,宽度取决于父容器(100%是父级的宽度)。

在你的情况下,父母是“ul”,占据了宽度的100%,因此标志占据宽度的35%。