Creating a CSS grid layout with an unspecified number of columns all set to equal width

Currently, I am in the process of designing a navigation bar using grids. In essence, when the user is an admin, there should be two additional links at the end of the bar. These links need to have the same width and should not be affected by the amount of text present. My implementation utilizes Vue.

I have removed tag attributes for the sake of simplicity

Hint: The purple lines mentioned do not actually exist in CSS; they are simply part of the grid layout for debugging purposes.

1) If the user is not an admin, the search bar takes up one fraction of the space. https://i.sstatic.net/WwK9M.png 2) However, if the user is an admin, then the search bar occupies 1fr, whereas the other two links take up auto space. https://i.sstatic.net/WAwPH.png

<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>

    <!-- Display links only if the user is an Admin -->
    <div><span>Submit Video</span></div> 
    <div><span>Profile</span></div>
</section>

This snippet depicts the corresponding CSS styling:

#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;
}

I am seeking guidance on how to ensure that the last two links maintain equal widths when visible on the screen. Any solutions for achieving dynamic column behavior would greatly help.

Many thanks!

Answer №1

After some trial and error, I managed to solve the issue by implementing the following 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;
}

Although it's not flawless, it does get the job done effectively: https://i.sstatic.net/IBsId.png https://i.sstatic.net/c6MaN.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on customizing the selected icon color in Material-UI's BottomNavigationAction styling

I'm facing an issue with Material-UI styled components and could use some assistance. My goal is to create a BottomNavigation bar in React using Material-UI v5 where the selected option's icon displays in red (#f00) while the unselected icons sho ...

Having Troubles with PHP File Upload Form

Executing index.php initiates the user input of metadata and files: <!DOCTYPE html> <html lang="en> <head> <meta charset="utf-8"> <meta name="robots" content="noindex, nofollow"/> <meta http-equiv="X-UA-Compati ...

Strip away the HTML tags and remove any text formatting

How can I effectively remove HTML tags and replace newlines with spaces within text? The current pattern I am using is not ideal as it adds extra space between words. Any suggestions on how to improve this pattern? replace(/(&nbsp;|<([^>]+)> ...

Tips on creating Twitter Bootstrap tooltips with multiple lines:

I have been using the function below to generate text for Bootstrap's tooltip plugin. Why is it that multiline tooltips only work with <br> and not \n? I would prefer to avoid having any HTML in my links' title attributes. Current Sol ...

Placing an image at the forefront of all elements

Recently, I created a horizontal opt-in bar for my Newsletter on my website. Instead of the traditional submit button, I decided to use an image by incorporating some CSS: #mc_embed_signup input.button { background: url(http://urltotheimg.com/image.jpg); ...

Getting variables from different functions in Python can be achieved by using the return

I am trying to implement a feature where I can fetch a search term from the function getRandomVideo() and then use it in a jQuery statement. For example, if I get "Beethoven" as the search term from the variable searches, I want to use it to retrieve JS ...

Error: Unrecognized action type in Vuex

I've been encountering some major issues with vuex lately. For some reason, getters, actions, and mutations are not being recognized. In the code snippet below, although fetchFacilities is working fine, addFacility is throwing an error: [vuex] unknown ...

Unable to show input in Javascript HTML

Every time I try to run this code on my webpage, the buttons do not seem to respond when clicked. I am aiming to have the user input for full name, date of birth, and gender displayed in the text box when the display button is clicked. When the next butt ...

Is it possible to resume CSS animation when the page is first loaded?

I'm looking for a way to ensure that my CSS animations on the elements in my header.php file continue smoothly when navigating to different pages. For example, if I have a 200-second looped animation and navigate to the "about us" page 80 seconds int ...

Node.js route error: no script MIME types allowed with 'X-Content-Type: nosniff' header present

I'm facing an issue where my css and js files do not load on the second route, but they work perfectly fine on the first route. Could someone explain why this discrepancy occurs? // ********************** INDEX PAGE ******************************* ...

Guide to retrieving the primary key auto-increment value for the ID field in an SQL record using PHP Scripting

I am currently working on a multi-page web survey form and I have a PHP script called process.php that handles my responses on www.buythosecars.com. This script stores the responses in a MySQL table and then redirects the user to www.buythosecars.com/surve ...

Executing a JQuery function when the webpage is loaded

I am attempting to execute some jQuery code when the page loads, but it doesn't seem to be working properly. The goal is to check if a link has already been saved and, if so, display a table with that information. Is this achievable? It should apply t ...

Retrieve the value of a PHP array within a for loop and transfer it to JQuery

*edited format I came across a PHP code for a calendar on the internet and I am currently working on implementing an onclick event that captures the date selected by a user as a variable (which will be used later in a database query). At this point, my g ...

Display popup dialogue upon page/component opening

Does anyone have suggestions for triggering a Vuetify modal dialog to display automatically when the page loads? I've been searching for examples on how to programmatically make a Vuetify dialog appear without much luck. ...

How to pass dynamic data from a parent component to a child component in Vue.js

Having some trouble with authentication in my Vue view and component. When a user enters their username and password, then clicks the login button, the information is emitted to the parent component. The parent component then makes a fetch request to an A ...

Can CSS be used to separate elements within a div from the overall page styles, similar to how an iFrame functions?

Is there a way to isolate elements within a div, similar to how it would behave in an iFrame? I am facing issues with the global SharePoint styles affecting my app inside SharePoint. I want to completely disable these global styles so that my app only use ...

Concealing divisions on a website with CSS styling

In my div, I have some text that I want to hide. <div style='visibility:hidden;' id='emailid'>$email</div> Although the visibility attribute successfully hides the text, it leaves behind empty space on the webpage where th ...

Steps to assign the identifier as the current index in the v-for iteration

Struggling to assign the id based on the index of a v-for loop. I attempted: <li v-for="(item, index) in items" v-bind:key="item.id"> <p>{{item.name}}</p> <input id= {{index}} type= "number"> < ...

The response from my ajax call is accurate, but it does not seem to be triggering any action

My current project involves creating a like/dislike button using ajax. The data is sent to a separate file where it gets saved in a database. Upon successful completion, the response I receive back is: {"status":"success","message":"Like has been saved."," ...

Settings for the packaging of web components

Is there a way to configure a web component in vue.config.js and separate the iconfont.css section when building? I am using the vue-cli-service build --target wc-async --name chat-ui src/views/Chat/Launcher.vue --report command to package the web compon ...