html - 如何将文本移动到页面右侧?
问题描述
我正在尝试重新创建 www.google.com,如果您在顶部看到左侧有“关于”和“商店”,右侧有“图片”和“Gmail”。我怎样才能将图像和 Gmail 放在右侧,同时保留单词之间的空间?
我尝试了填充,但这弄乱了格式,并且浮动:对;将我想要的内容推到右侧,但在单词之间放置 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-left
和nav-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>
推荐阅读
- ruby-on-rails - 在rails devise gem中保存自定义属性的问题
- android - Recyclerview 适配器 onBindViewHolder 有效负载不工作
- java - 如何在不冻结 Java Swing 中的 GUI 的情况下与进程随机通信?
- python - 如何在基于 ORM 异常的 Django 视图中引发异常
- javascript - wicked_pdf PDF 生成:重置页码并再次从 1 开始编号
- python - IDLE 3.8.2 中的错误消息:没有名为“discord”的模块
- php - Laravel 更新功能不起作用并且没有显示错误
- f# - F# 中带有条件的生成器
- macos - 3.在Mac OS X上运行的emacs中如何输入Neo2键盘布局的平面字符?
- html - 使用 Bootstrap 为低分辨率显示自适应网站布局时出现问题