html - 将 Div 对齐到中心但保持响应
问题描述
我正在制作一个个人作品集网站,我想将包含圆形(在 CSS 中动画)的 div 居中并对齐,同时保持响应。
我试过 flexbox,这是我的代码:
:root {
--background: #005;
--primary: #88D5BF;
--secondary: #5D6BF8;
--third: #e27fcb;
}
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
background: #f00b55;
display: flex;
align-items: center;
}
.main-logo {
width: 90px;
}
h1 {
color: white;
font-size: 20vmin;
line-height: 1;
font-family: ivypresto-display, serif;
font-weight: 400;
font-style: normal;
padding-left: 40px;
text-align: center;
}
header {
display: flex;
justify-content: center;
align-items: center;
margin-left: 50px;
margin-top: 50px;
}
.blob {
position: absolute;
top: 0;
left: 0;
background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
animation: morph 8s ease-in-out infinite;
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
height: 500px;
transition: all 1s ease-in-out;
width: 500px;
transform-origin: 50% 50%;
z-index: -1;
@keyframes morph {
0% {
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
}
50% {
border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
background: linear-gradient(45deg, var(--third) 0%, var(--secondary) 100%);
}
100% {
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
}
}
}
<!-- Header-->
<header>
<div class="blob">
</div>
<h1>Abbie is a<br>graduate UX/UI designer</h1>
</header>
解决方案
所以如果我理解正确的话。您想将蓝色斑点居中并在其上放置文本吗?正如约翰已经在答案中写的那样。您需要使用媒体查询更改 blob 的高度和宽度。如果要更改 blob 的位置,只需更改:
.blob {
left: 0;
right: 20%; <--- more left
}
:root {
--background: #005;
--primary: #88D5BF;
--secondary: #5D6BF8;
--third: #e27fcb;
}
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
background: #f00b55;
}
h1 {
color: white;
font-size: 20vmin;
line-height: 1;
font-family: ivypresto-display, serif;
font-weight: 400;
font-style: normal;
padding-left: 40px;
text-align: center;
}
header{
display: flex;
justify-content: center;
align-items: center;
margin-left: 50px;
margin-top: 50px;
}
.blob {
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 20%;
text-align: center;
background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
animation: morph 8s ease-in-out infinite;
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
height: 500px;
transition: all 1s ease-in-out;
width: 500px;
transform-origin: 50% 50%;
z-index: -1;
@keyframes morph {
0% {
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
}
50% {
border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
background: linear-gradient(45deg, var(--third) 0%, var(--secondary) 100%);
}
100% {
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
background: linear-gradient(45deg, var(--primary) 0%, var(--secondary) 100%);
}
}
}
<!-- Header-->
<header>
<div class="blob">
</div>
<h1>Abbie is a<br>graduate UX/UI designer</h1>
</header>
推荐阅读
- node.js - 变量作为参数传递给函数和局部变量
- python - 使用python将数据从文件插入到mysql时出错
- python - 如何根据数据框中的值绘制带有颜色的表格?
- arrays - 从文件创建一个数组并根据 bash 中的一行命名
- javascript - 如何检查特定类的所有对象是否也共享另一个类?
- terraform - Azure,terraform 报告 network_interface_id 必须是单个值,而不是创建内部负载均衡器时的列表
- php - 使用 PHP 传递正文标头
- java - Artifactory 无法安装为 Windows 服务
- .htaccess - .htaccess RedirectMatch 排除 index.html
- react-native - 在初始运行时从反应本机项目文件夹中提取 zip 文件