gpt4 book ai didi

html - 如何将两个 float 跨度之间的跨度居中并且容器是固定的?

转载 作者:行者123 更新时间:2023-11-28 03:53:42 26 4
gpt4 key购买 nike

我正在处理标题部分,其中有 3 个跨度,一个向左浮动,一个向右浮动,另一个跨度在中间。中间跨度无论如何都不会水平对齐。

body{
font-family: Myriad Set Pro;
margin: 0;
}


/* ===================== Header Section =============================*/
#header{
width: 100%;
position: fixed;
height: 75px;
line-height: 75px;
box-shadow: 5px 5px 5px #edeff2;
text-align: center;
}

#position{
float: right;
margin-right: 10px;
/*width: 20px;*/
/*margin-top: -75px;*/
}

#logo{
float: left;
height: inherit;
}

#logo:hover{
cursor: pointer;
}

#name{
border: 1px solid black;
position: absolute;
margin: 0px auto;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dash Html</title>
<link rel="stylesheet" type="text/css" href="dash.css">
</head>
<body>

<div id="header">
<a href="https://www.google.com" target="_blank">
<img src="abc.png" id="logo">
</a>
<span id="position"> Developer Developer </span>
<span id="name">SKSV</span>

</div>

</body>
</html>

最佳答案

这是一个更简单的解决方案。将它们包裹在父 div 中并使宽度相等。请看以下内容:

body{
font-family: Myriad Set Pro;
margin: 0;
}


/* ===================== Header Section =============================*/
#header{
width: 100%;
position: fixed;
height: 75px;
line-height: 75px;
box-shadow: 5px 5px 5px #edeff2;
text-align: center;
font-size:0;
}
.header-col
{
display:inline-block;
width:33.3333333334%;
vertical-align:middle;
font-size:13px;
}
#position{
display:block;
text-align:right;
}

#logo{
display:block;
text-align:left;
}


#name{
border: 1px solid black;
display:block;
text-align:center;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dash Html</title>
<link rel="stylesheet" type="text/css" href="dash.css">
</head>
<body>

<div id="header">
<div class="header-col">
<a href="https://www.google.com" target="_blank" id="logo">
<img src="abc.png">
</a>
</div>
<div class="header-col">
<span id="name">SKSV</span>
</div>
<div class="header-col">
<span id="position"> Developer Developer </span>
</div>
</div>

</body>
</html>

关于html - 如何将两个 float 跨度之间的跨度居中并且容器是固定的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43594993/

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