html - 单独的段落不单独显示
问题描述
我正在尝试为网站创建一个统计区域。在台式机上应该是两个,在移动设备上应该是堆叠的。如果将内部 DIV 的内容堆叠起来会很好,但我不知道该怎么做。
这是我的代码
.site-stats-wrap {
width: 100%;
margin-left: auto;
margin-right: auto;
background: pink;
margin-top: 10px;
margin-bottom: 10px;
}
@media only screen and (max-width: 500px) {
.site-stats-wrap {
width: 100%;
margin-left: auto;
margin-right: auto;
background: pink;
margin-top: 15px;
margin-bottom: 15px;
}
}
.site-stats-group {
width: 100%;
display: table;
}
.site-stat-title {
width: 50%;
float: left;
}
@media only screen and (max-width: 500px) {
.site-stat-title {
width: 100%;
float: left;
}
}
.site-stat-info {
width: 50%;
float: left;
}
@media only screen and (max-width: 500px) {
.site-stat-info {
width: 100%;
float: left;
}
}
.site-stat-title-display {
width: 80%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.site-stat-info-display {
width: 80%;
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
}
.site-stat-title {
font-family: 'Roboto', sans-serif;
font-size: 35px;
line-height: normal;
margin: 0;
}
@media only screen and (max-width: 500px) {
.site-stat-title {
font-family: 'Roboto', sans-serif;
font-size: 25px;
line-height: normal;
margin: 0;
}
}
.site-stat-subtitle {
font-family: 'Roboto', sans-serif;
font-size: 30px;
line-height: normal;
margin: 0;
}
@media only screen and (max-width: 500px) {
.site-stat-subtitle {
font-family: 'Roboto', sans-serif;
font-size: 20px;
line-height: normal;
margin: 0;
}
}
<div class="site-stats-wrap">
<div class="site-stats-group">
<div class="site-stat-title">
<div class="site-stat-title-display">
<p class="site-stats-title">Statistics</p>
</div>
</div>
<div class="site-stat-info">
<div class="site-stat-info-display">
<p class="site-stat-title">Title</p>
<p class="site-stat-subtitle">A Short Description</p>
<br>
<p class="site-stat-title">Title</p>
<p class="site-stat-subtitle">A Short Description</p>
</div>
</div>
</div>
</div>
我现在面临的问题是 A)每列的内容没有居中(他们只是根据内容在移动设备上获取高度,但需要在包装器内的桌面上保持相同的高度) B)内的文本stats 部分不会出现在单独的行上。
任何以内容为中心并帮助解决文本问题的答案将不胜感激。
UPDATE
基于Andrew Halpern的回答。
.wrap {
width: 100%;
display: flex;
background: pink;
margin-top: 10px;
margin-bottom: 10px;
align-items: center;
justify-content: center;
flex-flow: row wrap;
text-align: center;
}
.col1 {
width: 50%;
}
@media only screen and (max-width: 500px) {
.col1 {
width: 100%;
}
}
.col2 {
width: 50%;
}
@media only screen and (max-width: 500px) {
.col2 {
width: 100%;
}
}
<div class="wrap">
<div class="col1">
<h1>I'm Centered</h1>
</div>
<div class="col2">
<h1>I'm Centered Too</h1>
<h1>I'm Centered Too</h1>
<h1>I'm Centered Too</h1>
</div>
</div>
解决方案
CSS:
.container {
width: 50%;
margin: 0 auto;
display: grid;
grid-template-columns: repeat(2, 1fr);
}
.left-side,
.right-side {
padding: 2rem;
display: flex;
justify-content: center;
align-items: center;
}
.left-side {
background-color: crimson;
}
.right-side {
background-color: cornflowerblue;
}
@media screen and (max-width: 768px) {
.container {
width: 100%;
grid-template-columns: 1fr;
}
}
的HTML:
<div class="container">
<div class="left-side">
<h1>Centered.</h1>
</div>
<div class="right-side">
<div class="items">
<h1>Centered.</h1>
<h1>Centered.</h1>
<h1>Centered.</h1>
</div>
</div>
</div>
推荐阅读
- javascript - 您如何使 Google Cloud Search 的“排序依据”按钮可访问?现在您无法使用“Tab”按钮访问它
- javascript - 用 onChange 事件焦点在光标位置上反应输入掩码问题
- python - Django 日历推荐 - HTMLCalendar 没有每周视图
- flutter - 如何在颤振中构建apk时排除文件
- c - 如何在无限循环中将C中的变量重置回0?
- sql - 在没有聚合的 SQL 中将行透视到列
- java - 有没有办法将 KLV 添加到 MPEG-TS.H264 视频直播中?
- javascript - 每个纹理上的 PIXIJS 纹理旋转
- math - 字节数学计算
- oop - 在父类中使用 super() 方法