gpt4 book ai didi

html - 在一个序列中放置两个元素

转载 作者:太空宇宙 更新时间:2023-11-04 08:00:41 25 4
gpt4 key购买 nike

我希望文本和图标(登录、商店)与“ Logo ”处于同一级别,但位于右侧。我尝试通过添加到 '.shop-icon' {margin: -30px auto;} 但它都破坏了页面,然后整个 'nav bar' 和 'article' 覆盖了标题。

我还在学习,但一开始我知道我弄坏了一些东西。

* {
margin: 0;
padding: 0;
}

html {
font-size: 62.5%;
}

body {
font-family: 'Roboto', sans-serif;
background: #2B2B2B;
font-size: 1.6rem;
}

.header-front {
max-width: 992px;
margin: 0 auto;
}

h1.logo {
color: #F6F6F6;
font-size: 4.8rem;
font-weight: 700;
text-align: left;
}

.shop-icon {
text-align: right;
}

.bag,
.account {
color: #F6F6F6;
text-decoration: none;
text-transform: uppercase;
margin: 10px;
}

.main-menu {
background-color: #F7FCFA;
width: 100%;
}

p {
color: #FFFFFF;
}
<body>
<header class="header-front">
<h1 class="logo">Logo </h1>
<div class="shop-icon">
<a href="_blank" class="account">
Login <i class="fa fa-user-o" aria-hidden="true"></i>
</a>

<a href="_blank" class="bag">
shop <i class="fa fa-shopping-bag" aria-hidden="true"></i>
</a>
</div>

</header>

<nav class="main-menu">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</nav>
<article>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ultrices elit eget tortor varius ornare. Etiam commodo sapien dui, in gravida purus malesuada eget. Vestibulum mollis ipsum consectetur ipsum tempor, non sagittis nunc gravida. Aenean
dolor arcu, faucibus a urna nec, pulvinar mollis erat. Pellentesque scelerisque sapien purus, eget porta tellus lacinia ut. Aenean vel ipsum tortor. Ut faucibus sagittis lorem, a molestie enim commodo vel. Maecenas ac placerat nisl. Phasellus felis
elit, tincidunt nec ullamcorper vitae, interdum non leo. </p>
</article>
</body>

</html>

最佳答案

您可以简单地使用 flex。在容器中指定 display:flexalign-items: center 使元素垂直对齐。然后,您将 flex:1 指定为 shop-icon,以便它占用剩余空间,并且您已将其元素右对齐。

* {
margin: 0;
padding: 0;
}

html {
font-size: 62.5%;
}

body {
font-family: 'Roboto', sans-serif;
background: #2B2B2B;
font-size: 1.6rem;
}

.header-front {
max-width: 992px;
margin: 0 auto;
display: flex;
align-items: center;
}

h1.logo {
color: #F6F6F6;
font-size: 4.8rem;
font-weight: 700;
text-align: left;
}

.shop-icon {
text-align: right;
flex: 1;
}

.bag,
.account {
color: #F6F6F6;
text-decoration: none;
text-transform: uppercase;
margin: 10px;
}

.main-menu {
background-color: #F7FCFA;
width: 100%;
}

p {
color: #FFFFFF;
}
<body>
<header class="header-front">
<h1 class="logo">Logo </h1>
<div class="shop-icon">
<a href="_blank" class="account">
Login <i class="fa fa-user-o" aria-hidden="true"></i>
</a>

<a href="_blank" class="bag">
shop <i class="fa fa-shopping-bag" aria-hidden="true"></i>
</a>
</div>

</header>

<nav class="main-menu">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</nav>
<article>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ultrices elit eget tortor varius ornare. Etiam commodo sapien dui, in gravida purus malesuada eget. Vestibulum mollis ipsum consectetur ipsum tempor, non sagittis nunc gravida. Aenean
dolor arcu, faucibus a urna nec, pulvinar mollis erat. Pellentesque scelerisque sapien purus, eget porta tellus lacinia ut. Aenean vel ipsum tortor. Ut faucibus sagittis lorem, a molestie enim commodo vel. Maecenas ac placerat nisl. Phasellus felis
elit, tincidunt nec ullamcorper vitae, interdum non leo. </p>
</article>
</body>

</html>

关于html - 在一个序列中放置两个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47043354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com