Slanted lower edge - entire width

Can anyone provide guidance on how to design a div that is 100% width and 300px wide, with a slightly angled bottom border that spans the entire width of the box?

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

I am open to using either CSS or JavaScript for this task, as long as it remains responsive. I have come across examples utilizing borders for similar shapes, but confess to not fully grasping the concept.

Answer №1

If you're trying to create a design similar to this:

<div class="box"></div>

What we're aiming for is using the border as the main visual element.

We specifically want the bottom left border to be see-through.

If we give it a suitable height, it starts to resemble the image you provided.

.box {
    border-right: 300px solid red;
    border-bottom: 10px solid transparent;
    height:100px;

}

This essentially creates a drawing made entirely of borders, manipulated and sized to appear solid.

JSFiddle link

However, making it responsive becomes more challenging since percentage values aren't supported with borders.

You're limited to a fixed maximum border size—in this case, we'll stick with 300px from before. So our .box class now becomes:

.box {
    border-right: 300px solid red;
    border-bottom: 10px solid transparent;
    height:100px;
    width:100%;
    right:0px;
    float:right;
}

To make it seem like the solid box is actually floating left, we adjust by floating right. A wrapper with hidden overflow will maintain the appearance of adjustment even though the border-image doesn't change in size:

.box_wrapper{
    width:100px;
    overflow:hidden;
    left:0px;
}

In our HTML, we add a wrapper:

  <div class="box_wrapper">
      <div class="box"></div>
  </div> 

The end result is a clever workaround for responsiveness!

Second JSFiddle

If you adjust the size of the .box_wrapper in the fiddle, the bordered box would appear to resize.

Note: There might be a more efficient method to achieve this effect!

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 encountered when attempting to utilize multiple datasets with Twitter Typeahead/Bloodhound

Hello, I am currently learning how to use Typeahead and Bloodhound with the latest javascript. Below is a snippet of my code: Html: <div id="multiple-datasets"> <input class="typeahead" type="text" placeholder="NBA and NHL teams"> </div ...

What is the best way to style odd and even divs in CSS?

I am struggling with applying different CSS styles to the odd and even divs in my code. The current implementation I have does not seem to be working as expected. I specifically want the styling to target only the direct children of the div, rather than an ...

I strive to establish a strong link between React and Firebase

I am facing an issue with Firebase and React. The problem arises after clicking on my add-data button to insert data into the database. Below is the error message I receive in the console: Reference_impl.ts:482 Uncaught TypeError: db._checkNotDeleted ...

An error occurred: Reaching the maximum call stack size when utilizing the .map function in jQuery

Encountering a console error: Uncaught RangeError: Maximum call stack size exceeded This is the jQuery snippet causing trouble: $(document).on("change","select.task_activity", function(){ selected_activity = $("select.task_activity :selected").map(fu ...

How do you find a specific value in an array using a function?

As a newcomer to JavaScript and StackOverflow, I am currently working on creating a function to search for a specific value within an array I have created. Although I have written what I think is a functioning function, it seems to not be working. Any idea ...

Different Ways to Modify the Appearance of Angular's mat-slide-toggle and mat-checkbox

I am facing an issue in my Angular form where I have a select box containing objects derived from database records. The goal is to automatically populate the form with the object values once one is selected. My Angular application includes an array of obj ...

Conceal the iframe if the source is http:// and there is no associated

Is there a way to hide the iframe only if the src starts with "http://"? This is what I have tried so far: <script type="text/javascript> if ( $('iframe[src^="http://"]') ) document.getElementById('iframe').style.d ...

The sticky navigation bar becomes fixed at the top prematurely

Having a sticky navbar on my Bootstrap-based website, I've implemented the following jQuery code: $(document).ready(function () { var flag = false; function stickNav() { $(".navbar-default").affix({ o ...

What is the best way to integrate Greensock CustomEase with TypeScript?

Currently, I am developing a game using Typescript with PixiJS and GreenSock (or is it GSAP?) for handling all the tweening. I recently encountered a situation where I needed to implement some custom easing using cubic-bezier curves. GreenSock provides a C ...

What is the process for extracting the differences between two or three files and merging them together in Node.js?

Recently, I've been experimenting with webpack and successfully managed to output and transform es5 build to include nomodule in the tags directly from HtmlWebpackPlugin using hooks. Similarly, for the es6 build, I added type="module". Howe ...

What is the best way to save user input from an HTML text field into a jQuery variable for long-term storage?

JavaScript with jQuery $(document).ready(function(){ var userGuess; $('#submit').on("click", function() { userGuess = $('#guess-value').val(); $("#value").text(userGuess); alert(userGuess); }); ...

Fetching an image from a URL using Node.js

My problem lies in downloading images with unknown file extensions (such as jpg, png, jpeg, or bmp) from a URL. I want to check the Content-Length of the image and if it is greater than 0, download it to a file. If not, I want to try downloading the image ...

Troubleshooting a JavaScript Error in AngularJS Module

I created a Module called "app" with some helper functions in the file "scripts/apps.js": angular.module('app', ['ngResource']).run(function($scope){ $scope.UTIL = { setup_pod_variables: function (pods){...} ... }); Now, I want to ...

Checking for at least one matching pair in a JavaScript object

I have a pair of dictionaries that I need to compare in JavaScript. The goal is to determine if there is at least one identical key-value pair between them, not necessarily the entire dictionary being identical. my_dict = {"Text1":"Text1", "Text2":"Text3", ...

Timezones not synchronizing properly with Moment.js

Hello everyone, I am currently exploring the world of moment.js along with the timezone add-on. I'm encountering some issues with a world clock project that involves using moment.js and moment-timezone.js together on a page where highcharts are also p ...

Filtering arrays based on object properties in a dynamic manner

I've created a React live search dropdown component that filters an array of objects based on a search term. It currently filters the objects by title and displays all related objects, which is working well. Current Implementation: Data Structure d ...

Locate commas within quotation marks using regex and replace them with their corresponding HTML entity

When dealing with a string like this: "Hello, Tim" Land of the free, and home of the brave I want it to be transformed into: "Hello&#44; Tim" Land of the free, and home of the brave This should be a simple task, but I'm struggling to find th ...

Get the nearest offspring of the guardian

I have a main 'container' div with multiple subsections. Each subsection contains 1 or 2 sub-subsections. Let's say I have a variable that holds one of the subsections, specifically the 4th subsection. This is the structure:container > s ...

Traverse through the nested JSON array using a loop

Exploring a JSON object: { "date_price": [ { "date": "Jan 2000", "price": 1394.46 }, { "date": "Feb 2000", "price": 1366.42 }, { "date": "Mar 2000", "price": 1498.58 }, { "date": "Apr ...

Integrating PayPal into your Node.js application with Express.js

Having successfully integrated PayPal into my website, I am now faced with the challenge of inserting the total in the PayPal syntax section of my code. In app.js, routes are created for my page on the website. In cart.js, the cart is created along with a ...