Background div tilted and positioned to the lower right corner of the content block

Take a look at this example

.nav-bar {
  position: relative;
  background-color: red;
}
.nav-bar:before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  overflow: visible;
  width: 100%;
  height: 10.938rem;
  background: #1a5733;
  z-index: -1;
  -webkit-transform: skewY(-1.6deg);
  -moz-transform: skewY(-1.6deg);
  -ms-transform: skewY(-1.6deg);
  -o-transform: skewY(-1.6deg);
  transform: skewY(-1.6deg);
  -webkit-backface-visibility: hidden;
  backface-visibility: initial;
  display: block;
}
.nav-menu {
  position: relative;
}
<div class="nav-bar">
  <nav class="nav-menu">
    <a href="#" class="nav-link">Home</a>
    <a href="#" class="nav-link">About</a>
    <a href="#" class="nav-link">Highlights</a>
    <br>
    <a href="#" class="nav-link">Contacts</a>
    <br>
  </nav>
</div>

I am attempting to align the green skewed nav-bar:before element with the right-hand side of the nav-container so that its overflow matches the content in the container: https://i.sstatic.net/DLZOp.jpg (Please note that I adjusted the bottom to -25px for the screenshot, as the original value of 0 produces inconsistent results upon screen resize)

Is it feasible to calculate the necessary bottom difference based on the 1.6-degree skew applied to the nav-bar:before element? How can we ensure responsiveness?

Or do we simply need to manually adjust using media query breakpoints?

Answer №1

To achieve this effect, simply add transform-origin: right bottom to the element. This will ensure that the transformation is centered around the specified point, making it appear fixed in place.

.nav-bar {
  position: relative;
  background-color: red;
}
.nav-bar:before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  overflow: visible;
  width: 100%;
  height: 10.938rem;
  background: #1a5733;
  z-index: -1;
  -webkit-transform: skewY(-1.6deg);
  -moz-transform: skewY(-1.6deg);
  -ms-transform: skewY(-1.6deg);
  -o-transform: skewY(-1.6deg);
  transform: skewY(-1.6deg);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform-origin: right bottom;
  display: block;
}
.nav-menu {
  position: relative;
}
<div class="nav-bar">
  <nav class="nav-menu">
    <a href="#" class="nav-link">Home</a>
    <a href="#" class="nav-link">About</a>
    <a href="#" class="nav-link">Highlights</a>
    <br>
    <a href="#" class="nav-link">Contacts</a>
    <br>
  </nav>
</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

Issues with sliding effects in jQuery: slideUp() and slideDown()

My experience with jquery is limited, and I'm facing issues with the slideUp() and slideDown() animations. I've been working on a vCard design inspired by Tim Van Damme's site. You can check out my design at this link. When clicking on the ...

Full-width Dropdown Menu within a Container with a Maximum Width

Is it possible to make a dropdown menu within a navigation bar open to the full width of the page, even when the parent container has a maximum width of 500px? My attempt to use 100vw resulted in misaligned dropdown elements, and I cannot move the navbar ...

What potential issues could arise from utilizing a numerical value as an identifier or class in an HTML4, XHTML, or HTML5 webpage?

I am hesitant about using elements with either id="12" or class="12", as the title suggests. Although it is allowed by the specifications, particularly in HTML5, have you faced any issues when doing so? In my specific scenario, I have <li> elements ...

How can I update a date value received from a v-model in Vue.js when the input type is set to "date"?

My issue lies in the date format coming as "9999-99-99 00:00:00", while I want it to be just "9999-99-99". The dates are stored in an array with multiple fields. How can I update the value using Vue.js? new Vue({ el: '#app', data: () => ...

Only IE7 seems to be experiencing a z-index problem with CSS that is not present on any

I’ve encountered a perplexing problem with CSS z-index in IE7 that I just can’t seem to solve. #screen { display: none; background-image: url('/images/bg.png'); background-repeat: repeat; position: fixed; top: 0px; le ...

Trying to understand the strange behavior of HTML parsing with jQuery in Javascript and Firefox

I have been working on a script to parse an HTML page using jQuery. The script runs smoothly in Chrome, IE, and Safari, but I'm facing some unexpected behavior while testing it in Firefox (version 36.0.1). Here's the code snippet: $.ajax({ u ...

Guide to Wrapping Inner or Wrapping All Elements Except for the Initial Div Class

I am looking to enclose all the elements below "name portlet-title" without including other elements within the "div class name portlet-title". I have attempted the following methods: 1) $("div.item").wrapAll('<div class="portlet-body"></div ...

Challenging glitch in the JavaScript code

My jQuery code seems to be functioning properly in online text editors like Fiddle and StackOverflow snippets. However, when I try to implement the same code in Brackets or view it on GitHub, the navbar scroll down animation fails to work as expected. You ...

Centered inline-block divisions

I've been coding for a number of years now, but I've recently started learning CSS. I'm currently facing an issue and need some help. I want to place two divs next to each other and center them. Here's the code I'm using: HTML: & ...

Updating a conditional statement in jQuery

Understanding jQuery has always been a challenge for me. I find myself spending hours reading documentation every time I try to implement it, only to achieve very little progress. Here's the code I'm currently working on with live-editing availab ...

Guide to concealing pop-up with animation when clicking outside

My question is: Clicking on OPEN should open the popup. Clicking on BACK should close the popup. Clicking outside the popup should also close it. Note: Clicking inside the popup when it is open should not close it. The popup should only close on an outs ...

Tips for creating animated card designs with HTML, CSS, and JavaScript

As I delve into the realm of CSS animation, my primary focus is on replicating the captivating card shuffling animation showcased at Here's a glimpse of the progress I've made so far: https://youtu.be/GDIJ2K22cnY While I've successfully im ...

Blending HTML elements with ASP.NET code

Trying to concatenate two strings separated by a line break. This snippet shows what I am attempting: <td>@(string.Join("<br /> ", report.TimeReportProjects.Select(x => x.Project.ProjectName)))</td> <td>@(string.Join("<br /& ...

An issue in D3.js where the chart bars are not properly synced with the x-axis labels

Currently delving into the world of d3.js for the first time. In our project, we needed to adjust the width of each bar from .attr('width', xScale.rangeBand()) line 46 to .attr('width', '10') line 50 After making this cha ...

Is it possible to manipulate the content inside a div tag using JavaScript in HTML?

What is the most efficient way to dynamically adjust a data offset value within an HTML tag using JavaScript? For example: <div class="box" data-offset="2s"></div> I am looking to update the value within the data-offset attribute based on s ...

Tips for creating an array key dynamically while working with several <select> elements in PHP

<select id = 'formMonths' multiple = 'multiple' name = 'formMonths[]'> <option value="1">item1</option> <option value="2">item2</option> <option value="3">item3</option> </select> ...

Sequence of HTML elements arranged in a stack

Recently, I came across a useful jQuery tutorial called "jQuery for Absolute Beginners: Day 8". In this tutorial, there is an interesting code snippet that caught my attention: $(function() { $('.wrap').hover(function() { $(this).childre ...

Ensure that the browser is instructed to utilize a designated Accept field within the HTTP request

Can a web browser be directed to use a specific mime-type in an HTML request? For example, can we achieve this with the following code: <a type="application/pdf" href="https://url.com/">PDF</a> or <a type="text/html ...

Achieving a frosted glass effect for your background without relying on a background image

I am currently working on creating a modal window in React with a blurred backdrop. My goal is to blur the backdrop content while keeping the background image clear, as there is no image behind the modal window, just content. I have explored various soluti ...

Dynamic font sizing in CSS allows text on a webpage to

I am working on creating a dynamic screen using AngularJS. Within this screen, there are objects with a specific size: .item { margin: auto; margin-bottom: 10px; width: 11vw; height: 11vw; text-overflow: ellipsis; overflow: hidden; } These i ...