gpt4 book ai didi

html - 无法垂直对齐 div 内的所有元素(1 个图像 2 个跨度)2 个跨度应该在彼此的顶部

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:31 25 4
gpt4 key购买 nike

你好,我试了好几天都没有成功,用 HTML 5 和 CSS 创建一个元素 block ,其中有一个包含左侧图像的 div,图像旁边的 2 个文本应该在顶部其他在移动 View 中响应但在普通浏览器 View 中它们应该在一行上。

我已经尝试将来自 SO 的几个 css 解决方案结合起来并取得了部分成功,据我所知,这是我能够实现的最大成果

html {
box-sizing: border-box;
font-size: 62.5%;
}

body {
/*not support gradient browsers*/
background: #002053;
color: white;
font-family: sans-serif;
}

ul {
list-style-type: none;
padding: 0;
}

.wrapper {
width: 100%;
margin: 10 auto;
}

.selected-element {
height:9rem;
border-bottom: 0.1rem solid #ccc;
}

.saved-users {
background-color: rgba(240, 240, 240, 0.3);
}

.segment {
line-height: 3.5rem;
}

.icon {
width: 5em;
height: 5em;
border-radius: 2.5rem;
vertical-align:
}

.user-elements {
font-size: 2.5rem;
}
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="https://necolas.github.io/normalize.css/7.0.0/normalize.css">

<body>
<div class="wrapper">
<main class="container">
<section class="saved-users">
<div class="selected-element" id="freaking-id">
<img src="https://avatars3.githubusercontent.com/u/12096062?v=4" class="icon">
<span class="segment">
<span class="user-elements user-name"> Username </span>
<span class="user-elements time-stamp">2018-10-05 22:49:41</span>
</span>
</div>
<div class="selected-element" id="second-id">
<img src="https://avatars3.githubusercontent.com/u/12096062?v=4" class="icon segment">
<span class="segment">
<span class="user-elements user-name"> Second Username </span>
<span class="user-elements time-stamp">2018-10-07 22:09:41</span>
</span>
</div>
</section>
</main>
</div>
</body>

</html>

最佳答案

您需要使用 CSS 媒体查询来更改移动 View 上的样式。你可以查看这个演示:

html {
box-sizing: border-box;
font-size: 62.5%;
}

body {
/*not support gradient browsers*/
background: #002053;
color: white;
font-family: sans-serif;
}

ul {
list-style-type: none;
padding: 0;
}

.wrapper {
width: 100%;
margin: 10 auto;
}

.selected-element {
height:9rem;
border-bottom: 0.1rem solid #ccc;
line-height: 9rem;
}

.saved-users {
background-color: rgba(240, 240, 240, 0.3);
}

.segment {
line-height: 2rem;
display: inline-block;
vertical-align: middle;
}

.icon {
width: 5em;
height: 5em;
border-radius: 2.5rem;
vertical-align: middle;
display: inline-block;
}

.user-elements {
font-size: 2.5rem;
}

/* Mobile Layout: 320px. */
@media only screen and (max-width: 767px) {
.segment {
max-width: 80%;
line-height: 3rem;
}
.user-elements {
display: block;
}


}
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="https://necolas.github.io/normalize.css/7.0.0/normalize.css">
</head>
<body>
<div class="wrapper">
<main class="container">
<section class="saved-users">
<div class="selected-element" id="freaking-id">
<img src="https://avatars3.githubusercontent.com/u/12096062?v=4" class="icon">
<span class="segment">
<span class="user-elements user-name"> Username </span>
<span class="user-elements time-stamp">2018-10-05 22:49:41</span>
</span>
</div>
<div class="selected-element" id="second-id">
<img src="https://avatars3.githubusercontent.com/u/12096062?v=4" class="icon segment">
<span class="segment">
<span class="user-elements user-name"> Second Username </span>
<span class="user-elements time-stamp">2018-10-07 22:09:41</span>
</span>
</div>
</section>
</main>
</div>
</body>

</html>

关于html - 无法垂直对齐 div 内的所有元素(1 个图像 2 个跨度)2 个跨度应该在彼此的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52693031/

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