简体   繁体   English

将 Logo 和 Company 捕捉到左侧,将导航栏捕捉到右侧

[英]snapping Logo and Company to the left and nav-bar to the right

I'm styling a Header and Navigation bar for a landing page.我正在为登陆页面设计 Header 和导航栏。 My aim is to have the company name - <h1> , placed right next to logo - <img> .我的目标是将公司名称 - <h1>放在徽标 - <img>旁边。 However I would need the navigation bar to be slammed to the right.The navigation bar also need to be responsive to the width of the page.但是,我需要将导航栏撞到右侧。导航栏还需要响应页面的宽度。 I've included a basic picture of what I'm attempting to have done.我已经包含了我正在尝试做的事情的基本图片。 My goal is to be able to replace Logo and Company name with pretty much any image or name in the future.我的目标是将来能够用几乎任何图像或名称替换徽标和公司名称。 The whole header needs to fixed at the top.整个 header 需要固定在顶部。

标题导航样式

here is my CSS & HTML这是我的 CSS & HTML

 * { box-sizing: border-box; font-size: 10px; margin: 0px; padding: 0px; } h1 { font-size: 3rem; } #header-img { height: 3rem; } #nav-link { list-style-type: none; } #header { display: flex; justify-content: space-between; align-items: center; } nav > ul { display: flex; justify-content: space-around; } #nav-bar { width: 35vw; }
 <header id="header"> <img id="header-img" src="https://w0.pngwave.com/png/91/429/web-development-html-css3-the-ohana-code-logo-2cpaper-projection-shaded-1660937-html-dropdown-js-png-clip-art.png" alt=""> <h1>Company Name</h1> <nav id="nav-bar"> <ul> <li id="nav-link"><a href="#nav-link1">Nav Link 1</a></li> <li id="nav-link"><a href="#nav-link2">Nav Link 2</a></li> <li id="nav-link"><a href="#nav-link2">Nav Link 3</a></li> </ul> </nav> </header>

Nest the Logo - <img> and Company Name - <h1> into it's own div and use display: flex;将徽标 - <img>和公司名称 - <h1>嵌套到它自己的div中并使用display: flex; to have them align horizontally.让它们水平对齐。

 * { box-sizing: border-box; font-size: 10px; margin: 0px; padding: 0px; } h1 { font-size: 3rem; } #header-img { height: 3rem; } #logo-companyname { display: flex; } #nav-link { list-style-type: none; } #header { display: flex; justify-content: space-between; align-items: center; } nav > ul { display: flex; justify-content: space-around; } #nav-bar { width: 35vw; }
 <header id="header"> <div id="logo-companyname"> <img id="header-img" src="https://w0.pngwave.com/png/91/429/web-development-html-css3-the-ohana-code-logo-2cpaper-projection-shaded-1660937-html-dropdown-js-png-clip-art.png" alt=""> <h1>Company Name</h1> </div> <nav id="nav-bar"> <ul> <li id="nav-link"><a href="#nav-link1">Nav Link 1</a></li> <li id="nav-link"><a href="#nav-link2">Nav Link 2</a></li> <li id="nav-link"><a href="#nav-link2">Nav Link 3</a></li> </ul> </nav> </header>

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

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