繁体   English   中英

网格布局的 CSS 大小调整问题

[英]CSS resizing issue with grid layout

我的页面上有一个网格,但它似乎没有按照我的要求做(像往常一样,哈哈)。 有两个主要问题我似乎无法解决。

第 1 点:网格的右侧(最近的文章)似乎占用了太多空间。 理想情况下,我希望网格居中,这样两半的大小相同在此处输入图片说明

编号 2:调整大小时,网格的左侧部分会被压缩,而右侧则不会。 如果可能,我希望左侧保持不变,并压缩“最近文章”列表的右侧在此处输入图片说明

使用的代码在这里:

HTML:

 <div class="homepage">
            <div class="topics">
                <div class="homepage-topics-title">
                    Explore some topics:
                </div>
                <div class="individual-topics">
                    <a href="/productivity" class="topic1">Productivity</a>
                    <a href="/orginisation" class="topic2">Orginisation</a>
                    <a href="/time-management" class="topic3">Time-Management</a>
                </div>
            </div>
            <div class="recent">
                <div class="homepage-recent-title">
                    Recent articles
                </div>
                <div class="hompage-recent-articles">
                    {{{body}}}
                </div>
            </div>
        </div>

CSS:

.site {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.site-content {
    flex-grow: 1;
    padding: 6rem 0;
}

@media (max-width: 767px) {
    .site-content {
        padding: 3rem 0;
    }
}


/* Homepage code */
.homepage{
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 3rem;
}

.homepage-recent-title{
    font-size: 3rem;
    position: relative;
    align-self: center;
    overflow: hidden;
    padding-left: 3rem;
    line-height: 1;
}

.homepage-topics-title{
    font-size: 3rem;
    position: relative;
    align-self: center;
    overflow: hidden;
    margin-left: 3rem;
    line-height: 1;
}

.individual-topics{
    position: relative;
    display: grid;
    grid-template-rows: 1fr 1fr 1fr;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
    padding-left: 5rem;
    padding-right: 50%;
    font-size: 1.6rem;
    font-weight: 400;
    align-items: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 3;
}

如果你调整你grid-template-columns ,我想你会得到你需要的。

/* Homepage code */
.homepage{
    display: grid;
    grid-template-columns: min-content 1fr;
    margin-top: 3rem;
}

 .site { display: flex; flex-direction: column; min-height: 100vh; } .site-content { flex-grow: 1; padding: 6rem 0; } @media (max-width: 767px) { .site-content { padding: 3rem 0; } } /* Homepage code */ .homepage { display: grid; grid-template-columns: min-content 1fr; margin-top: 3rem; } .homepage-recent-title { font-size: 3rem; position: relative; align-self: center; overflow: hidden; padding-left: 3rem; line-height: 1; } .homepage-topics-title { font-size: 3rem; position: relative; align-self: center; overflow: hidden; margin-left: 3rem; line-height: 1; } .individual-topics { position: relative; display: grid; grid-template-rows: 1fr 1fr 1fr; padding-top: 1.5rem; padding-bottom: 1.5rem; padding-left: 5rem; padding-right: 50%; font-size: 1.6rem; font-weight: 400; align-items: center; text-overflow: ellipsis; white-space: nowrap; line-height: 3; }
 <div class="homepage"> <div class="topics"> <div class="homepage-topics-title"> Explore some topics: </div> <div class="individual-topics"> <a href="/productivity" class="topic1">Productivity</a> <a href="/orginisation" class="topic2">Orginisation</a> <a href="/time-management" class="topic3">Time-Management</a> </div> </div> <div class="recent"> <div class="homepage-recent-title"> Recent articles </div> <div class="hompage-recent-articles"> {{{body}}} </div> </div> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM