How can I modify it so that it begins at the bottom left instead of the bottom right?

After stumbling upon this interesting codepen featuring a diagonal fill div on hover, I find myself wondering how to change the starting point of the fill from bottom right to bottom left. While it may seem like a simple task, I am at a loss on where to begin. Any guidance or assistance on this matter would be immensely appreciated.

.diagonal {
    position: relative;
    line-height: 50px;
    background: #67809F;
    color: white;
    border: none;
    font-weight: bold;
    font-family: 'Open Sans', sans-serif;
    overflow: hidden;
    z-index: 1;
    padding: 0px;
  }

.diagonal:after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 500%;
    height: 1000%;
    background: #34495E;
    z-index: -1;
    transform-origin: 0% 0%;
    transform: translateX(calc(20% - 25px)) translateY(10%) rotate(-45deg);
    /transform: translateY(10%) translateX(16%) rotate(-45deg);
    transition: transform .3s;
  }

.diagonal:hover::after {
    transform: translateY(10%) translateX(-25px) rotate(-45deg);
  }

Check out the codepen here

Answer №1

Adjust the translateY(10%) to translateY(0%) in both the original and hover states

https://jsfiddle.net/9c4x8fkv/

.demo {
text-align: center;
margin-top: 150px;
}

.mt {
  margin-top: 20px;
}

.small {
  width: 120px;
}

.medium {
  width: 160px;
}

.large {
  width: 230px;
}

.extra-large {
  width: 360px;
}

.diagonal {
  position: relative;
  line-height: 50px;
  background: #67809F;
  color: white;
  border: none;
  font-weight: bold;
  font-family: 'Open Sans', sans-serif;
  overflow: hidden;
  z-index: 1;
  padding: 0px;
}
.diagonal:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 500%;
  height: 1000%;
  background: #34495E;
  z-index: -1;
  transform-origin: 0% 0%;
  transform: translateX(-25px) translateY(0%) rotate(-45deg);
  /transform: translateY(10%) translateX(16%) rotate(-45deg);
  transition: transform .3s;
}
.diagonal:hover::after {
  transform: translateY(0%) translateX(calc(20% - 25px)) rotate(-45deg);
}
  
<div class="demo">
  
  <button class="mt small diagonal">Click me!</button>
  <br>
  <button class="mt medium diagonal">Click me!</button>
  <br>
  <button class="mt large diagonal">Click me!</button>
  <br>
  <button class="mt extra-large diagonal">Click me!</button>

</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

Creating a layout with two divs displayed next to each other using CSS

Just when I thought I had it figured out, my two side-by-side divs are not behaving as intended inside the parent div. Why is the orange "Content" div ending up below the navigation bar? Can anyone spot what I did wrong here? Thank you in advance! CSS: ...

Every time I rotate my div, its position changes and it never goes back to

Trying to create an eye test by rotating the letter "E" when a directional button is clicked. However, facing an issue where the "E" changes position after the initial click instead of staying in place. Here is a GIF showcasing the problem: https://i.stac ...

Is there a way to ensure that the border of a textarea matches the border of a text input?

My goal is to make the textarea fields in my form have the same appearance as the text input fields, regardless of the browser being used. I am interested in achieving this without imposing a customized style, but instead by leveraging the standard style w ...

How can I make an HTML textbox in C# MVC flash a background color for one second using TextBoxFor?

I'm currently working with MVC and have the following code in my razor view. @Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly", @class=ViewBag.IsLatest ? "latest":""}) I want to briefly change the background color of this te ...

The process of combining a CssStyleCollection with a System.Web.UI.WebControls.Style

I am working with a list item and trying to apply styles using System.Web.UI.WebControls.Style. However, I noticed that there isn't a MergeStyle option similar to what's available for controls. Instead, there is an Attributes.CssStyle property of ...

Exploring the effects of zooming on YouTube videos in Firefox

Strange phenomenon, but my website appears to be having display issues specifically on Firefox. Surprisingly, it looks perfectly fine on IE9, Safari, and Chrome. The layout of the site in Firefox seems to change when I zoom in or out, resulting in the You ...

Is the order of elements in a CSS file important?

In my situation, I am dealing with a nested list and enclosing div that was created by Drupal's menu system, so I am unable to modify it. My goal is to replicate the menu from a hardcoded website (link removed). How can I include the sub-items (ul l ...

Bootstrap creates an element positioned at the end of the row

I am currently utilizing the Bootstrap framework and I'm facing a challenge where I need an element positioned at the end of a row. <div class="row"> <div>div 1</div> <div>div end</div> </div> These divs a ...

Optimizing carousel image dimensions for various screen sizes

I'm currently working on a full screen carousel in HTML and I'm curious about the optimal image size to ensure it resizes properly on all screen sizes without any distortion. Can anyone help me out with this? ...

Lengthen the space between each item on the list to enhance readability

Is there a way to adjust the line height between li tags? I attempted using height:100%, but it seems ineffective. Are my methods correct? Can anyone provide guidance? The following is the code snippet in question: <html xmlns="http://www.w3.org/1999 ...

Table with Bootstrap 4 drop-down navigation

I'm having some issues with a dropdown menu in Bootstrap 4. The problem arises within a table: https://i.sstatic.net/AbqTX.png When I click on the settings in the first row, a dropdown appears as expected: https://i.sstatic.net/xSfli.png However, ...

Groupings of CSS style declarations

I am currently learning CSS and I have a question that may seem basic or silly, but I can't seem to find the answer anywhere. Here is the CSS code I am working with: #table-of-contents ol { list-style-type: none; counter-reset: item; margin: 0; ...

What steps can I take to ensure that my DIV completely surrounds the floating DIVs within it?

Having an issue with my CSS. The problem arises in a specific area of my screen where there are variable numbers of buttons enclosed within a DIV named sbr_btn. The layout is as follows: Outer DIV Outer DIV Outer DIV 01 02 03 04 05 06 07 08 ... ...

How can I vertically and horizontally center elements in the middle of a web page using ASP.NET and CSS?

Creating a basic web form can be easy. It must contain three lines of text/ASP.NET elements within a Master page that includes a header and footer. To ensure that these three lines are centered both vertically and horizontally on the page, especially whe ...

Changing the Options for Page Size in Material Paginator

Firstly, here is my angular code: ts: @Component({ selector: 'app-dashboard', templateUrl: './dashboard.component.html', styleUrls: ['./dashboard.component.scss'] }) export class DashboardComponent implements OnInit, A ...

What could be causing my JavaScript function to not properly set the CSS display property to "inline" for an image element?

Objective: My goal is to design a webpage featuring a basic image of fruits. Upon clicking the image, it should transform into an array of 6 images showcasing various types of fruits such as apples, oranges, and bananas arranged in two rows with three imag ...

Issue with the height of nested divs within ion-col not being rendered properly on iOS devices

I am currently using Ionic 2 for my project. Presented below is the template I have: HTML Code <ion-grid> <ion-row> <ion-col width-20> <div> <img src="http://www.kacholy.com/new_site/pic/image_727 ...

What is the method for stretching the navbar and content to fill the entire viewport in Bootstrap?

Can anyone help me with an issue regarding a navigation bar and content created in Bootstrap 5? I'm trying to use vh-100 to make both the navigation bar and content stay on the view page without a scrollbar. However, the size of the navigation bar is ...

What is the reason that <span> elements do not automatically wrap around to the next line when they are in line with each other without any white space?

Once upon a time, I believed that line breaks had no impact on the rendering of HTML due to minification. However, I recently discovered something peculiar. <!DOCTYPE html> <html> <body> <style> div { width: 200px; background: ...

Utilizing CSS to incorporate a background image into HTML code

Is it feasible to utilize pure HTML for the background-image property? Consider the following scenario: The original: background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height=&apo ...