What is the best way to achieve concave borders in HTML/CSS, similar to the example provided?

Check out this unique graphic created with normal divs in a flexbox layout, courtesy of mode.com.

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

Ever wondered how this effect is achieved? Upon inspecting the page source, I discovered that there are four elements arranged in a row-based flexbox. The central element within the flexbox contains both an upper and a lower div that seamlessly blend into the left and right divs.

My main intrigue lies in identifying the source of the rounded, concave inner borders. I half-expected to find pseudo-elements like &:before or &:after on those middle-column pieces, but to my surprise, none were present. Given the web's notorious struggle with non-square media, this is a fascinating example that I would like to incorporate into my own projects. If anyone can shed light on how this effect is achieved, I would greatly appreciate it. Feel free to delve into the page source code of .

Answer №1

Successfully replicated their primary header appearance using pure CSS (no JS) and only a single <h1> element (as opposed to their multiple h1 elements):

Side-by-side comparison:

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


Curious about the source of the rounded, concave inside borders
Expected to find pseudo-elements like ::before or ::after on those middle-column sections, but none were observed.

The rounded corners are present - the visibility might have been missed:

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

Their method involves a solid color and

border-bottom/top-right/left-radius:
for the curved corners, which functions effectively on a solid background color - whereas my method employs mask-image: with a radial-gradient to achieve proper transparency, allowing it to work on any background texture.


html {
    font-family: sans-serif;
}

h1 {
    display: grid;
    grid-template-columns: repeat(2, auto) 100px;
    grid-template-rows: repeat(3, 1fr);
    
    outline: 1px solid red;
}

h1 > span {
    display: inline-block;
/*  outline: 1px solid blue;*/
    background-color: cyan;
    
    border-radius: 15px;
    padding: 0.5em;
    
    position: relative;
}

h1 > span:nth-child(1) {
  grid-column: 1 / span 2;
  grid-row: 1 / 2;
  justify-self: end;
  
  border-bottom-right-radius: 0;
}
h1 > span:nth-child(2) {
  grid-column: 2 / 3;
  grid-column: 1 / span 2;
  grid-row: 2 / 3;
  justify-self: end;
  
  border-top-right-radius: 0;
  border-top-left-radius: 0;
  border-bottom-right-radius: 0;
}
h1 > span:nth-child(3) {
  grid-column: 2 / 4;
  grid-row: 3 / 4;
  justify-self: end;
  
  border-top-left-radius: 0;
}

h1 > span::before,
h1 > span::after {
    content: '';
    display: inline-block;
    display: none;
    width: 15px;
    height: 15px;
    
    background-color: cyan;
    -webkit-mask-image: radial-gradient(15px at bottom left, rgba(0, 0, 0, 0) 99%, black 99%);
    
    position: absolute;
}

h1 > span:nth-child(2)::before {
    display: inline-block;
    top: 0;
    left: -15px;
}

h1 > span:nth-child(2)::after {
    display: inline-block;
    bottom: 0;
    right: -15px;
    
    -webkit-mask-image: radial-gradient(15px at top right, rgba(0, 0, 0, 0) 99%, black 99%);
}

h1 > span:nth-child(3)::before {
    top: 0;
    left: -15px;
    display: inline-block;
}
<h1>
    <span>Dyslexia for</span>
    <span>Cure</span>
    <span>Found</span>
</h1>

<h1>
    <span>Business Intelligence</span>
    <span>built around</span>
    <span>data teams</span>
</h1>


An alternative method to explore is implementing Metaballs using CSS shadows and filters - the resources linked below focus primarily on free-floating/circular metaballs, rather than incorporating metaball-like characteristics into existing rectangular HTML elements.

This particular demo stands out to me for some reason:

https://codepen.io/keithclark/pen/WNgRMQ

/* From https://codepen.io/keithclark/pen/WNgRMQ */
body,
html,.wrap {
  height:100%;
  margin:0;
  padding:0;
  overflow:hidden;
}
body {
  -webkit-filter: contrast(25);
  filter: contrast(25);
  background: black;
}
.wrap {
  background: inherit;
  animation: 7s spin ease-in-out infinite;
}

.meta::before,
.meta::after {
  content: "";
  position: absolute;
  width:100px;
  height:100px;
  left:50%;
  top:50%;
  margin:-50px;
  background: rgba(160,230,245,.9);
  border-radius:50%;
  -webkit-filter: blur(25px);
  filter: blur(25px);
  animation: move 12s infinite alternate ease-in-out;

}
.meta::before {
  animation-duration: 19.3s;
  animation-delay: -3.3s;
}
.meta:nth-child(2)::before {
  animation-duration: 14.7s;
  animation-delay: -2.7s;
}
.meta:nth-child(2)::after {
  animation-duration: 8.7s;
  animation-delay: -5.32s;
}
@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}
@keyframes move {
  0% {
    transform: translate(0%, 100%);
  }
  15% {
    transform: translate(-120%, 160%);
  }
  30% {
    transform: translate(100%, -80%);
  }
  40% {
    transform: translate(-140%, 0%);
  }
  60% {
    transform: translate(40%, -80%);
  }
  80% {
    transform: translate(-160%, -20%);
  }
  100% {
    transform: translate(40%, 60%);
  }
}
<div class="wrap">
  <!-- From https://codepen.io/keithclark/pen/WNgRMQ -->
  <div class="meta"></div>
  <div class="meta"></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

Are conditional comments truly the best approach? What is their functionality and operation like?

A previous question addressing a div positioning issue in Internet Explorer received multiple suggestions advising the use of conditional commenting Why is this relatively positioned div displaying differently in IE? How does one implement conditional co ...

The d3.select function is failing to update the chart on the website

I am facing a challenge in updating data in a d3 chart with the click on an HTML object #id. After successfully coding it in jsfiddle, I encountered issues when implementing it on a web page. The scenario involves a simple leaflet map where the chart is d ...

Using HTML5 to play video from a stored binary string

I have been attempting to extract the data from a video file in binary format using the FileReader.readAsBinaryString(Blob|File) method, as demonstrated in this example http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files. My intention i ...

What is the best way to structure Vue.js components for optimal organization?

Imagine having an index page called index.vue consisting of various components like this: index.vue <template> <div> <component-1 /> <section class="section-1"> <div class="container section-container"> <com ...

Displaying specific data points

I am encountering an issue where I want to select multiple values and have each selected value displayed. However, when I make a selection, I only see one value from a single box. I do not wish to use append because it keeps adding onto the existing valu ...

Using React Material UI icon within an auto complete feature

https://i.stack.imgur.com/W3CmF.png I am struggling to incorporate the target icon into the autoComplete component. After reviewing the documentation, I have been unable to find a solution. In TextInput, a similar outcome can be achieved by implementing ...

What could be causing the iPhone to trim the 20px right padding of my website?

Essentially, here's the situation: Browser: Iphone (the issue doesn't occur in Android): My current setup includes: <meta name="viewport" content="user-scalable = yes"> Here is the corresponding CSS: html, body, #wrapper { height: 1 ...

Utilizing highcharts to visualize non-linear time data pulled from a CSV file

I am seeking guidance on implementing a simple graph based on data from a CSV file in web development. I lack experience in this area and have struggled to find a suitable example to follow. The CSV file contains data in the format of a unix timestamp, hu ...

Can the JavaScript code be altered within the client's browser?

So, I'm using JQuery Validator on my webform to validate form data. However, I haven't added any validation on the server side. I'm curious if it's possible for a user to modify the code and bypass my validations in their browser. If th ...

Creating TypeScript types for enums can make your code more robust and ensure that you are using

I need to create an interface based on the values of an enum for a React use-case. The enum contains key value pairs that are used as form IDs. When the value of an input element is changed in an event listener, I want to set the state using this.setState( ...

Saving the output of an AngularJS expression in an input field

Looking at the calculations below, I am currently evaluating an expression, {{ annualIncome * 4.5 }}, in one input and then re-evaluating the same expression in another input. Instead of saving the result and transferring it to the other input, I am repeat ...

Utilize checkboxes to sort through MySQLi data

Currently, I have a page that is populated with various types of posts such as news and blog entries. My goal is to implement checkboxes so that users can select which type of post they want to view. For example, I would like the option to check 'new ...

Adjust image size with react - personalize styling for react-easy-crop

I am currently working on developing a basic react component that involves cropping images using react-easy-crop. It seems like the style of the react-easy-crop module can be customized with the style prop, which consists of three objects: containerStyle, ...

Adjusting the size of HighCharts HighMaps with a custom function

Simple query here (I believe) I have a DIV with the class "container" acting as my Map. The Highcharts plugin I'm using is responsive, but it only resizes when the window does. I'm looking to manually trigger a resize without adjusting my windo ...

Combining an image and a card in Bootstrap 5: a step-by-step guide

Is there a way I can align an image and a card in the same line like in this example? I want the image and card to be combined in one line, but when the page is viewed on mobile devices such as Android or iOS, I want the image to appear at the top with th ...

Adjusting the layout of a webpage using CSS

I am facing a challenge where I need to adjust the layout of a webpage using CSS for mobile view. Currently, the desktop version has a sidebar floated to the left and a textbox floated to the right. The HTML structure is as follows: <div id="container" ...

The luminosity of MeshBasicMaterial in Three.js

In my current setup with threejs, I am utilizing MeshBasicMaterial for lighting effects. Each element contains a simulated point light within. I have assigned a variable named color, defined as rgb(random value, random value, random value). I am looking ...

The peculiar characteristics of the dragLeave event in various web browsers

I observed a peculiar behavior while working with drag events in Internet Explorer 11. It seems that adding a 'width' property to the elements triggers the dragLeave event, whereas without it, the event does not fire. Can anyone shed light on why ...

How to Condense an Element Using Position: Absolute

https://i.sstatic.net/GMUss.png I'm attempting to create functionality where the "Open Chat" button displays an Absolute positioned div, then hides it when clicked again. I experimented with using the react-collapse component, but encountered issues ...

The action of JQuery is modifying the value of the checkbox, but it is not visually showing as checked

I am working on a list that contains checkboxes and text, similar to an email inbox. My goal is to be able to check or uncheck the checkbox anytime I click anywhere on the list item (row). To achieve this functionality, I have used the following code withi ...