gpt4 book ai didi

html - 设计不适用于跨度和按钮

转载 作者:太空狗 更新时间:2023-10-29 12:32:09 26 4
gpt4 key购买 nike

我正在尝试将 button 与 2 个 span 对齐。 2 个 span 彼此重叠,我想在第二个 span 旁边显示 button

这是我的 CSS:

/* Styles go here */

.contacts {
position: absolute;
top: 0;
left: 70px;
}

.contacts .name {
font-weight: 700;
display: block;
}

li {
position: relative;
margin-bottom: 30px;
}
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap-css@3.3.6" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<ul>
<li>
<div class="contacts">
<span class="name">short name</span>
<span class="city">City</span>
<button class="btn btn-default btn-sm pull-right">Contact</button>
</div>
</li>
<li>
<div class="contacts">
<span class="name">very long name will be here</span>
<span class="city">city</span>
<button class="btn btn-primary btn-sm pull-right">Contact</button>
</div>
</li>
<li>
<div class="contacts">
<span class="name">another long name will be here too</span>
<span class="city">city</span>
<button class="btn btn-default btn-sm pull-right">Contact</button>
</div>
</li>
</ul>
</body>
</html>

当名称太长时,如何对齐 button 并使其不移动,是否可以在没有 Bootstrap 的情况下完成?

感谢您的任何提示。

最佳答案

只需从按钮中删除 pull-right 类即可。

/* Styles go here */

.contacts {
position: absolute;
top: 0;
left: 70px;
}

.contacts .name {
font-weight: 700;
display: block;
}

li {
position: relative;
margin-bottom: 30px;
}
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap-css@3.3.6" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<ul>
<li>
<div class="contacts">
<span class="name">short name</span>
<span class="city">City</span>
<button class="btn btn-default btn-sm pull-right">Contact</button>
</div>
</li>
<li>
<div class="contacts">
<span class="name">very long name will be here</span>
<span class="city">city</span>
<button class="btn btn-primary btn-sm">Contact</button>
</div>
</li>
<li>
<div class="contacts">
<span class="name">another long name will be here too</span>
<span class="city">city</span>
<button class="btn btn-default btn-sm">Contact</button>
</div>
</li>
</ul>
</body>
</html>

关于html - 设计不适用于跨度和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37486865/

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