gpt4 book ai didi

html - Circle Div 不以 flexbox 为中心

转载 作者:行者123 更新时间:2023-11-28 15:06:44 24 4
gpt4 key购买 nike

在我的标题中,我想在屏幕中央有一个圆圈,在左边有一个 h 1 标签,上面写着我的名字,并随着它缩放。我正在尝试将 flexbox 与它一起使用,但如果我尝试使用 justify-self: center ,我找不到使圆居中的方法,但它不起作用,我不知道我是什么做错了。

我尝试使用 margin: auto,但如果我尝试使用它,则它不会使我的个人资料图片居中,因为类名挡住了边距。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/home.css" rel="stylesheet">
<title>Portofolio</title>
</head>
<body>
<div class="header">
<div class="name">
<h1 class="name">Roel <span id="break"> Voordendag </span></h1>
</div>
<div class="profile-picture">
</div>
</div>
<div class="about">
<span class="about-text">
<p>
</p>
</span>
</div>
</body>
</html>

SCSS

.header{
width: 100%;
display: flex;
@include breakpoint(flex){
flex-direction: column-reverse;
}
}


.header .profile-picture{
width:35%;
border-radius:50%;
padding-bottom:35%;

border-style: solid;
border-width: thin;
border-color: $primary-color;
background-repeat: no-repeat;
background-size: cover;
background-image: url('https://www.istockphoto.com/photos/businessman');
position: relative;
align-self: center;
@include breakpoint(medium){
width: 320px;
height: 320px;
padding-bottom: 0;
justify-self: center;
}
}
.header .name{
color: $primary-color;
font-family: $primary-font;
font-size: 4vw;
text-align: center;
@include breakpoint(medium){
justify-self: flex-start;
align-self: center;
text-align: left;
}
h1{
margin: 0;
padding: 0;
}
}
#break{
@include breakpoint(medium){
display:block;
}
}

断点

@mixin breakpoint($point) {
//laptops to big screens
@if $point == xlarge {
@media (min-width: 1140px) { @content ; }
}
//tablet in horizontal mode
@else if $point == large {
@media (min-width: 992px) { @content ; }
}
//tablet vertical/big phones
@else if $point == medium{
@media (min-width: 786px) { @content ; }
}
//phones
@else if $point == small {
@media (min-width: 360px) { @content ; }
}
@else if $point == flex {
@media (max-width: 786px) { @content ; }
}
}

Breakpoint flex 是我想使用 flexbox 的起点

最佳答案

justify-self 不适用于 flex 元素。

在这种情况下,使用 row 方向并且因为您只想定位 flex 容器的一个元素,请使用自动边距并将 justify-self:center 替换为 左边距:自动;右边距:自动;

如果要居中的元素没有任何默认的上/下边距,也可以使用简写 margin: 0 auto


此外,这里还有几篇文章,介绍了如何对齐 flex 元素:

关于html - Circle Div 不以 flexbox 为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49245186/

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