gpt4 book ai didi

html - 调整页面大小时div移动

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

我在尝试重新创建的网站上有一个时间轴,当我将窗口大小时调整为移动设备时,div 分开了。我对网站的了解有点远,并且对我需要做什么才能使这项工作非常谨慎。时间线有图标(有自己的 div)和图标背景(也有自己的 div)但我想我需要将它们包裹在一个更大的 div 中才能完成这项工作,但不确定如何进行。

在此处查看调整大小之前和调整大小之后的图片:

enter image description here

看看图标是如何从背景中分离出来的?

enter image description here

时间轴中每一项的HTML代码:

                    <div class="timeline_item">
<div class="timeline_time"><p><em>1 hr ago</em></p></div>
<div class="icon_background"></div>
<div class="timeline_icon "><i class="ss-icon">doc</i></div>
<div class="timeline_text"><p>You read the article </p> </div>
</div>

CSS:

.timeline_item {
width: 100%;
padding-bottom: 17%;
}

.timeline_item .timeline_time {
float: left;
width: 20%;
}

.timeline_item .timeline_icon {
float: left;
width: 1%;
}

.timeline_item .timeline_text {
float: left;
width: 65%;
padding-left: 3%;
}

.timeline_icon {
margin-left: -4%;
margin-top: 2.5%;
}

最佳答案

在无法访问正确的 Jsfiddle 演示的情况下,这里有一个使用伪元素的简化 HTML 结构的建议。

你可以使用图标字体、sprite 或任何我使用单个字母的地方。

Codepen Demo

HTML

<div class="timeline">

<article class="timeline_item">
<div class="timeline_time">
<p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="doc"><p>You read the article </p> </div>
</article>

<article class="timeline_item">
<div class="timeline_time">
<p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="alert"><p>You have a 'Do Not Miss' Meeting scheduled for tomorrow 9a.m.</p> </div>
</article>

<article class="timeline_item">
<div class="timeline_time"><p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="video"><p>You watched a video</p> </div>
</article>

</div>

CSS

* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}

.timeline {
width:50%;
margin: 1rem auto;
border:1px solid lightgrey;
}

.timeline_item {
display: table;
width:100%;
}
.timeline_time,
.timeline_text {
display: table-cell;
padding:1rem 2rem;
}

.timeline_time {
width:25%;
text-align: right;
border-right:1px solid lightgrey;
}

.timeline_text {
position: relative;
}
[data-event-type]:before {
position: absolute;
content:"";
width:32px;
height:32px;
line-height: 32px;
text-align: center;
color:white;
left:0;
top:0;
border-radius: 50%;
transform:translate(-50%,50%);
}

[data-event-type="doc"]:before {
content:"D";
background: #00f;
}

[data-event-type="alert"]:before {
content:"A";
background: #f00;
}
[data-event-type="video"]:before {
content:"V";
background: #0f0;
}

此处展示的技术可能会帮助您解决当前的问题。

当然,这种布局方法还有其他选择,包括 float 和实际表格。其中一些需要“修复”才能实现 CSS 表格固有的“等高”。

关于html - 调整页面大小时div移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25165018/

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