Creating a striking two-tone border pattern in an HTML document

Looking to create a design with a straight line that features two colors and a slanted line in between. Here is an example of the desired result:

https://i.stack.imgur.com/9ys6e.png

Answer №1

When the border attribute is a must-have, consider utilizing SVG attributes like "d" to achieve the desired effect:

body{
  background:black;
}
.stripdiag {
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M0 97 L100 97 L100 100 L0 100 L0 97Z' fill='blue' /><path d='M61 97 L100 97 L100 100 L61 100 L61 97Z' fill='red' /><path d='M60 100 L61 100 L70 1 L69 0 L60 100Z' fill='white' /></svg>");
    height: 120px;
}
<div class="stripdiag"></div>

Key points to remember:

M x,y Move to specified coordinates x,y

m x,y Move to the right x and down y (or left and up if negative values)

L x,y Draw a straight line to the given coordinates x,y

l x,y Draw a straight line relatively right x and down y (or left and up if negative values)

H x Draw a horizontal line to specific coordinate x

h x Draw a horizontal line relatively to the right x (or to the left if a negative value)

V y Draw a vertical line to exact coordinate y

v y Draw a vertical line relatively down y (or up if a negative value)

Z or z Close the current subpath by connecting the last point of the path with its initial point. If the two points are at different coordinates, a straight line is drawn between them.

Answer №2

Give this a shot:

//HTML
<div class="striped-bar"></div>

//CSS
.striped-bar{
    height: 10px; //adjust the height to your preference
    border-top: 10px solid;
    border-image: linear-gradient(-45deg, purple 30%, white 30.5%, white 31%, 
    white 31.5%, green 32%) 8;
}

Take a look at an example here: https://jsfiddle.net/we52h369/3/

You may need to tweak the values based on the positioning of your border (top or bottom) and the width of your div. In order to achieve the desired angle, I rotated the gradient by -45 degrees which resulted in the stop points being listed in reverse order. While there might be a better approach, for now, this seems to do the job. The final value after the bracket controls the angle's pitch - higher value = steeper pitch. Experiment with these parameters and you should get the effect you want. Just remember that the key feature here is the border-image property. If you still require assistance, explore this property further.

Cheers!

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

Changing CSS attributes with jQuery when conditions are met

After creating menus with expandable items that change style upon clicking, I encountered an issue where the styling changes were not being applied correctly. To address this problem, I followed Sushanth's suggestion and replaced $this with $(this), ...

Include a stylesheet as a prop when rendering a functional component

Using Next.js, React, Styled JSX, and Postcss, I encountered an issue while trying to style an imported component for a specific page. Since the stylesheets are generated for a specific component at render time, I attempted to include custom styles for the ...

Display Text Only When Selected - Material-UI

Is there a way to display only the selected tab's text? I came across this code snippet in the MUI documentation that involves showing labels on selection. How can I achieve this effect, maybe by manipulating the state to change the color of the selec ...

How come the hidden container does not reappear after I click on it?

I'm having an issue with a hidden container that holds comments. Inside the container, there is a <div> element with a <p> tag that says "Show all comments". When I click on this element, it successfully displays the comments. However, cli ...

How can I delete a CSS class from an element?

Is there a way to remove the "ui-widget-content" class from the code below? It appears in multiple places throughout my code. Here is an example snippet: <pre> <form id="clientForm"> <div id="clientData"> <div id="gbox_grid_1" class=" ...

A straightforward development and production build to incorporate HTTPS for a static website created with React and Express

Is there a straightforward method to create a static web page and Node backend where the Node server runs in HTTPS during development but not in production? How can the static web page point to https://localhost/foo in dev mode, and simply /foo in producti ...

Utilize Flexbox to arrange elements in a column direction without relying on the position property in CSS

Flexbox - align element to the right using flex-direction: column; without relying on position in CSS Hello everyone, I am looking to move my row element to the right without using positioning. This code includes flex-direction: column; and I do not have ...

Employing Bootstraps data-spy and data-toggle features with a button

Is it possible for a button to not only toggle a hidden accordion but also scroll the page to that section? Currently, my code is working great with navigation, but I'm struggling to make the button display text and scroll to the top of the section. ...

Mobile site experiencing slow scrolling speed

The scrolling speed on the mobile version of my website, robertcable.me, seems to be sluggish. Despite conducting thorough research, I have not been able to find a solution. I have attempted to address the issue by removing background-size: cover from my ...

HTML needs to be wrapped around every set of three items using C# ForEach loop

Currently, I am faced with the task of constructing an HTML code structure within C# code behind. Specifically, I need to insert an HTML element that spans 3 columns in a row of 12 columns (utilizing Zurb Foundation). To achieve this, I am iterating throu ...

What is the best approach to creating a fully rounded capsule using CSS?

I've been having trouble creating a complete capsule in CSS and I'm not achieving the expected outcome. Can anyone assist me in resolving this issue? I am new to CSS. Below is my code: <style> #myStyle { position: relat ...

Modifying the Background Color of a Header in React Native

As a newcomer to React Native, I am attempting to change the background color of the header bar (Navigation Bar). Here are some approaches that I have tried: return ( <View style={styles.container}> <NavigationBar titl ...

The IIS appears to be experiencing difficulties in serving static content such as CSS, JavaScript, and images, resulting

I've completed this process a countless number of times... Start by creating a project (in this case, an empty web application using only HTML files). Edit the hosts file to allow for a custom URL (local.xxx-xxx.com) Create an IIS website and app po ...

What is the best way to prevent a draggable div from moving past the edge of the viewport?

My situation involves a draggable div that functions as a popup window when a specific button is clicked. However, I noticed that dragging the div to the end of the viewport allows me to drag it out of the visible area, causing the body of the page to expa ...

Efficiently adjust the width of a child div to automatically fit within

I stumbled upon this fascinating jsfiddle on this website that almost completely addresses my concern, solving up to 90% of it. Check out the JSFiddle Nevertheless, I am keen to incorporate margins within the inner divs. Despite attempting to modify the ...

Can Jquery be used to swap out specific li content?

<div class="widget_ex_attachments"> <ul> <li> <i class="fa fa-file-word-o"></i> <a href="uploads/2014/09/Parellel-universe.docx">Parellel universe</a> </li> ...

Access a webpage whose URL has been dynamically assigned using JavaScript

I have a website that consists of a single page and features four tabs. Whenever a tab is clicked, it displays the corresponding content in a div while hiding the other three divs along with their respective content. To ensure a smooth user experience, I u ...

The inner div overflowing at 100% dimensions

I'm working with an outer DIV that has a CSS property of position: fixed to serve as an overlay. Inside this, I have another div set to 100% width with a margin of 30px to create the appearance of an inner border frame. Unfortunately, the right and bo ...

What methods can I use to pass an argument from an HTML file to jQuery?

I need to retrieve the value 7 from the HTML file <button id="buttonseven" onclick="buttonClick(7)">7</button> How can I capture this value using jQuery? $(document).ready(function(){ $('#buttonseven').click( ...

flawless approach to showcasing visual content

I am a beginner in css. My goal is to showcase my images in an optimal way This is the HTML code I have: <div id="photos"> <h3>Title of the Photo</h3> <P class="like"><a href="#">Give it a Like</a& ...