Unique CSS design with an accentuated border

I was experimenting with creating a corner using CSS and managed to achieve something like this:

.left-corner {
  width: 0;
  height: 0;
  border-top: 100px solid powderblue;
  border-left: 100px solid transparent;
}
<div class="left-corner"></div>

But I wondered if it's possible to create a corner with multiple colors in CSS, similar to the image linked here:

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

Answer №1

Check out this simplified approach using a basic linear-gradient:

body {
  background: pink;
}

.left-corner {
  width: 100px;
  height: 100px;
  background: linear-gradient(to top right, transparent 50%, red 50%, red 54%, blue 54%);
}
<div class="left-corner"></div>

If needed, you can create an out-of-color effect easily:

body {
  background: pink;
}

.left-corner {
  width: 100px;
  height: 100px;
  background: 
  linear-gradient(to top right, transparent 48%, red 48%, red 52%, transparent 52%),
  linear-gradient(to top right, transparent 51%,blue 0%) 0 5px/calc(100% - 5px) calc(100% - 5px) no-repeat;
  border-radius:3px 0 3px 0;
}
<div class="left-corner"></div>

You can also easily configure multiple colors:

body {
  background: pink;
}

.left-corner {
  width: 100px;
  height: 100px;
  background: linear-gradient(to top right, transparent 45%, green 45%, green 48%, red 48%, red 52%, yellow 52%, yellow 56%, transparent 0%), 
  linear-gradient(to top right, transparent 50%, blue 0%) 0 5px/calc(100% - 5px) calc(100% - 5px) no-repeat;
  border-radius:5px 0 5px 0;
}
<div class="left-corner"></div>

Answer №2

To achieve intricate border layouts, you can utilize the transform: skew() property in CSS. Here is an example:

* {
  margin: 0;
  padding: 0;
}

.left-corner {
  width: 0;
  height: 0;
  border-top: 100px solid black;
  border-left: 100px solid transparent;
}

.left-corner:before {
  content: "";
  position: absolute;
  top: 50px;
  left: 0px;
  border-top: 10px solid red;
  border-left: 100px solid red;
  transform: skew(0deg, 45deg);
}
<div class="left-corner"></div>

Answer №3

If you're aiming to replicate the image you've shared, one approach is to utilize a pseudo element positioned above your original Element.

Take a look at the Code Snippet provided below.

.left-corner{
  width: 0;
  height: 0;
  border-top: 120px solid red;
  border-left: 120px solid transparent;
  
  position:relative;
}

.left-corner:before {
  content: "";
  
  position:absolute;
  top:-120px;
  left:-100px;
  
  border-top: 100px solid powderblue;
  border-left: 100px solid transparent;
}
<div class="left-corner"></div>

Answer №4

As per your request for a taller border (red one)....

...utilize the pseudo class :after with position:absolute.

...set your div width and height equal to the border-width, which is 100px, and apply box-sizing:border-box.

...the height value is determined by the square root of 1002 + 1002(since 100 is the border-width) plus extra width as needed (e.g., 6 in this scenario).

...set the left value to half of the border-width

...the top value will be (border-width+height)/2.

Snippet for demonstration purposes

.left-corner {
  width: 100px;
  height: 100px;
  border-top: 100px solid powderblue;
  border-left: 100px solid transparent;
  position: relative;
  box-sizing: border-box;
}

.left-corner:after {
  content: "";
  position: absolute;
  top: -123.4213px;
  left: -52px;
  width: 6px;
  background: red;
  height: 147.4213px;
  transform: rotate(-45deg);
  border-radius: 4px;
}
<div class="left-corner"></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

Suggestions on how to refactor redundant code in various peer AngularJS controllers for handling $intervals

In my compact single-page application, I have implemented multiple tabs to display operational status information for different applications. Each tab is associated with a controller that creates $interval objects to make AJAX calls to fetch status data fr ...

Steps to configuring reverse gradient in a solitary line

I have successfully resolved similar issues with diagonal gradients in the past. However, I am currently facing challenges with linear gradients. Previously, I was able to create a gradient with a cross pattern. background: linear-gradient(to right, tran ...

Text scrolls - items are shown all at once

I've been experimenting with creating moving/scrolling text. After some trial and error, I've managed to achieve this effect. If you're interested, you can check out the code on CODEPEN. The issue that's currently bothering me is rel ...

Is it possible for me to retrieve/load a <datalist> element from a different file?

I'm in the process of developing a Google Chrome extension that essentially consists of a dropdown menu and an input box with datalists. The user can change their selection in the dropdown menu, which will then switch the datalist being used by the in ...

An alternative method to confirm the checkbox selection without physically clicking on it

Currently, I'm in the process of creating a basic to-do list and have been attempting to connect the task with its corresponding checkbox. My goal is for the checkbox to automatically be checked when the task is clicked. Instead of using HTML to add ...

Create a URL hyperlink using javascript

I am looking to create a link to a page that updates its URL daily. The main URL is where X represents the day of the month. For example, for today, July 20th, the link should read: In my JavaScript section, I currently have code that retrieves the cur ...

Two divs with floated attributes and equal heights

My unique HTML is below: <div class="container"> <div class="box"> <div class="float"> <img src='http://media-cdn.tripadvisor.com/media/photo-s/03/9b/2f/db/miami-beach.jpg' /> </div> ...

The process of eliminating body padding in Nuxt.js

I'm considering building a website using Nuxt.js because I've heard it's both cool and user-friendly. While I do have some knowledge of vue.js, I'm stuck on a particular issue: How can I remove the padding from the body? I understand ...

Troubleshooting problem with divs overlapping in Internet Explorer 7

Check out this webpage: http://jsfiddle.net/aJNAw/1/ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ...

Display a smaller image preview in the product photo gallery

Hey there! I'm currently working on a website and looking to showcase my product in a similar way as shown here: I would like my main image to be displayed with all the other variants of the product image underneath, along with the same visual effect ...

Images within the signature are not appearing as intended

Trying to find a way to display a company logo in an email signature without it being blocked by default on different email clients. Initially, I attempted uploading the image to the company website, but encountered the following error: So, I decided to t ...

Navigate to a fresh HTML page upon form submission

I'm completely new to the world of web apps and JavaScript, and I'm facing an issue where my form submission doesn't redirect me to a thank you page. Instead, it just leads to a blank page every time. I've tried researching solutions on ...

Webpack fails to handle CSS background images

I'm having trouble with my Webpack configuration as it's not processing CSS images set in the background property: background: url('./hero.jpg') no-repeat right; This is resulting in an error message that reads: ERROR in ./src/app/comp ...

Utilize ASP to limit the application of a CSS file exclusively to the child page

My website consists of a master page and several child pages. I have created specific CSS classes for styling. However, I only want certain child pages to utilize these styles while the master page should always use them. How can I limit the access to th ...

The Bootstrap navbar branding element vanishes upon navigating away from the home page

I have recently started learning Python, Django, and Bootstrap. I am facing an issue where the navbar-brand disappears when navigating to a different page or view other than the index. In my case, the nav-brand is an image source. Below is the code snippet ...

Avoid running old JavaScript code when using turbolinks in conjunction with highcharts library, specifically LazyHighCharts

Utilizing turbolinks 5 and rails version 5, along with the latest Highcharts has been causing me some issues. T LazyHighCharts offers a solution for Turbolinks 5 by encapsulating chart building javascript within (function() { document.addEventListe ...

Troubleshooting issue with changing class based on input values

It appears that there is an issue with the functionality when switching values on page load. Initially, I was able to make it work for a single switch, but now that there are multiple switches on the page, toggling affects all of them. How can I modify it ...

What is the best way to customize the behavior of multiple instances of ng-include within the same view?

My goal is to have unique behavior for each instance of the calendar that I include multiple times in my main HTML view. Specifically, I want to display 3 different dates based on the day selected in each calendar. In my main HTML view, I have included th ...

Implement a single CSS menu across various HTML pages

I'm currently working on developing a website. All of my pages have a common menu bar that I would like to include from a separate HTML file. Is there a way to include HTML files in order to address this concern? If so, what is the syntax for imple ...

Could this be the most straightforward and versatile method for vertically centering text inside a block element?

Discovering something new in the world of coding is always exciting: HTML: <div>Vertically Centered Text<span></span></div> CSS: div { height: 100px; /* adjust as needed */ } div > span { display: inline-block; v ...