css - 我如何更改图像并将其居中

标签 css flexbox

我怎样才能改变图片并使其对着 flexbox 居中?

我尝试添加宽度和高度但奇怪地移动并且看不到 png。 我也关心响应式 谢谢你的帮助

CSS 代码

.container{
    width: 100%;
    height: 50vh;
    border-top: 4px solid rgb(134, 17, 212);
    display: flex;
    justify-content: space-evenly;
    padding-top: 15px;
    background: rgb(20, 20, 19);
}

.contact, .projects, .me{
    background: rgb(20, 20, 19);
    width: 100%;
    display: flex;
    color: white;
    justify-content: space-evenly;
    font-size: 1.3em;
}

.contact {
    background: url('cntct.png') top center no-repeat;
    width:
}

HTML代码

  <div class="container">
        <div class="contact">Kontakt</div>
        <div class="projects">Projekty</div>
        <div class="me">O mnie</div>
    </div>

</div>

enter image description here

最佳答案

你能添加一张你想要它看起来像什么的图片吗?如果没有它,我可以建议添加 background-size: 50px, auto, contain; 来调整背景图像的大小。下面是一个使用示例联系人图像的示例:

  .container{
        width: 100%;
        height: 50vh;
        border-top: 4px solid rgb(134, 17, 212);
        display: flex;
        justify-content: space-evenly;
        padding-top: 15px;
        background: rgb(20, 20, 19);
    }
    
    .contact, .projects, .me{
        background: rgb(20, 20, 19);
        width: 100%;
        display: flex;
        color: white;
        justify-content: space-evenly;
        font-size: 1.3em;
    }
    
    .contact {
        background: url('https://cdn.pixabay.com/photo/2016/06/13/17/30/mail-1454732_960_720.png') top center no-repeat;
        background-size: 50px, auto, contain;
        
    }
      <div class="container">
            <div class="contact">Kontakt</div>
            <div class="projects">Projekty</div>
            <div class="me">O mnie</div>
        </div>

    </div>

你也可以把它放在 flexbox 的任何地方:background: url('cntct.png') 50% 25px no-repeat; 例如:

enter image description here

关于css - 我如何更改图像并将其居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56449666/

相关文章:

html - 显示 flexbox 居中但左对齐元素像文本左对齐

javascript - 如何使用jquery计算高度

html - 居中和右对齐flexbox元素

css - 在 flex 容器的剩余空间(不是全宽)中水平居中 flex 元素

html - 元素应占用可用的水平空间并在必要时中断

html - Bootstrap 列包装在移动设备上,应该完全适合内联

html - "overflow-y: scroll;"隐藏水平线上溢出的元素

css - 将边框应用于 Chrome 中的复选框

HTML - 重新排序 Bootstrap 列

css - 在与正方形 <div> 重叠的地方剪裁圆形框阴影