Is it possible to create a torn border effect in CSS with no images?

Is there a straightforward method to achieve a torn border on just one side of a div block without the need for external images?

Answer №1

To achieve a torn effect, you can utilize CSS background gradient:

HTML

.box:after {
  content: "";
  display: block;
  position: relative;
  top: 0;
  left: 0;
  width: 200px;
  height: 200px;
  background: linear-gradient(#2B3A48 0%, transparent 0%), linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
  background: -webkit-linear-gradient(#2B3A48 0%, transparent 0%), -webkit-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -webkit-linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
  background: -o-linear-gradient(#2B3A48 0%, transparent 0%), -o-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -o-linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
  background: -moz-linear-gradient(#2B3A48 0%, transparent 0%), -moz-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -moz-linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
  background-repeat: repeat-x;
  background-size: 0px 100%, 9px 27px, 9px 27px;
}
<div class="box"></div>


Looking for Transparency?

If transparency is desired, hexadecimal color values can be substituted with rgba values.

  • The hexadecimal value of the blue color used is #2B3A48
  • This same blue in rgba format is rgba(43,58,72,0)
  • RGBA represents Red Green Blue Alpha where alpha denotes transparency levels ranging from 0 to 1.
  • To adjust transparency, modify the alpha value in rgba(43,58,72,0) based on preference.

EXAMPLE

rgba(43,58,72,0.5) = 50% translucent.

SOLUTION

To obtain the ripped effect, simply replace all occurrences of #2B3A48 with rgba(43,58,72,0.5)

.square:after {
  content: "";
  display: block;
  position: relative;
  top: 0;
  left: 0;
  width: 200px;
  height: 200px;
  background: linear-gradient(rgba(43, 58, 72, 0.5) 0%, transparent 0%), linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 linear-gradient(45deg, #272220 33.33%, rgba(43, 58, 72, 0.5) 33.33%) 0 0%;
  background: -webkit-linear-gradient(rgba(43, 58, 72, 0.5) 0%, transparent 0%), -webkit-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -webkit-linear-gradient(45deg, #272220 33.33%, rgba(43, 58, 72, 0.5) 33.33%) 0 0%;
  background: -o-linear-gradient(rgba(43, 58, 72, 0.5) 0%, transparent 0%), -o-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -o-linear-gradient(45deg, #272220 33.33%, rgba(43, 58, 72, 0.5) 33.33%) 0 0%;
  background: -moz-linear-gradient(rgba(43, 58, 72, 0.5) 0%, transparent 0%), -moz-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -moz-linear-gradient(45deg, #272220 33.33%, rgba(43, 58, 72, 0.5) 33.33%) 0 0%;
  background-repeat: repeat-x;
  background-size: 0px 100%, 9px 27px, 9px 27px;
}
<div class="square"></div>

If a transparent black shade is desired, substitute the black color with an rgba value.

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

Issue with allowing the second floating div to occupy the remaining horizontal space inside the container div

Describing the scenario, there is a container division with two floating divisions of different widths. You can view it live by following this link (look for "Hotel booking" section): I have added a border to the second division. My goal is to make this s ...

Strange floating elements wrapping inside Bootstrap 3 column divs

Essentially, I have a series of twitter-bootstrap square divs with classes like col-md-x, col-sm-x stacked together to form an image list. It's functioning smoothly for the most part. However, there are instances (which remain a mystery to me) where t ...

tips on resizing a dragged item to fit into a dropped container using jQuery

Is there a way to adjust the size of a dragged element to match its parent's dimensions after successfully dragging it (ensuring that both elements have the same width and height)? Does anyone know how to accomplish this alignment between the two ele ...

How to create a border using a repeated image with spacing between each repetition

Is there a way to create a dashed horizontal line from an image and adjust the spacing between each dash using HTML and CSS? I feel like using javascript for this would be excessive. https://i.sstatic.net/YiD9q.png I'm encountering this issue with t ...

Ways to have the right sidebar seamlessly blend in with the page content by hovering over it rather than occupying a separate area

While working on the design of my website, I encountered a challenge with the sidebar. I aim to have a sidebar that hovers from the right side to the left, displaying the full content when the cursor is placed over it, much like the one featured on . Altho ...

Introducing a fresh WooCommerce setting now available within the Inventory section: "Sold individually"

I implemented a new feature under the Inventory > Sold individually setting using the woocommerce_product_options_sold_individually hook. Here is the code snippet: add_action( 'woocommerce_product_options_sold_individually', 'custom_produ ...

Tips for customizing text field appearance in Safari and Chrome

I haven't had a chance to test it on IE yet. My goal is to create a unique style for the background image and text box shape, along with borders, for the search bar on my website, [dead site]. If you check it out on Firefox or Opera and see the sear ...

Picture escapes the div in a hurry

I mistakenly placed the yellow dot "gif1" outside of the black box "gif" instead of inside. How many errors can you spot in my code? Take a look at the Livewave Preview to see the current state of the design. I have attempted to fix this issue by using o ...

Converting a CSS Submenu from Horizontal to Vertical Orientation

Below is the current code snippet for my menu navigation bar: To access my live blog, please click on this link: www.4time2fun.com <div id="topmenu"> <div id="navigation"> <ul class="categories"> <li class="articles"> <a href ...

Tips for ensuring the position of buttons remains consistent no matter the size of the image

I am facing an issue with maintaining the button location when an image is added. My goal is to ensure that the button's position remains horizontal consistently. Front-end: React CSS framework: semantic-ui-react render() { return ( &l ...

Tips for stopping a CSS animation from restarting when the order of a v-for rendered list is updated in Vue.js

I am working on a project that involves creating a list of data and using a template to draw blocks with time bars for each item in the list. The order of the items in the list can be updated at any time. However, I have noticed that whenever the list ord ...

Conceal the parent div from its sibling within the same parent container

My goal is to conceal a parent component from its child element. I attempted to achieve this by using the parent component as a background while adding additional backgrounds to the child elements for overriding purposes. However, this method did not work ...

Tips for resizing a chartjs within bootstrap columns to accommodate various web browsers

I am using chartjs charts within bootstrap rows and columns. The number of columns per row can be dynamically changed. For example, I could rebuild my rows with the following markup: const twoColumn = spacerColumn + "<div class=&ap ...

Loading New Content in a Bootstrap Card with Navbar: A Guide on Updating Content without Refreshing the Page

Working with Django in the creation of a basic website, one specific page named analysis.html is utilized to access data from the Twitter API. Within the analysis.html file, there exists a card sourced from Bootstrap's components: <div class="car ...

The functionality of bootstrap.styl malfunctions during the parsing process in stylus

I am attempting to incorporate stylus, a css preprocessor, with twitter bootstrap version 2.04. Upon downloading boostrap, I execute the command "stylus --css < bootstrap.css > bootstrap.styl" to generate a bootstrap.styl file. However, upon trying t ...

Looping CSS text animation with typing effect

I am struggling with a CSS code that types out text, but it only does so once and I need it to repeat infinitely. Despite adding animation-iteration-count: infinite;, it still doesn't work as intended. Another issue is that it slows down at the end. H ...

I am facing an issue in my Laravel project where certain colors are not displaying correctly or appear to be missing. I am unsure of how to

I am facing an issue in my Laravel project where some colors are not displaying or are missing. I have tried changing the color theme without success. Additionally, the syntax highlighting is not working properly even after trying the Laravel extension. B ...

Steps to turn off the automatic completion feature for orders in WooCommerce on your WordPress website

Looking for assistance with changing the order status from completed to processing. When an order is placed, it automatically goes to completed status which is not the desired outcome. The status should change based on the virtual product purchased. I wou ...

Styling emails with CSS: Tips for customizing fonts

I've been experimenting with setting a personalized font for an email. Within the HTML code of the email, I included the fonts using this snippet: <head> <style> /* latin-ext */ @font-face { font-family: &ap ...

What is causing the scrollbars to appear only in IE on this layout?

While my layout functions properly in Chrome, I am encountering an issue in IE where the main content area is displaying scrollbars instead of filling out 100% as intended. Is there a way to fix this? In the design I am working on, the main content area h ...