【问题标题】:how to adjust padding in html/css?如何调整 html/css 中的填充?
【发布时间】:2020-06-27 18:04:25
【问题描述】:

我想在图像上填充以接近剩余部分,但对我没有任何作用。 我正在尝试:

 float-right or padding-right:250px; // but nothing happent and also it will spoil my mobile view also.

请检查我在做什么:

    .fontProfile {
    font-family: "Open Sans", Arial, sans-serif;
    /* min-height: 100vh;
    background-color: #fafafa;
    color: #262626;
    padding-bottom: 3rem; */
    }
    .imgProfile {
    display: block;
    }

    .containerProfile {
    max-width: 93.5rem;
    margin: 0 auto;
    padding: 0 2rem;
    }

    .btnProfileIn {
    display: inline-block;
    font: inherit;
    background: none;
    border: none;
    color: inherit;
    padding: 0;
    cursor: pointer;
    }

    .btnProfileIn:focus {
    outline: 0.5rem auto #4d90fe;
    }


    /* Profile Section */

    .profile {
     padding: 5rem 0;
    }

    .profile::after {
    content: "";
    display: block;
    clear: both;
    }

    .profile-image {
    float: left;
    width: calc(33.333% - 1rem);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 3rem;
    }

    .imgProfile {
    border-radius: 50%;
    }

    .profile-user-settings,
    .profile-stats,
    .profile-bio {
    float: left;
    width: calc(66.666% - 2rem);
    }

    .profile-user-settings {
     margin-top: 1.1rem;
    }

    .profile-user-name {
    display: inline-block;
    font-size: 3.2rem;
    font-weight: 300;
    }

    .profile-edit-btn {
    font-size: 1.4rem;
    line-height: 1.8;
    border: 0.1rem solid #dbdbdb;
    border-radius: 0.3rem;
    padding: 0 2.4rem;
    margin-left: 2rem;
    }

    .profile-settings-btn {
     font-size: 2rem;
     margin-left: 1rem;
    }

    .profile-stats {
    margin-top: 2.3rem;
    }

    .profile-stats li {
    display: inline-block;
    font-size: 1.6rem;
    line-height: 1.5;
    margin-right: 4rem;
    cursor: pointer;
    }

    .profile-stats li:last-of-type {
     margin-right: 0;
    }

    .profile-bio {
    font-size: 1.6rem;
    font-weight: 400;
    line-height: 1.5;
    margin-top: 2.3rem;
    }

    .profile-real-name,
    .profile-stat-count,
    .profile-edit-btn {
    font-weight: 600;
    }



    /* Media Query */

    @media screen and (max-width: 40rem) {
    .profile {
        display: flex;
        flex-wrap: wrap;
        padding: 4rem 0;
    }

    .profile::after {
        display: none;
    }

    .profile-image,
    .profile-user-settings,
    .profile-bio,
    .profile-stats {
        float: none;
        width: auto;
    }

    .profile-image {
        width: 3.7rem;
    }

    .profile-user-settings {
        flex-basis: calc(100% - 10.7rem);
        display: flex;
        flex-wrap: wrap;
        margin-top: 1rem;
    }

    .profile-user-name {
        font-size: 2.2rem;
    }

    .profile-edit-btn {
        order: 1;
        padding: 0;
        text-align: center;
        margin-top: 1rem;
    }

    .profile-edit-btn {
        margin-left: 0;
    }

    .profile-bio {
        font-size: 1.4rem;
        margin-top: 1.5rem;
    }

    .profile-edit-btn,
    .profile-bio,
    .profile-stats {
        flex-basis: 100%;
    }

    .profile-stats {
        order: 1;
        margin-top: 1.5rem;
    }

    .profile-stats ul {
        display: flex;
        text-align: center;
        padding: 1.2rem 0;
        border-top: 0.1rem solid #dadada;
        border-bottom: 0.1rem solid #dadada;
    }

    .profile-stats li {
        font-size: 1.4rem;
        flex: 1;
        margin: 0;
    }

    .profile-stat-count {
        display: block;
    }
    }



    @supports (display: grid) {
    .profile {
        display: grid;
        grid-template-columns: 1fr 2fr;
        grid-template-rows: repeat(3, auto);
        grid-column-gap: 3rem;
        align-items: center;
    }

    .profile-image {
        grid-row: 1 / -1;
    }



    .profile-image,
    .profile-user-settings,
    .profile-stats,
    .profile-bio {
        width: auto;
        margin: 0;
    }

    @media (max-width: 40rem) {
        .profile {
            grid-template-columns: auto 1fr;
            grid-row-gap: 1.5rem;
        }

        .profile-image {
            grid-row: 1 / 2;
        }

        .profile-user-settings {
            display: grid;
            grid-template-columns: auto 1fr;
            grid-gap: 1rem;
        }

        .profile-edit-btn,
        .profile-stats,
        .profile-bio {
            grid-column: 1 / -1;
        }

        .profile-user-settings,
        .profile-edit-btn,
        .profile-settings-btn,
        .profile-bio,
        .profile-stats {
            margin: 0;
        }
    }
    }
    <header>

    <div class="container containerProfile">

        <div class="profile">

            <div class="profile-image">

                <img class="imgProfile" src="https://images.unsplash.com/photo-1513721032312-6a18a42c8763?w=152&h=152&fit=crop&crop=faces" alt="">

            </div>

            <div class="profile-user-settings">

                <h1 class="profile-user-name fontProfile">janedoe_</h1>

                <button class="btnProfileIn profile-edit-btn">Edit Profile</button>

                <button class="btnProfileIn profile-settings-btn" aria-label="profile settings"><i class="fa fa-cog" aria-hidden="true"></i></button>

            </div>

            <div class="profile-stats">

                <ul>
                    <li><span class="profile-stat-count">164</span> posts</li>
                    <li><span class="profile-stat-count">188</span> followers</li>
                    <li><span class="profile-stat-count">206</span> following</li>
                </ul>

            </div>

            <div class="profile-bio">

                <!-- <p><span class="profile-real-name">Jane Doe</span></p> -->

            </div>

        </div>
        <!-- End of profile section -->

     </div>
     <!-- End of container -->

     </header>

我在图像和名称之间有很大的差距。我希望该 div 接近其余部分。

This is the problem - The gap

欢迎任何想法或建议。

【问题讨论】:

  • 你好,请问你能解释更多或者你想要添加填充或者你想要修复图像和文本之间的差距的最终结果
  • @godfather 我想修复图片和文字之间的差距。
  • 你好,莎拉,你检查过我的答案了吗?

标签: html css html5-canvas media-queries html5-video


【解决方案1】:

试试你的 CSS 部分

.imgProfile {
padding-right:250px }

【讨论】:

    【解决方案2】:

    除了向profile-image 添加填充之外,您可以做的是尝试使剩余部分接近图像 div,为此您可以这样做:

    .profile-user-settings {
        width: auto;
        margin: 0px;
        margin-right: -35px;
    }
    

    【讨论】:

      【解决方案3】:

      您可以对图像 div 使用 flex 并将内容对齐到最后。

      .imgProfile {
          display: flex;
          justify-content: flex-end;
      }
      

      【讨论】:

      • @Sumner Evans display:flex;证明内容:弹性结束;不工作。请提出为什么它在我的代码中不起作用。它应该工作。你的建议很好,但不幸的是对我没有用。
      【解决方案4】:

      如果您包含 margin-left:200px(或任何您想要的),您可以将图片关闭到剩余部分。像这样:

      .imgProfile { display: block; margin-left: 200px; }

      【讨论】:

        【解决方案5】:

        在这部分 css

        `@supports (display: grid){ .profile {
                                                                                               
            display: grid;
            grid-template-columns: auto 1fr;
            grid-template-rows: repeat(3, auto);
            grid-column-gap: 3rem;
            align-items: center;}`
        

        像我一样改变 grid-template-columns:1fr 2fr;自动 1fr ;你可以删除 grid-column-gap

        【讨论】:

        • @Sarah 这有帮助吗?
        猜你喜欢
        • 2017-02-14
        • 1970-01-01
        • 2016-05-13
        • 2010-10-24
        • 2013-10-27
        • 2011-12-11
        • 2021-05-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多