Arrange grid layout with border gutters and central icon

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

.vertical-line {
  height: 169px;
  width: 0.5px;
  background-color: red;
}

.horizontal-line {
  width: 300px;
  height: 0.5px;
  background-color: red;
}
<div class="hero__grid">
  <div class="hero__grid-cell"></div>
  <div class="hero__grid-cell">
    <div class="vertical-line"></div>
  </div>
  <div class="hero__grid-cell"></div>
  <div class="hero__grid-cell">
    <div class="horizontal-line"></div>
  </div>
  <div class="hero__grid-cell"><i class="far fa-heart"></i></div>
  <div class="hero__grid-cell">
    <div class="horizontal-line"></div>
  </div>
  <div class="hero__grid-cell"></div>
  <div class="hero__grid-cell">
    <div class="vertical-line"></div>
  </div>
  <div class="hero__grid-cell"></div>
</div>

I'm attempting to achieve this design: https://i.sstatic.net/sMwom.png

Initially, I started by just trying:

display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;

and then adding in the lines and icon, but it doesn't quite seem to work as intended. What I am considering is creating a 3x3 grid layout :

grid-template-columns: 1fr auto 1fr;
grid-template-rows: 1fr auto 1fr;

Then placing the content in the auto (2nd) row and column divs, however, the visual result doesn't look correct to me. I understand that CSS can be finicky, so maybe this is actually the best approach?

  1. How can I create borders (or lines) between grid cells to achieve this effect?
    I've attempted using border-bottom but it spans the full width/height.

  2. How can I position the heart icon at the center of those borders?

Answer №1

This approach utilizes grid-gap to create space between rows and columns.
The heart icon is placed absolutely and moved up and left by half of its size.

body {
  font-family: sans-serif;
  font-size: 10px;
}

.hero__grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: 1fr auto 1fr;
  grid-gap: 2.4em;
  width: 500px;
}

.vertical-line,
.horizontal-line {
  background-color: #BBB;
}

.vertical-line {
  height: 100%;
  width: 0.5px;
}

.horizontal-line {
  height: 0.5px;
}

.hero__grid-cell {
  position: relative;
}

.cell-content {
  padding: 0.8em 0;
}

.hero__grid-cell .far {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  color: #e56260;
  font-size: 2.4em;
}

h1 {
  font-size: 1.5em;
  margin: 0 0 0.3em;
}

p {
  font-size: 1.3em;
  margin: 0;
  color: gray;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />

<div class="hero__grid">
  <div class="hero__grid-cell cell-content">
    <h1>Heading</h1>
    <p>Donec sollicitudin molestie malesuada.</p>
  </div>
  <div class="hero__grid-cell">
    <div class="vertical-line"></div>
  </div>
  <div class="hero__grid-cell cell-content">
    <h1>Heading</h1>
    <p>Praesent sapien massa, convallis.</p>
  </div>
  <div class="hero__grid-cell">
    <div class="horizontal-line"></div>
  </div>
  <div class="hero__grid-cell"><i class="far fa-heart"></i></div>
  <div class="hero__grid-cell">
    <div class="horizontal-line"></div>
  </div>
  <div class="hero__grid-cell cell-content">
    <h1>Heading</h1>
    <p>Cras ultricies ligula sed magna dictum porta.</p>
  </div>
  <div class="hero__grid-cell">
    <div class="vertical-line"></div>
  </div>
  <div class="hero__grid-cell cell-content">
    <h1>Heading</h1>
    <p>Vivamus suscipit tortor eget felis porttitor.</p>
  </div>
</div>

gap (grid-gap)
The gap CSS property defines the spacing between rows and columns. It acts as a shortcut for row-gap and column-gap.

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

What is the method for accessing font sizes through CSS code?

Why is the font size value in CSS returning incorrect values? Check out this jsFiddle example Here's the HTML code snippet: <div id="test">TEXT</div> <div id="test2">TEXT2</div> Now, take a look at the CSS: #test{ font ...

Achieve the effect of "background-attachment: fixed" using a div element

I am attempting to replicate a similar effect as seen here, which is accomplished using the CSS property background-attachment:fixed. However, I want to achieve this effect using div elements instead. For instance, could I apply this effect to an h1 tag? ...

Support with formatting a dynamic asp:CheckBoxList utilizing Bootstrap styling

I'm currently facing a challenge with styling my asp:CheckBoxList that is populated with values from a database. My framework of choice is Bootstrap 4.3.1 and I'm attempting to style the CheckBoxList using the default example below: <div cla ...

How can I use JavaScript or JQuery to retrieve the HTML content as a string from a specific URL?

How can I extract the URL of a link from a webpage and add it to my code without an ID for that specific link? Is there a way to search based on the content within the <a> tag? ...

Can one customize the background color of a segment in a radar chart using Chart.js?

Could I customize the color of the sectors in my radar chart to resemble this specific image? https://i.stack.imgur.com/U8RAb.png Is it feasible to achieve this using Chart.js? Alternatively, are there other chart libraries that have this capability? It ...

Automatically tally up the pages and showcase the page numbers for seamless printing

I've been tackling a challenge in my Vue.js application, specifically with generating invoices and accurately numbering the pages. An issue arose when printing the invoice – each page was labeled "Page 1 of 20" irrespective of its actual position in ...

Issue encountered while attempting to remove a row from a table (JavaScript)

I'm encountering an error when attempting to delete a table row: "Uncaught ReferenceError: remTable is not defined index.html:1:1". When I inspect index.html to identify the issue, I find this: remTable(this) This is my code: const transact ...

Achieving successful content loading through AJAX using the .load function

Our website features a layout where product listings are displayed on the left side, with the selected product appearing on the right side (all on the same page). Initially, when the page loads, the first product is shown on the right. Upon clicking a new ...

The CSS grid functionality seems to be malfunctioning on a specific page, yet it operates perfectly on other

I'm currently working on my Portfolio application, but I'm facing an issue on the home page where the grid layout is not functioning properly. The different div tags are overlapping each other instead of displaying correctly. https://i.sstatic.n ...

leveraging embedded jetty for developing a web-based interface

As a newcomer to web development and using embedded Jetty, I have created the source code below in Eclipse IDE. I need to programmatically start the Jetty server and cannot use the command line to do so. The web interface must be lightweight due to the li ...

Show the initial instance following a nested class

I need the first .tab class that directly follows the .tab-wrapper class to be visible, while the others should remain hidden <ul class="tabs"> <li>1</li> <li>2</li> </ul> <div class="tab-wrapper"> &l ...

Safari not properly adjusting height of bootstrap cards within column in row

I'm currently working on a bootstrap and angular project. I've noticed that in Safari, the card heights are not behaving as expected compared to other browsers like Firefox, Chrome, and Edge. I have tried setting the height to 100%, but it seems ...

Three fluid horizontal DIVs aligned side by side

Is there a way for me to align three divs beside each other, each with unique background images? The center div should be 989px wide, while the widths of the left and right divs can vary. ...

"Can you guide me on positioning an image logo before text by utilizing the content attribute within the style tag

I am new to coding and experimenting with HTML. I want to display an image before the text "hello html" but for some reason, it is not working. Here is the code I have tried: <head> <style> .img::before { content: url("img/smartphone.png"); ...

Subject line matches webpage header

Is it possible to automatically generate an email subject that includes the title of the webpage from where the user is sending an email? For instance: If my webpage's title is "About Us," Can the email subject be "About Us" as well? I am not very ...

JQuery Load fails to load in real-time

I have a PHP file where I am using JQuery to load the content of another file called 'live.php' which should display the current time, but for some reason it is not loading live. Can anyone help me troubleshoot this issue? It used to work perfect ...

Adjust speed on various HTML5 video players

I'm looking to slow down all the HTML5 video players on my page to 0.5x speed. Currently, I have a JavaScript snippet that only affects one video player at a time. <script type="text/javascript"> /* play video twice as fast */ document.quer ...

Internet Explorer 7 does not display icons

When I look at my icon, I'm calling it like this: <td> <i id="sthAdd" class="icn_plus"></i> </td> and the class looks like this: .icn_plus { background: url(../images/icons/plus-14x14.png) no-repeat; width: 20px; heig ...

As I scroll, the background color of my body vanishes

Seeking assistance with a CSS issue. I have set the height property of my body to 100%, which works well when all content is visible on screen. However, when I need to scroll due to window size changes, the body color disappears and only the HTML backgro ...

Is there a way to attach a JavaScript event to a textarea without directly accessing it?

I am curious about how to incorporate the following code: onblur="hcb.watermark.blur(event)" onfocus="hcb.watermark.focus(event)" style="color: rgb(136, 136, 136); into a textarea with the id "HCB_textarea" and the class "commentbox hcb-shadow-r," withou ...