The results in the grid are displayed in a horizontal layout, rather than a

My grid results are not rendering as desired, appearing horizontally instead of in two columns. Attached is my current CSS and a screenshot of the issue for reference. Any suggestions on how I can achieve the layout shown in the screenshot below?

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.grid-item {
  padding: 16px;
  border-bottom: 1px solid black;
}

.grid-item:nth-child(odd) {
  border-right: 1px solid black;
}

.grid-item:nth-last-child(-n + 2):nth-of-type(odd),
.grid-item:last-child {
  border-bottom: none;
}
<form method="POST" id="Submit">
  <div class="inner-form">
    <div class="input-field first-wrap">
      <div class="svg-wrapper">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
                      <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16  "></path>
                  </svg>
      </div>
      <input id="search" type="url" name="url" placeholder="Paste here" required/>
    </div>

    <div class="input-field second-wrap">
      <button id="button" class="btn-search" onclick="searchIt()" value="press" type="submit">SEARCH       </button>
      <!-- <button type="submit" class="btn-search">SEARCH</button> -->
    </div>
  </div>
  <p id="errorMessage">Yikes!</p>

</form>

EJS Template

<div class="grid">
  <div class="grid grid-item">
          <div class=“Countries>
              <img alt="" src= "<%= country.icon %>" /> <%= country.name %>
          </div>
  
          <div class ="Category">

          <% country.categories.forEach(function(cat){ %>
              <%= cat.name %>
          <% }); %>
    
          </div>
   </div>

https://i.sstatic.net/KbP6o.png

Answer №1

.grid {
  display: grid;
  grid-template-rows: 1fr 1fr;
  grid-template-columns: repeat(4,1fr);
}

.grid-item {
  padding: 16px;
  border-bottom: 1px solid black;
  border-right: 1px solid black;
}

.grid-item:nth-child(4),
.grid-item:nth-child(odd),
.grid-item:nth-child(8){
  border-right: none;
}

.grid-item:nth-last-child(-n+3){
  border-bottom: none;
}
<div class="grid">
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
  <div class="grid-item">Country Name</div>
</div>

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

Is there a way for me to make my navigation fill the entire height of the header?

I am trying to create a navigation menu within a header div where the list items are displayed horizontally inside a ul element. I want these list items to be 100% the height of the header. Despite trying to set the height to 100% on various elements such ...

tips for generating a random number for direct display

Can anyone help me figure out how to automatically display the total of numbers from this script on my blog post without having to click anything? Additionally, I need it to update if the browser is refreshed. ` http://jsfiddle.net/BenedictLewis/xmPgR/ ...

``I'm having trouble with TablePagination styling on a material-table component. Anyone have

I am trying to customize the appearance of rows numbered from-to of x on a Material-Table, using the following code: import MaterialTable from 'material-table' import { TablePagination, withStyles } from '@material-ui/core' const Style ...

Unlock the Power of Angular: Leveraging ViewEncapsulation.Native to Access HTML Elements

I am encountering an issue where I am receiving an error when trying to access an HTML element by ID. The problem arises when I attempt to access the classList upon a user clicking a button to apply a different style class to the element. The class list an ...

What could be causing my browser to not respond to the JavaScript function for clicking?

I have been struggling to get the images on my browser to change when I click on them. Despite my efforts, I haven't found a solution yet... I've experimented with changing the variables to ".jpg" and also tried removing them altogether. var ...

css: Positioning divs relative to their parent div

In my design, I want the blue div to be positioned next to the red div without affecting the yellow div's placement. http://jsfiddle.net/pCGxe/ Is there a cleaner way to achieve this layout without resorting to using position:absolute or other trick ...

Alignment of text varies between canvas and HTML

How can I ensure that the labels in both canvas and HTML display overlap exactly, regardless of font family and size? The current code fails to center text inside an area when switching between canvas and HTML view. let canvas = document.getElementById( ...

The "Open in new tab" feature seems to be missing for links when using Safari on iOS

My webapp contains links structured like this: <a href="/articles/">Articles</a> I am using JavaScript to control these links within my app: $(document).on("click", 'a', function(ev) { ev.preventDefault(); ev.stopPropagat ...

Issues with CSS overlays arise when attempting to display a welcome page on top of a flash component

Can anyone help with fixing the issue of my overlay being hidden behind the flash element? The blue bar with the 'Continue' button still shows up on top. I need some CSS changes to make sure that the overlay appears above everything else below it ...

The bottom border of the HTML header does not properly wrap around the Table of Contents (ToC), although the text within the header does. What steps

I have created a Table of Content (ToC) using a Div element and styled it with the following HTML and CSS: h3.articletitle { font-weight: bold; font-size: 30px; border-bottom: 1px solid #4F120B; } h4.articlesubtitle { font-weight: bold; ...

I am encountering an issue where my input is moving to the following line after the initial one. What could be

Trying to create a layout I like for this form has been a bit of a struggle. I thought I had something good at first, but after the first row of input, the formatting gets all messed up and I can't figure out what's going wrong. <!DOCTYPE htm ...

Caution: It is important for each child within a list to have a distinct "key" prop when using react-input

I'm currently facing an issue with the following code snippet: {array.map((item) => ( <> <input key={item.id} type="checkbox" /> ...

Adjusting picture dimensions with percentages in canvas and jquery

I'm currently working on a one-page project that involves a canvas where users can click to add or place images randomly. I have made progress with most of the functionality, but as a beginner in jquery and canvas, I am struggling to set a maximum siz ...

Incorporate user input into Alert Dialog Boxes

Would you be able to assist me in displaying the input value from the "email" field in my alert box? The code seems to be working fine, but I'm having trouble getting the alert box to show the email form value. I decided to use Bootstrap for som ...

Tips to prevent the webpage from scrolling to the top when clicking on an anchor with an ID

I have developed a CSS/HTML carousel that consists of 4 slides. The goal is to display the selected slide when clicking on the bottom button (a href). However, I am facing an issue where every time I click on a link, the selected slide appears as intended ...

Role="presentation" containing a <form> element within

<nav> <ul class="nav nav-pills pull-right"> <li role="presentation"> <form action="/logout" method="POST" id="logout-form"> <a href="#" onClick="document.getElementById('logout-form&ap ...

Text centered vertically with jQuery is only loaded after the page is resized

My jQuery script is designed to vertically center text next to an image, but it seems to only work properly after resizing the page. $(window).load(function () { $(function () { var adjustHeight = function () { $('.vertical-al ...

Arranging the list items in a perfectly straight vertical line

Concern: I'm struggling with alignment issues on my website. I have country flags displayed using display:inline;. The issue arises when the number next to the flag exceeds single digits (e.g., 10 or more) as it affects the alignment due to the consi ...

jQuery Mobile for Enhanced Customer Relationship Management on the Web

I have recently been tasked with creating a Web Based CRM Software and I plan to use PHP and MYSQL as my backend. For the frontend, I am considering using a UI framework such as jQuery Mobile. I like that it is fully AJAX-driven, easy to code with, and has ...

Clicking on an element in the Dropdown Form will directly redirect you to a link, without the need to press a

I'm having trouble with my dropdown form. I want the user to be directed to a specific URL when they click on an element, without needing to hit a submit button. Below is the code I've been working with: <select name="mydropdown" class="style ...