Encasing text within triangles for a stylish flex layout design

After some trial and error, I finally found the solution to my shape-outside issue. It turns out that shape-outside needs to be a sibling, rather than a child, of the item it wants to affect. Following the advice from AH in the comments, I decided to rewrite the section as a grid. The Codepen has been updated for reference. Each element in the grid now acts as a placeholder, housing each triangle div. Within each triangle div, there is a shape-outline styled div along with a simple paragraph element containing the text. By playing around with the horizontal margins of the grid elements, I was able to make it work. While not the most elegant solution, it gets the job done.

Hello! I've been working on this tangram-like grid for a while now, but I'm struggling to get it to function properly. My goal is to have text wrapped inside each triangle element. I explored using shape-outside, but due to the use of display:flex in the parent div, the standard solutions did not seem to apply in my case. I am open to exploring grid-based alternatives or even a complete design overhaul if it simplifies the process.

Codepen

This is how it functions: There are 6 rows, each containing 4 elements. Every even line is moved up by 100% to align with the previous odd line. The triangles are created with clip-path pointing in four possible directions. Any assistance or suggestions would be greatly appreciated!

#edu-grid {
    height: 700px;
    width: 90%;
}

.edu-row {
    height: 33%;
    width: 100%;
}
.edu-item {
    height: 100%;
    width: 25%;
    border: 1px solid black;
}

.edu-top-left {
    clip-path: polygon(0 0, 100% 0, 0 100%);
}

.edu-top-right {
    clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.edu-bottom-right {
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.edu-bottom-right-shape {
    shape-outside: polygon(100% 0, 100% 100%, 0 100%);
    height: 100%;
    width: 100%;
    float: left;
    margin: 0;
}

.edu-bottom-left {
    clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.edu-bocc {
    background: blue;
}

.edu-blank {
    background: black;
}

.edu-mcg {
    background: red;
}

.edu-whu {
    background: green;
}

.edu-upb {
    background: yellow;
}

.edu-up {
    margin-top: -231px;
}

.flex {
    display: flex;
    justify-content: center; /* align horizontal */
    align-items: center; /* align vertical */
}
<div id="edu-grid">
  <div id="edu-1" class="flex edu-row">
    <div class="edu-item edu-blank edu-top-left">a</div>
    <div class="edu-item edu-bocc edu-top-left">a</div>
    <div class="edu-item edu-blank edu-top-right">a</div>
    <div class="edu-item edu-mcg edu-top-left">a</div>
  </div>
  <div id="edu-2" class="flex edu-row edu-up">
    <div class="edu-item edu-bocc edu-bottom-right"></div>
    <div class="edu-item edu-bocc edu-bottom-right"><div class="edu-bottom-right-shape"></div><div><p>a</p></div></div>
    <div class="edu-item edu-bocc edu-bottom-left">a</div>
    <div class="edu-item edu-mcg edu-bottom-right">lorem ipsum etc etch</div>
  </div>
  <div id="edu-3" class="flex edu-row">
    <div class="edu-item edu-bocc edu-top-right"></div>
    <div class="edu-item edu-bocc edu-top-right"></div>
    <div class="edu-item edu-bocc edu-top-left"></div>
    <div class="edu-item edu-mcg edu-top-right"></div>
  </div>
  <div id="edu-4" class="flex edu-row edu-up">
    <div class="edu-item edu-blank edu-bottom-left"></div>
    <div class="edu-item edu-bocc edu-bottom-left"></div>
    <div class="edu-item edu-blank edu-bottom-right"></div>
    <div class="edu-item edu-whu edu-bottom-left"></div>
  </div>
  <div id="edu-5" class="flex edu-row">
    <div class="edu-item edu-upb edu-top-right"></div>
    <div class="edu-item edu-upb edu-top-left"></div>
    <div class="edu-item edu-whu edu-top-right"></div>
    <div class="edu-item edu-whu edu-top-left"></div>
  </div>
  <div id="edu-6" class="flex edu-row edu-up">
    <div class="edu-item edu-upb edu-bottom-left"></div>
    <div class="edu-item edu-upb edu-bottom-right"></div>
    <div class="edu-item edu-whu edu-bottom-left"></div>
    <div class="edu-item edu-whu edu-bottom-right"></div>
  </div>
</div>

Answer №1

After reviewing the recent edits you have implemented, I realized that my concept differs slightly. Therefore, I am sharing my alternative idea here in case it proves useful.

The main structure resembles a grid; however, this specific section does not touch upon the concept of flexed rows.

In this grid setup, items are positioned using the grid-column/grid-row system, allowing for two items per grid. Each item takes the shape of a Tetris-style triangle.

If a certain position within the grid (e.g., the first cell) lacks a triangular piece, no element is placed there to reveal the grid's background instead of masking it as if a piece were present.

* {
  margin: 0;
}

.container {
  background-color: black;
  height: 100vmin;
  aspect-ratio: 4 / 3;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 0px;
  --so0: polygon(0 0, 100% 0, 0 100%);
  
  /* Additional CSS properties trimmed for brevity */
<div class="container">

  <div class="blue row1 col1 bottomright">
    <div></div>
    <div>text text text text text...</div>
  </div>

  <!-- More code snippets follow -->

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

I'm just starting to dabble in Perl and am curious about a few things regarding regular expressions

I am currently teaching myself Perl and find that examples are the most effective way for me to learn. Right now, I am delving into a basic Perl script that scrapes a specific blog and have encountered some confusion regarding a few of the regex statements ...

CSS margin-left causing issues in Chrome Extension

My current situation is incredibly puzzling, as I am at a loss for what is happening. I developed a Firefox add-on using jQuery and CSS to revamp a website. When attempting to transfer the add-on to Chrome (which was relatively straightforward due to the s ...

Tips for positioning buttons in a sticky footer

I've been trying to align buttons on the left, center, and right side but haven't had any success. How can I ensure that buttons are aligned properly on each side, even when adding more buttons? When adding more buttons to the left, I want them ...

disable readonly attribute on several fields by clicking button with jquery

I am struggling with selecting all the input fields of a row in my student details table at once when clicking the edit button. The fields are readonly and can be edited by clicking the edit button. Below is the HTML code snippet: <table class="table ...

Scroll the content of a div to the bottom using JavaScript

I'm facing a situation with my code: function scrollme(){ dh=document.body.scrollHeight ch=document.body.clientHeight if(dh>ch){ moveme=dh-ch window.scrollTo(0,moveme) } } However, I am looking for a way to make it scroll only within a specific d ...

Use a CSS media query to elevate the third inline-block div above the initial two divs without utilizing Bootstrap

I am trying to style three colored HTML div tags displayed inline-block by using CSS only. The challenge I am facing is getting the blue div to appear on top of the red and green divs. My goal is to achieve a layout where the blue div overlaps the other tw ...

Disabling the @import cache feature in LessCSS Assetic

I'm facing a minor issue that is robbing me of precious time. Currently, I am using the assetic plugin with the lesscss filter in my symfony2.1 project. The problem lies in Assetic not detecting changes in imported files when using the @import functi ...

Responsive navigation bar breakpoint in Bootstrap 4

Hey there! I'm currently working on making my navigation bar responsive. Everything seems to be working well until I decrease the resolution, then my navbar ends up under 'COMPANY'. I've tried looking at different solutions online, but ...

Achieve a scrolling effect for just a specific section of an HTML page

Hey there! I'm currently working on adding scrolling text along the side of a webpage for a specific section. My goal is to have three different sections, each with text that stops scrolling when you reach it and then transitions to the next section o ...

Tips for toggling CSS classes based on the user's current page

<nav id="navMenu" class="navMenu"> <ul> <li class="active homePage"> <a href="index.php" title="Homepage">Home</a> </li> <li class="resourcesPage"> <a href="re ...

What is the ideal location for storing my CSS files?

I have a medium-sized website that shares a common header/footer, and each page has its own specific layout file. The common header/footer is stored in a separate html file, but I am struggling with where to place the CSS file because the link element in f ...

When new text is added to Div, the first line is not displayed

One of the divs on my page has an ID of "TrancriptBox" and contains multiple lines of text. When I scroll through it on my iPad, everything works fine. However, if I scroll and then change the text within that div, it doesn't display the first line o ...

Tips to prevent elements from overlapping in Angular applications

I am facing an issue with my Angular-based app where I dynamically populate the page with table rows. There is an app-console element below the page that has a fixed position. Whenever I click the button to add a new row, it overlaps with the app-console. ...

Implementing JavaScript to override inline CSS styles

Is it possible to override inline CSS using JavaScript with compatibility for IE6? I came across a pure CSS solution, but unfortunately it doesn't work in IE. http://www.sitepoint.com/blogs/2009/05/27/override-inline-css/ <div class="block"> ...

Why aren't CSS variables "calculating" the color?

Can anyone help me understand why I am having trouble assigning block-level CSS variables using values from SASS? Specifically, the line color: hsl(3, 75%, var(--main-color-l)); is not producing any output. My setup involves a static site generator with ...

items within an unordered list that can be collapsed

Answer: Nikhil was on the right track with his solution, but I had to make some modifications. Specifically, I needed to create and initialize an empty array to display the details properly. Here's the updated code: if (this.name.toLowerCase() == va ...

What are the indicators of JSON in a response?

When using ReactJS to make a fetch request to an API, the JSON body response includes the following: { "place": <a href=\"http:\/\/place.com\/ search?q=%23MILKYDOG\" target=\"_blank\">#milkydog<&b ...

Using JQuery to handle click events on an array of checkboxes and displaying the value of the selected

I am struggling to show the label text and checkbox value from a checkbox array whenever each one is clicked (for testing purposes, assume I want it to appear in an alert). My HTML looks like this: <label class="checkbox"> <input type="checkbox" ...

What is the best way to find information in a multi-page table?

I've implemented a table with pagination and search functionality to look up data within the table. However, currently the search only works within the current page of the table rather than searching the entire dataset. Is there a way to modify the se ...

The importance of maintaining aspect ratio for HTML5 videos within parent containers

I have a bootstrap card with a video and text below. The HTML for the video card is as follows: <div class="card video-card"> <div class="card-body"> <video width="100%"> <source src="/request/video/Sample ...