Generate a spider's web beneath an hour element using CSS

I am attempting to create a spider's web effect under an <hr /> element, but I am encountering difficulties with the circular parts.

Instead of using SVG, I want to style the hr element so that the web appears under all instances of it, without requiring additional HTML elements.

Below is a rough depiction of what I am aiming for:

Desired Outcome

Something similar to the image shown here:

Current Code

My current approach to creating the 'spindles' between the pseudo elements involves the following CSS:

html{
    margin:0;
    padding:0;
    background:rgba(0,0,0,0.1);
    color:black;    
}
hr{
    height:30px;
    border-bottom:none;
    border-right:none;
    position:relative;    
}
hr:before, hr:after{
    content:"m";
    position:absolute;
    height:40px;
    width:1px;
    top:0;
    left:0;
    transform-origin:top left;
    transform:rotate(-20deg);
    background:black;
}
hr:after{
transform:rotate(-40deg);    
}
<hr />

However, this method results in overlapping 'm's and does not achieve the desired effect.

Past Attempts

  • I have experimented with using different letters in the content property of the pseudo elements.

  • I have also tried incorporating curves and overflow hidden properties, but these attempts were unsuccessful.


Any suggestions or solutions would be greatly appreciated. If achieving this with pure CSS is possible, that would be ideal! Currently, I am struggling to find a method to attain this level of functionality.

Answer №1

Note: While it is possible to achieve this effect using CSS, it is recommended to use SVG or PNG images for such complex shapes/effects since CSS is not primarily designed for this purpose.

CSS Method:

To create the spider web effect, the following steps are taken:

  1. The right angle borders on the left and top constitute the actual borders of the hr element. Height is explicitly set for the hr element as the default height of the hr element only includes the border thickness.
  2. The diagonal lines in the middle are generated using a pseudo-element that is skewed along both the X and Y axes.
  3. The circular elements are produced using another pseudo-element with a 50% border-radius, alongside additional box-shadows projected around and below it. The central circle/ellipse in the top row is the real element while the others are shadows. Enlarging the shadow size for the shapes in the second row is achieved by adding an extra spread radius to the shadow.
  4. The arc-shaped shadow effect is created using two shadows, one placed over the other to form just an arc rather than a complete solid ellipse.

hr{
    border-left: 2px solid black;
    border-top: 2px solid black;
    height: 200px;
    overflow: hidden;   
    position: relative;
    border-right: none;
    border-bottom: none;
}
hr:after{
    position: absolute;
    content: '';
    top: 0px;
    left: 0px;
    height: 100%;
    width: 100%;
    border-left: 2px solid black;
    border-top: 2px solid black;
    -webkit-transform: skewY(30deg) skew(30deg);
    -moz-transform: skewY(30deg) skew(30deg);
    transform: skewY(30deg) skew(30deg);
    -webkit-transform-origin: left top;
    -moz-transform-origin: left top;
    transform-origin: left top;
}
hr:before{
    position: absolute;
    content: '';
    top: 0px;
    left: 0px;
    height: 30px;
    width: 36px;
...
<hr>


For better comprehension of how box-shadows were used to create arcs, here's a snippet where the shadows have different colors from the background.

hr{
    border-left: 2px solid black;
    border-top: 2px solid black;
    height: 200px;
    overflow: hidden;   
    position: relative;
    border-right: none;
    border-bottom: none;
}
hr:after{
    position: absolute;
    content: '';
    top: 0px;
    left: 0px;
    height: 100%;
    width: 100%;
    border-left: 2px solid ...
<hr>

Here you can view three rows of circular/elliptical parts. A screenshot of its output is provided below.


SVG Method:

Here's a simple SVG implementation of the spider web pattern using the path element and a (arc) commands.

div.vector {
  margin: 10px auto;
  height: 250px;
  width: 600px;
  overflow: hidden;
  position: relative;
}
svg {
  height: 100%;
  width: 100%;
}
line,
path {
  stroke: #CCC;
  stroke-width: 2px;
  fill: none;
}
#top {
  stroke-width: 2px;
}
/* For display purposes */

body {
  background: #000;
}
<div class='vector'>
  <svg viewBox='0 0 600 250' preserveAspectRatio='none'>
    <line x1='1' y1='1' x2='600' y2='1' id='top' />
    <line x1='1' y1='1' x2='1' y2='250' />
    <line x1='1' y1='1' x2='450' y2='250' />
    <line x1='1' y1='1' x2='175' y2='250' />
    <path d=...

Answer №2

After giving it my all...

It proved challenging to achieve the desired outcome with just 2 pseudo elements...

.spider:after, .spider:before {
    content: "";
    position: absolute;
    left: 40px;
    width: 100px;
    height: 80px;
    border: solid 3px transparent;
    border-top-color: black;
    border-left-color: black;
    transform: skewX(50deg);
    background-image: radial-gradient(ellipse at bottom right,  
        transparent 100px, black 100px, 
        black 102px, transparent 102px,
        transparent 120px, black 120px, 
        black 122px, transparent 122px
    );
    background-repeat: no-repeat;
    transform-origin: top left;
}

.spider:before {
    transform: skewX(50deg);
}
.spider:after {
    transform:  rotate(38deg) skewX(60deg);
}
<div class="spider"></div>

Answer №3

Have you considered trying out something like this? (JSFiddle)

Here's a snippet using jQuery .after() to insert a spider's web image right below any <hr> tag:

$(document).ready(function(){
    $("hr").after("<img src='http://www.repeatimpressions.com/images/2305.gif' class='hrSpiderWeb'>");
    //This script will append the spider web image after each <hr> element
}); 

You can then simply incorporate an <hr> in your HTML markup, and it will automatically have the styled image beneath it.


To enhance the effect, consider adding the following CSS rules:

$(document).ready(function() {
    $("hr").after("<img src='http://www.repeatimpressions.com/images/2305.gif' class='hrSpiderWeb'>");
    //For every <hr> element, jQuery will add the spider web image after it
});
.hrSpiderWeb {             /* Styling for the image*/
    height: 75px;           /* Setting the height */
    margin-top: -2px;       /* Removing space between image and line */
    margin-left: -5px;      /* Aligning the left side of the image */
}
hr {
    margin-bottom: -2px;    /* Further alignment adjustments */
    /*Styling options for the <hr> - can be customized */
    height: 1px;
    color: black;
    background-color: black;
    border: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Some content</p>
  <hr>
<p>Some more content!</p>

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 purpose of row-gap (and column-gap) in both Flexbox and Grid Layouts?

While researching browser compatibility for the gap property, I came across this informative page: https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap. The page includes examples for both Flex and Grid Layouts, leading me to assume it would only work ...

Is there a way to conceal a Select element so that it is not visible on the screen, yet can still activate the dropdown menu when another element is clicked

One idea for my website is to replace a select element with a button that triggers the dropdown. The plan is to place the select element inside a button DIV, position the select element on top of the button, and set its opacity to 0 so it appears hidden. W ...

Increase the size of the grid system column upon clicking on a Bootstrap icon

I am using Google Maps in a tab with Bootstrap, but the map is too small. I would like to change the Bootstrap grid system when I click on a FontAwesome icon: the first column should turn into col-md-8, and the second column should become col-md-4. Here i ...

The CSS classes for the dropzonejs are not being properly updated for editing purposes

I'm currently facing an issue where I am attempting to include an editable area inside a dropzone, but for some reason, the editable area is not visible within the dropzone and the CSS classes are not being applied. <a href="#" editable-text="us ...

Tips for synchronizing the height of a scrollable list-group column with a neighboring column

Within my Bootstrap 4 layout, I have a column on the left that includes a dynamically generated .list-group, which could potentially contain numerous .list-group-items. On the right side, there is another column showcasing multiple cards inside a .row. Th ...

CSS - Update BackgroundColor Depending on Child Element Color

Is there an official CSS way to change the background color based on the child element in HEX? For example: render() { return ( ... <span> <h3 style={{ color: item.color }}>Item Color</h3> </span> ...

Having trouble retrieving the object variable that begins with http

Within my application, I utilize a JSON object named profile which can be accessed in my HTML like so: <pre>{{ profile | json }}</pre> By using the above code, I am able to display the contents of the profile object on the screen, although sp ...

The content has spilled over from the div and leaked into the adjacent div

When the left div's content exceeds the right div's, it spills over into the next container div. Sample HTML: <div class="musictemplate_container"> <div class="musictemplate_left"> something<br> omething< ...

What could be causing my webGL page to fail loading the second time following a refresh?

My friend and I are working on a JavaScript page together. Initially, the page loads smoothly when opened in a tab, although it may be a bit slow. However, upon refreshing the tab, the WebGl canvas appears completely blank while the HTML elements are stil ...

Assistance required in adjusting the clickable area of the link

While casually exploring a random website, I decided to experiment with some design elements. However, I encountered an issue where the link was only clickable on the left side and not the right. This is how it appears: There is a div containing a heading ...

What is the best way to mirror an image using CSS3?

I'm looking to create a minimalist front page for my wife's jewelry website. I envision a simple layout with a blurred background and a sleek title at the top. In the center of the page, there will be several sections dedicated to different types ...

Tips for eliminating the gap between Bootstrap 4 columns

Is there a way to eliminate the spacing between Bootstrap columns? I have three columns set up using Bootstrap but no matter what I do, I can't seem to get rid of the space between them. <!doctype html> <html lang="en> <head> ...

Unable to rotate 3D cube

Struggling with getting my cube to rotate properly while coding. Anyone able to assist? I've exhausted all options. See my code here: Link to Codepen @keyframes spin { from { transform: rotateY(0deg); } to { transform: rotateY(360deg); } } bo ...

Can you explain the significance of the characters '& > * + *' in JSX (CSS)?

When using material UI, the progressbar demo includes lines of JSX code like this: '& > * + *': { marginTop: theme.spacing(2), }, Can you explain what the selector '& > * + *' represents in this context? ...

What could be causing my cross fade to not repeat as intended?

I created a basic background image cross fader using the code found at http://jsfiddle.net/jRDkm/2/. This code was inspired by . However, I'm encountering an issue where the slideshow only repeats once before fading to white. How can I modify the cod ...

Starting the description text immediately after the title while maintaining equal width for the title can be achieved by carefully

I need some assistance with formatting a title and description in a specific way. The title should be followed by the description starting on the next line while maintaining the same width for the title. It should resemble the image linked below https://i. ...

Learning how to retrieve a Docx file, or any type of file, using Django

My current project involves creating and storing a Docx file on the server based on user input. The file is then stored on the server to be accessed later. While the docx file is essentially static, I am encountering issues with enabling the download funct ...

Access a designated tab using cbpFWTabs

I am currently using the cbpFWTabs plugin from Tympanus for my tabs (http://tympanus.net/Development/TabStylesInspiration/). However, I am struggling to open a specific tab upon page load. I have attempted to create a show method within the page script, bu ...

Utilizing AnimateCSS within a ReactJs component

After installing Animate.CSS with the command npm install animate.css --save, I noticed it was saved in the directory ./node_modules as a locally packaged module. I went through the Animate.CSS documentation on Github, which mentioned that adding class na ...

Is there a way to automatically adjust the positioning of added pins on an image as I scroll through the image?

I have inserted a large image onto my HTML page and to manage its size, I am displaying it within a div that allows for scrolling like a map. Using jQuery, I have placed 3 markers on the image. The issue I am facing is that when I scroll the image, the ma ...