我正试图从头开始编写我的第一个网站,最后一天我发现自己被这个问题困住了.我正在try 将我的移动视图的徽标居中.我已经将它们正确地放置在@media标签中,它们显示在网格内,但是经过无数次try 后,我无法让它们位于网格列的中心.如果我的代码乱七八糟,我真的很抱歉.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/styles.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Prata">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter">
    <title>Developer Portfolio</title>
</head>
<body>
    <nav>
    <div class="logo">
        <h3>
            <a href="/">Johnathan Specter</a>
        </h3>
    </div>
        <div class="nav-list">
            <ul>
                <li><a href="#">Articles</a></li>
                <li><a href="#">Chats</a></li>
                <li><a href="#">Awards</a></li>
                <li><a href="#">About</a></li>
                <button class="nav-button">Get in touch</button>
            </ul>
        </div>
    </nav>
    <div class="mob-menu">
        <img src="/Assets/Hamburger Menu.svg" class="hamburger-icon">
        <ul class="mobile-menu">
            <li><a href="#">Articles</a></li>
            <li><a href="#">Chats</a></li>
            <li><a href="#">Awards</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Get in touch</a></li>
        </ul>
    </div>
    <section class="top">
        <div class="top-container">
            <div class="column-left">
                <h1 class="sub-heading">Helping companies build better, scalable software.</h1>
                <p>Award-winning web developer and author with over 15+ years of working experience with Fortune 500 companies like Apple, Google, Facebook, and more.</p>
            </div>
        </div>
    </section>
    <section class="logos">
        <div class="company-logos">
            <img src="/Assets/Logos/Walmart.svg" alt="Walmart logo" class="walmart-logo">
            <img src="/Assets/Logos/JP Morgan.svg" alt="JP Morgan logo">
            <img src="/Assets/Logos/Visa.svg" alt="Visa logo">
            <img src="/Assets/Logos/Tinder.svg" alt="Tinder logo">
            <img src="/Assets/Logos/Samsung.svg" alt="Samsung logo">
            <img src="/Assets/Logos/Verizon.svg" alt="Verizon logo">
        </div>
    </section>
    <section>
        <div class="previews">
            <div class="spense">
                <img src="/Assets/Spense.png" alt="preview of spense.com website" class="spense-img">
                <h2 class="spense-heading">Spense.com</h2>
                <p>Rethinking the way writers get paid, an open-source platform designed to help writers focus more on writing, and less on when and how they'll get paid. Project in collaboration with Codewell.cc</p>
            </div>
            <div class="yelp">
                <img src="/Assets/YelpCamp.png" alt="preview of yelpcamp.com website" class="yelp-img">
                <h2 class="yelp-heading">YelpCamp.com</h2>
                <p>Allowing backpack travelers to perfectly plan their trip through and open-source platform similar to TripAdvisor. With over 1m MAU, YelpCamp has been the crowd's favourite in 2021.</p>
            </div>
        </div>
    </section>
    <section>
        <div class="blurb">
            <div class="blurb1">
                <h1 class="blurb1-heading">A co-founder at one of the world's largest communities.</h1>
                <p>The combined experience I have working at the top Fortune 500 companies has allowed me to developer a skillset that helps me in not just development, but in every aspect of any business.</p>
                <p>I'm proud to announce that I am now working at one of the world's largest communities teaching young minds about how to sell yourself as a developer and open them to a whole new world of opportunities.</p>
            </div>
            <div class="blurb2">
                <p>As a developer, you have everything available to you and all that's holding you back is yourself.</p>
                <p>A quote I live by perfectly illustrates what I mean.</p>
                <p>"How big would you dream, if you knew you wouldn't fail?" You've already gone through the hardest parts being a developer, it's time to elevate your skills and become a leader, in something you're passionate about.</p>
                <p>I'm happy to chat over coffee some time about how I can help your company.</p>
            </div>
        </div>
    </section>
    <section>
        <div class="interested">
            <div class="interested1">
                <h1>Intersted in working with me?</h1>
                <p>I'm active on all social media platforms listed below, but you, can also me an email and I will get back to you within 24-48, hours.</p>
                <button class="git-button">Get in touch</button>
            </div>
            <div class="interested2">
            </div>
        </div>
    </section>
</body>
</html>
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: black;
}

nav {
    display: flex;
    flex-wrap: wrap;
    padding: 2% 6%;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: 'Prata';
    color: #ffffff;
    font-size: 110%;
}

.logo a {
    text-decoration: none;
    font-family: 'Prata';
    color: #ffffff;
}

.logo:hover {
    transform: scale(1.1);
    transition: 0.3s;
}

.nav-list {
    flex: 1;
    text-align: center;
}

.nav-list li {
    list-style: none;
    display: inline-block;
    padding: 8px 12px;
    position: relative;
}

.nav-list li:hover {
    transform: scale(1.1);
    transition: 0.3s;
}

.nav-list li a {
    color: #939495;
    text-decoration: none;
    font-family: 'Inter';
}

.nav-button {
    background-color: #fbe850;
    color: #000000;
    float: right;
    padding: 15px 30px;
    font-family: 'Prata';
}

.nav-button:hover {
    transform: scale(1.1);
    transition: 0.3s;
}

.company-logos {
    display: flex;
    flex-wrap: wrap;
    flex-basis: 100%;
    padding: 2% 6%;
    justify-content: space-between;
}

h1 {
    font-family: 'Prata';
    color: #ffffff;
}

p {
    font-family: 'Inter';
    color: #939495;
}

.top-container {
    display: flex;
    width: 50%;
    padding: 2% 6%;
}

.sub-heading {
    font-size: 250%;
}

.previews {
    display: flex;
    padding: 2% 6%;
    gap: 1rem;
}

.previews > * {
    flex-basis: 100%;
}

.spense-heading {
    font-family: 'Prata';
    color: #ffffff;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.spense p {
    color: #939495;
}

.spense-img {
    height: auto;
    max-width: 100%;
}

.yelp-img {
    height: auto;
    max-width: 100%;
}

.yelp-heading {
    font-family: 'Prata';
    color: #ffffff;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.yelp p {
    color: #939495;
}

.blurb {
    display: flex;
    padding: 2% 6%;
    gap: 1rem;
    background-color: #2e3038;
}

.blurb1 h1 {
    margin-bottom: 1rem;
    color: #ffffff;
}

.blurb1 p {
    margin-bottom: 1rem;
    color: #939495;
}

.blurb2 p {
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    color: #939495;
}

.interested {
    display: flex;
    padding: 2% 6%;
    gap: 1rem;
}

.interested h1 {
    margin-bottom: 1rem;
}

.interested1 p {
    margin-bottom: 1rem;
    margin-right: 1rem;
}

.interested1 {
    flex-basis: 50%;
}

.git-button {
    background-color: #fbe850;
    color: #000000;
    padding: 15px 30px;
    font-family: 'Prata';
}

.git-button:hover {
    transform: scale(1.1);
    transition: 0.3s;
}

.hamburger-icon {
    margin: auto 0;
    display: none;
    cursor: pointer;
}

.mobile-menu {
    display: none;
    position: absolute;
    top: 50px;
    left: 0;
    height: calc(100vh - 50px);
    width: 100%;
}

.open .mobile-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

@media (max-width: 500px) {
    .top-container {
        width: 100%;
        margin-bottom: 3rem;
    }

    .previews {
        display: block;
    }

    .blurb {
        display: block;
    }

    .blurb1 {
        margin-bottom: 3rem;
    }

    .interested {
        display: block;
        max-width: 80%;
    }
}

@media (max-width: 750px) {
    .nav-list {
        display: none;
    }

    .hamburger-icon {
        display:inline-block
    }
}

@media (max-width: 800px) {
    .company-logos {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        align-items: center;
        justify-content: center;
    }
}

我已经用谷歌搜索了很多次,据我所知,这不应该是一个很难解决的问题,我只能假设我有什么东西覆盖了我的代码,阻止我将图像居中.

推荐答案

.company-logos img {
  justify-self: center;
}

我会的.

另一个 Select :

.company-logos img {
  margin: 0 auto;
}

Note:你可能没有意识到,但是你在你的系统上发布了除了图片以外的所有东西,因为它们是相对的.你应该用一些随机图像URL或一些图像占位符(例如:https://via.placeholder.com/150)替换src


工作示例:

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

body {
  background-color: black;
}

.company-logos {
  display: flex;
  flex-wrap: wrap;
  flex-basis: 100%;
  padding: 2% 6%;
  justify-content: space-between;
}

@media(max-width: 1050px) {
  .company-logos {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
}

@media (max-width: 800px) {
  .company-logos {
    grid-template-columns: repeat(2, 1fr);
  }
}

.company-logos img {
  justify-self: center;
}
    <section class="logos">
        <div class="company-logos">
            <img src="https://via.placeholder.com/150" alt="Walmart logo" class="walmart-logo">
            <img src="https://via.placeholder.com/150" alt="JP Morgan logo">
            <img src="https://via.placeholder.com/150" alt="Visa logo">
            <img src="https://via.placeholder.com/150" alt="Tinder logo">
            <img src="https://via.placeholder.com/150" alt="Samsung logo">
            <img src="https://via.placeholder.com/150" alt="Verizon logo">
        </div>
    </section>

Note:我删除了所有与问题无关的代码.

Html相关问答推荐

卡片上方的文本

选中/取消选中带有_hyperscript的多个复选框

需要关于HTML的建议

如何影响flex项目中的flex-gap收缩顺序和文本换行顺序?

如何使用css横向显示英文和中日韩文字?

在R中从网页上的特定iframe中提取图形数据

如何使背景图像在面包屑中相互重叠

目标第一个祖先标签的 XPath

为什么带有截断的 contentedible div 在受约束时会在 Chrome 中添加空格

网格项未在同一行上对齐

当浏览器宽度减小时字体大小变得太大

HTML 重定向到当前服务器

在HTML使用link标签导入外部CSS时出现元素link不允许使用尾斜杠错误

实验的响应式屏幕尺寸

如何消除线性渐变线的模糊?

如何并排放置
的定义列表,但如果
变长,
会向下移动?

如何将某些 div 的高度限制为具有 display flex 行的同一父 div 中的其他 div?

不理解 CSS 中的 General sibling combinator (~)

当另一个 div 的高度改变或执行其内容的换行时,将 flex 方向更改为列

Select 除第一个匹配的子元素之外的第 nth-child(n)