英文:
How do I get my logo to align left, and links right?
问题
Sure, here is the translated content you provided:
我对CSS还很陌生,正在尝试弄清楚如何将我的标志放在导航链接的上面。我希望我的标志位于左侧,链接位于右侧。
我在这里添加了一些HTML!我的标志也变得非常大,似乎没有不将显示设置为flex并将内容调整为space-between就无法工作。
```CSS部分已经翻译,以下是HTML部分。
<header>
<div class="hero">
<div class="container">
<nav class="navbar">
<div class="logo"><img src="Logo/logo.svg" alt="vic logo"/>
</div>
<ul class="nav_links">
<li class="active">
<a href="index.html" class="nav_links">home</a>
</li>
<li>
<a href="stills.html" class="nav_links">stills</a>
</li>
<li>
<a href="designs.html" class="nav_links">designs</a>
</li>
</ul>
</nav>
我尝试跟随一些教程,但似乎还不太起作用。
英文:
I'm new to css and trying to figure out how to get my logo on top of my nav links. I'd like my logo to be on the left with links on the right.
I've just added in some html here as well! My logo is also just getting really large and doesn't seem to work without having a display as flex and the content justified to space-between.
.logo {
width: 240px;
height: 120px;
display: inline-block;
float: left;
}
.logo:hover{
transform: scale(1.4) rotate(180deg);
}
.navbar {
display: inline-block;
width: 100%;
padding-top: 4px;
padding-bottom: 4px;
font-size: 18px;
align-items:center;
}
.nav_links:hover {
color:#3f8b7b;
text-decoration: underline;
font-weight: 600;
}
.nav_links, ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
}
.nav_links li {
display: inline-block;
padding: 0px 20px;
}
li, a {
display: inline;
float: left;
font-size: 24px;
font-family: Arial, Helvetica, sans-serif;
font-weight:500;
margin-left: 24px;
margin-top: 24px;
margin-bottom: 36px;
text-decoration: none;
color: #191a1a;
}
<header>
<div class="hero">
<div class="container">
<nav class="navbar">
<div class="logo"><img src="Logo/logo.svg" alt="vic logo"/>
</div>
<ul class="nav_links">
<li class="active">
<a href="index.html" class="nav_links">home</a>
<li>
<a href="stills.html" class="nav_links">stills</a>
</li>
<li>
<a href="designs.html" class="nav_links">designs</a>
</li>
</ul>
</nav>
I tried to follow along with a couple tutorials but it's not quite working.
答案1
得分: 1
以下是您要翻译的部分:
"我不确定我理解将标志翻转180度并以您的方式缩放的原因,但一般来说,要将标志放在左边并将导航链接放在右边,您可以按照以下步骤进行操作:
- 将您的标志和导航放入div或其他允许进行样式设置的容器中。
- 将容器的display属性设置为“flex”,并将justify-content设置为“space-between”(除了使用flex之外,还有其他几种方法可以实现,但这是一种非常直接的解决方案)。这样做通常会将标志放在左侧,导航链接放在右侧。
- 到了这一步,您应该能够删除标志和导航栏的float属性,并且可能可以删除导航的display属性;因为我们使用了flex,所以不再需要它。
我注意到您还选择在列表项上(.nav_links
)使用了与无序列表相同的类名。一般来说,您不应该这样做。请注意,上面的HTML更改了应用于列表项中链接的类的名称。
如果您遇到任何问题或有任何问题,请告诉我。"
英文:
I am not sure I understand the reasoning for flipping the logo 180º and scaling it the way you have, but in general, to get your logo on the left and your nav links on the right, you can follow these steps:
- Wrap your logo and navigation into divs or another form of container that allows them to be styled.
- Set the container's display property to "flex" and set justify-content to "space-between". (There are several ways to do this other than using flex, but this is a very straightforward solution.) Doing it this way will generally place the logo on the left and the nav links on the right.
- At this point, you should be able to get rid of the fload properties from your logo and navbar, and you can probably remove the display property from the navigation; you won't need it since we're using flex.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 4px; /* this is an arbitrary number; adjust as needed */
padding-bottom: 4px;
font-size: 18px; /* You set this here but then set the link font-size to 24px? */
font-family: Arial, Helvetica, sans-serif;
color: #191a1a;
}
.logo {
width: 240px;
height: 120px;
}
.logo:hover{
transform: scale(1.4) rotate(180deg);
}
.logo img {
max-width: 100px;
}
.nav_links {
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
}
.nav_links li {
margin-left: 24px;
}
.nav_links li:first-child {
margin-left: 0;
}
li a {
color: #191a1a;
display: inline-block;
text-decoration: none;
font-size: 24px;
font-family: Arial, Helvetica, sans-serif;
font-weight: 500;
margin-bottom: 36px;
}
li a:hover {
color: #3f8b7b;
text-decoration: underline;
font-weight: 600;
}
li.active a {
color: #3f8b7b;
font-weight: 600;
text-decoration: underline;
}
<!-- language: lang-html -->
<nav class="navbar">
<div class="logo">
<img src="Logo/logo.svg" alt="vic logo"/>
</div>
<ul class="nav_links">
<li class="active">
<a href="index.html" class="nav_link">home</a>
</li>
<li>
<a href="stills.html" class="nav_link">stills</a>
</li>
<li>
<a href="designs.html" class="nav_link">designs</a>
</li>
</ul>
</nav>
<!-- end snippet -->
I noticed that you also chose to use the same class name on the list items (.nav_links
) as you chose for the unordered list. In general, you don't want to do that. Notice that my HTML above changes the name of the class applied to the links in the list items.
Let me know if you run into any issues or have any questions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论