有趣的CSS问题 “左边有图标,右边没有图标,如何将导航既能居中显示,又能在超长文本的情况下铺满导航”?
问题: “左边有图标,右边没有图标,如何将导航既能居中显示,又能在超长文本的情况下铺满导航”?
这个问题是和Yuki聊天中获知的,感觉确实挺有趣的。
可以拿来作为面试题玩。
你觉得解决方案应该是什么样的呢?
答案 👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body,
html {
margin: 0;
padding: 0;
width: 100%;
}
.wrap {
width: 100%;
background-color: #eee;
margin: 0;
padding: 0;
height: 50px;
display: flex;
align-items: center;
padding: 0 10px;
box-sizing: border-box;
}
.wrap .icon {
width: 40px;
height: 50px;
background-color: green;
}
.wrap .content {
min-width: calc(100% - 80px);
max-width: calc(100% - 40px);
text-align: center;
background-color: #ccc;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="wrap">
<div class="icon"></div>
<div class="content">测试</div>
</div>
<br />
<div class="wrap">
<div class="icon"></div>
<div class="content">
测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
</div>
</div>
</body>
</html>

日本千叶县
晴
Redmi K30 Speed 5G
like
dislike
comment
1030
comments0
ShiinaAiiko.NO.00004欢迎旅行者到此一游
推荐
从未发布过哦