Html 如何水平对齐元素?
所有人!!我正在用codepen构建一个非常简单的页面,我对这些东西还很陌生。我想在同一行中对齐导航栏上的所有选项。我甚至不知道为什么他们一开始看起来像这样。我也想对页面末尾的社交媒体图标做同样的处理。这是我的钢笔Html 如何水平对齐元素?,html,css,alignment,Html,Css,Alignment,所有人!!我正在用codepen构建一个非常简单的页面,我对这些东西还很陌生。我想在同一行中对齐导航栏上的所有选项。我甚至不知道为什么他们一开始看起来像这样。我也想对页面末尾的社交媒体图标做同样的处理。这是我的钢笔 .topnav{ 背景色:#586882; 溢出:隐藏;} .topnav a{ 浮动:左; 显示:块; 颜色:#F2F2; 文本对齐:居中; 填充:px 16px; 文字装饰:无; 字体大小:17px;} 这就是你要找的吗 .topnav{ 背景色:#586882; 溢出:隐藏
.topnav{
背景色:#586882;
溢出:隐藏;}
.topnav a{
浮动:左;
显示:块;
颜色:#F2F2;
文本对齐:居中;
填充:px 16px;
文字装饰:无;
字体大小:17px;}
这就是你要找的吗
.topnav{
背景色:#586882;
溢出:隐藏;}
.topnav a{
浮动:左;
显示:块;
颜色:#F2F2;
文本对齐:居中;
填充:16px 16px;
文字装饰:无;
字体大小:17px;}
这就是你要找的吗
.topnav{
背景色:#586882;
溢出:隐藏;}
.topnav a{
浮动:左;
显示:块;
颜色:#F2F2;
文本对齐:居中;
填充:16px 16px;
文字装饰:无;
字体大小:17px;}
更改此选项:
a {
overflow: hidden;
display: inline-block;
margin-bottom: px;
width: calc(50% - 4px);
margin-right: 8px;
}
@media screen and (min-width: 80em) {
a {
width: calc(40% - 6px);
}
a:nth-of-type(2n) {
margin-right: 8px;
}
a:nth-of-type(4n) {
margin-right: 0;
}
}
为此:
a {
overflow: hidden;
display: inline-block;
margin-bottom: px;
width: calc(33% - 4px);
margin-right: 8px;
}
改变这一点:
a {
overflow: hidden;
display: inline-block;
margin-bottom: px;
width: calc(50% - 4px);
margin-right: 8px;
}
@media screen and (min-width: 80em) {
a {
width: calc(40% - 6px);
}
a:nth-of-type(2n) {
margin-right: 8px;
}
a:nth-of-type(4n) {
margin-right: 0;
}
}
为此:
@media screen and (min-width: 80em) {
a {
width: calc(33% - 6px);
}
a:nth-of-type(2n) {
margin-right: 8px;
}
a:nth-of-type(4n) {
margin-right: 0;
}
}
更改此项:
a {
overflow: hidden;
display: inline-block;
margin-bottom: px;
width: calc(50% - 4px);
margin-right: 8px;
}
@media screen and (min-width: 80em) {
a {
width: calc(40% - 6px);
}
a:nth-of-type(2n) {
margin-right: 8px;
}
a:nth-of-type(4n) {
margin-right: 0;
}
}
为此:
a {
overflow: hidden;
display: inline-block;
margin-bottom: px;
width: calc(33% - 4px);
margin-right: 8px;
}
改变这一点:
a {
overflow: hidden;
display: inline-block;
margin-bottom: px;
width: calc(50% - 4px);
margin-right: 8px;
}
@media screen and (min-width: 80em) {
a {
width: calc(40% - 6px);
}
a:nth-of-type(2n) {
margin-right: 8px;
}
a:nth-of-type(4n) {
margin-right: 0;
}
}
为此:
@media screen and (min-width: 80em) {
a {
width: calc(33% - 6px);
}
a:nth-of-type(2n) {
margin-right: 8px;
}
a:nth-of-type(4n) {
margin-right: 0;
}
}
.topnav{
背景色:#586882;
溢出:隐藏;}
.topnav a{
浮动:左;
显示:块;左边距:5px;;
颜色:#F2F2;
文本对齐:居中;
填充:16px;
文字装饰:无;
字体大小:17px;}
.topnav{
背景色:#586882;
溢出:隐藏;}
.topnav a{
浮动:左;
显示:块;左边距:5px;;
颜色:#F2F2;
文本对齐:居中;
填充:16px;
文字装饰:无;
字体大小:17px;}
快速修复方法是添加
width: 33%;
margin: 0;
到css中的.topnav a
但我建议您看看flexbox是如何工作的,因为这将更具响应性
我个人非常喜欢。一个快速解决方法是添加
width: 33%;
margin: 0;
到css中的.topnav a
但我建议您看看flexbox是如何工作的,因为这将更具响应性
我个人非常喜欢。HTML
<body style="background-color:#d1ffe3">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans|Heebo" rel="stylesheet">
<div class="container-fluid">
<ul class="topnav">
<li style="width:100%"><a href="#div_id">ABOUT</a></li>
<li style="width:100%"><a href="#div_id2">PORTFOLIO</a></li>
<li style="width:90%"><a href="#div_id3">CONTACT ME</a></li>
</ul>
<center>
<div id="div_id">
<h1>ABOUT</h1></center>
</div>
<div class="row">
<div class="col-md-6">
<center>
<h2>Hello, I am Maria Pantsiou</h2>
<h1>Former musician, 3D graphics design hobbyist, physicist and potential web developer.<h1>
</center></div>
HTML