html - 列数未知/宽度相同的 CSS 网格布局

标签 html css vue.js css-grid

我正在创建一个带有网格的导航栏。 简而言之,当用户是管理员时,他最后会多出两个链接,它们的宽度应该相同,而不是像现在这样依赖于文本量。我正在使用 vue.

为了简单起见,我删除了标签属性

提示:CSS中不存在紫色线条,它只是用于调试的网格布局

1) 用户不是管理员,搜索栏占用 1 分数 Not admin 2)用户是admin,搜索栏是1fr,另外两个是auto enter image description here

<section id="masthead">
        <button>
            <span></span>
            <span></span>
            <span></span>
        </button>
        <div>
            <span>Logo</span>
        </div>
        <div>
            <input type="search" id="search">
            <button id="loupe">O</button>
        </div>

        <!-- show links if Admin -->
        <div><span>Submit Video</span></div> 
        <div><span>Profile</span></div>
</section>

这是CSS

#masthead {
    display: grid;
    grid-template-columns: 75px 100px 1fr auto auto;
    grid-template-rows: auto;
    grid-column-gap: 10px;
    height: 56px;
    box-shadow: 0px 0px 7px rgba(136, 136, 136, 0.22);
    position: relative;
    z-index: 1000;
}

当最后两个链接存在于 View 中时,如何使它们具有相同的宽度。 我想要动态列:)

谢谢

最佳答案

我使用这个 css 修复了它:

#masthead {
    display: grid;
    grid-template-columns: 75px 75px 0.9fr;
    grid-auto-flow: column;
    grid-template-rows: auto;
    height: 56px;
    box-shadow: 0px 0px 7px rgba(136, 136, 136, 0.22);
    position: relative;
    z-index: 1000;
}

它并不完美,但它完成了工作: without admin items with admin items

关于html - 列数未知/宽度相同的 CSS 网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47347614/

相关文章:

jquery - 添加图像动态创建的 div 以显示文本

html - 在页面之间保持导航栏

CSS 三 Angular 形被剪掉

javascript - 如何在 Vue.js 中取消绑定(bind)数组副本

javascript - 如何在 vuejs 中发出补丁请求并更新使用 v-model 的个人的标记输入

vue.js - nuxt 应用程序中的 Vuex 抛出 "Do not mutate vuex store state outside mutation handlers"!

javascript - 使用输入类型文本以表单形式上传图像

javascript - 如何让 Shadow Dom 与 LIst 一起工作?

javascript - 如何使用 PHP Mailer 发送附件而不移动到服务器

javascript打字机不打印单词