html - 如何将文本移动到页面右侧?

标签 html css

我正在尝试重新创建 www.google.com,如果您在顶部看到左侧有“关于”和“商店”,右侧有“图片”和“Gmail”。我究竟如何才能将图像和 Gmail 置于右侧,同时保留单词之间的空间?

我尝试了填充,但这搞乱了格式,并且 float :正确;将我想要的内容推到右侧,但在单词之间放置 0 间距。

.googlelogo {
  display: block;
  margin: 0 auto;
  margin-top: 150px;
}

.nav a {
  text-decoration: none;
  color: #696969;
}

.nav .gmail,
.nav .images {}
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <link href='/styles/styles.css' text='styles/css' rel='stylesheet'>
  <title>Google</title>
</head>

<body>
  <div class='nav'>
    <a class='about' href='www.google.com/#'>About</a>
    <a class='store' href='www.google.com/#'>Store</a>
    <a class='images' href='www.google.com/#'>Images</a>
    <a class='gmail' href='www.google.com/#'>Gmail</a>

  </div>
  <div class='logo'>
    <img class='googlelogo' src='https://cdn.vox-cdn.com/uploads/chorus_asset/file/4019334/OGB-INSIDER-BLOGS-GoogleLogox2-Animated.0.gif' alt='Google logo' height='100'>
  </div>
</body>

</html>

最佳答案

将这些部分分为 nav-leftnav-right 并使用 flexbox 将它们均匀分布。

.nav {
  display: flex;
  justify-content: space-between;
}

.googlelogo {
  margin: 0 auto;
  margin-top: 150px;
}

.nav { /* Added CSS for Flexbox */
  display: flex;
  justify-content: space-between;
}

.nav a {
  text-decoration: none;
  color: #696969;
}

.nav .gmail,
.nav .images {}
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <link href='/styles/styles.css' text='styles/css' rel='stylesheet'>
  <title>Google</title>
</head>

<body>
  <div class='nav'>
    <div class="nav-left"> <!-- Added HTML: Left Section Wrap -->
      <a class='about' href='www.google.com/#'>About</a>
      <a class='store' href='www.google.com/#'>Store</a>
    </div>
    <div class="nav-right"> <!-- Added HTML: Right Section Wrap -->
      <a class='images' href='www.google.com/#'>Images</a>
      <a class='gmail' href='www.google.com/#'>Gmail</a>
    </div>
  </div>
  <div class='logo'>
    <img class='googlelogo' src='images/google.png' alt='Google logo' height='100'>
  </div>
</body>

</html>

关于html - 如何将文本移动到页面右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56973596/

相关文章:

html - 几乎全屏的iframe

html - 如何将边框分成4等份?

html - 从 mod_autoindex 中删除最后修改时间和大小

javascript - Web“复制到剪贴板”而不触发移动键盘

html - 如何相对于父表单元格定位绝对定位元素

jquery - 无法覆盖外部文件的溢出 CSS 属性

当我放大或缩小时,html 布局困惑

html - 如何在 WP 中隐藏除具有当前菜单祖先的元素之外的完整菜单

javascript 在单击时启用禁用单选按钮并一次仅选择一个

html - 当 'div' 打开时,强制元素向下移动,这样它们就不会与 'details' 相交