Text in a class button that is not skewed

I crafted a button for my website using a CSS class, aiming for a parallelogram shape by utilizing the skew function. The code worked like a charm, giving the button the desired shape. However, I encountered a dilemma where the text inside the button also became skewed, following the shape of the button. Is there a way to prevent the text from looking like the Leaning Tower when inside the button? Here's the HTML code:

<input type="submit" alt="submit" value="Login" class="button">

And here's the CSS for the button class:

.button {
    float: top;
    width: 275px;
    height: 40px;
    margin-top: 6px;
    display: inline-block;
    font-family: Impact;
    text-align: center;
    -webkit-transform: skewX(20deg);
    -moz-transform: skewX(20deg);
    -o-transform: skewX(20deg);
    transform: skewX(20deg);
}

Answer №1

Partly concurring with Sidharth, it seems unavoidable to use a wrapper element to apply the CSS-transform and then reset it for its child elements (the submit-input):

<div class="button-wrapper">
  <input type="submit" alt="submit" value="Login">
</div>

Sidharth's suggestion proposes hiding the original <input> element completely and relying on JavaScript to simulate a click when the styled wrapper is clicked. However, there is a simpler workaround: Style the button-wrapper on :hover and remove all styles from the nested <input> element, making it 100% wide (jsBin example):

.button-wrapper {
  background: #fff;
  border: 1px solid #bbb;
  border-color: #ddd #ccc #bbb;
  overflow: hidden;

  -webkit-transform: skewX(20deg);
  -moz-transform: skewX(20deg);
  -o-transform: skewX(20deg);
  transform: skewX(20deg);
}

.button-wrapper:hover {
  background: #efe;
  border-color: #090;
}

.button-wrapper input {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 20px;
  font-weight: bold;
  padding: 4px 0;
  margin: 0;
  width: 100%;

  -webkit-transform: skewX(-20deg);
  -moz-transform: skewX(-20deg);
  -o-transform: skewX(-20deg);
  transform: skewX(-20deg);
}

.button-wrapper input:hover {
  color: #060;
}

Answer №2

Even though years may have passed, I recently encountered the same issue and discovered that implementing a reverse skew on the text resolved the problem. Here is the snippet of code where I applied this solution:

.goldenBlock {
     background-color: rgba(255,215,0,0.85);
     padding: 5px;
     -webkit-transform: skew(15deg);
     transform: skew(15deg); 
}

.goldenBlock p {
    -webkit-transform: skew(-15deg);
    transform: skew(-15deg); 
}

Answer №3

To encapsulate the "button," establish a wrapper and insert the text within it. To ensure that the button is activated when the text is selected, javascript must be utilized to simulate a "click" event, as the click will not naturally reach the button otherwise.

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

Analyzing div tags using Nokogiri

There's a piece of code that effectively extracts tid and term data: (answered generously by Uri Agassi) for i in (1..10) doc = Nokogiri::HTML(open("http://somewebsite.com/#{i}/")) tids = doc.xpath("//div[contains(concat(' ', @class, ...

"Ajax has the ability to alter the vertical scroll position

I have a quick query for you. Can anyone assist me in understanding why the page scroll resets to the top after an Ajax request? I suspect it has something to do with JQuery. There isn't much information available online, so I'm reaching out for ...

Turn off browser feature that automatically adds overflow:hidden on touch screen devices

Encountering a problem with browsers (potentially Chrome) adding CSS rules on touch-enabled devices. In a website developed for a client (specifically for Chrome), the scroll bars disappear on elements when accessed from their ultrabooks. The client still ...

Creating a counter for a list using CSS

I am attempting to utilize the counter increment feature in CSS for my ordered list, but it doesn't seem to be functioning properly. Here is the desired format I want to achieve: 1. Acknowledgements 1.1 blah, blah .... 1.2 blah, blah .... 1 ...

The barely noticeable difference of 1 pixel in the link between Chrome and Firefox

Hello there, I need some advice on how to adjust a one-pixel difference between Chrome and Firefox. The menu links appear correctly in Chrome, but in Firefox, they are 1px smaller than they should be. Below is the CSS code: ul#menu { padding: 0 0 2px ...

Implementing jQuery selector for CSS and properly handling special characters in the code

I've been attempting to use jQuery to change the background color of a radio button. I provided the CSS code below, but even after escaping special characters in jQuery as shown below, the solution still isn't working. #opt5 > [type="radio"]: ...

Using jquery to remove textbox value when checkbox is unchecked

I have a single datatable created using jQuery. The first column of the table consists of checkboxes, and the last column contains textboxes. Because these elements are generated dynamically, they end up having identical IDs and names as shown below: $ ...

The issue I'm facing involves Materialize CSS interfering with the rendering of input fields from PrimeNG. Does anyone have a solution to resolve

The code I am working with is as follows: <div class="container" style="width:100%;"> <div class="ui-widget-header" style="padding:4px 10px;border-bottom: 0 none"> <i class="fa fa-search" style="margin:4px 4px 0 0"></i> < ...

How to upload a file with JavaScript without using Ajax technology

Is it possible to upload a file using the input tag with type='file' and save it in my project folder without using ajax? Can JavaScript help me achieve this task? Below is the code snippet I am currently working on: function func3() { var ...

I haven't quite reached success yet, but I am working on getting my slideshow to display on my local server

My homepage is fully loading, but the slideshow feature is not functioning correctly. I have a file called slide.js in my /lib directory that I am trying to integrate into my homepage. The images are referenced properly and working, but they are not displa ...

How can HTML text be displayed based on certain JavaScript conditions?

By modifying the style of the text, I was able to implement basic functionality for validating correct answers. However, my main query is whether it is feasible to display a specific phrase upon achieving a perfect score. Upon analyzing the provided sample ...

simultaneous image hover effect for all images

I am experiencing an issue with my CSS and Bootstrap hover effect. The overlay tags are enclosed within a div class, but they all hover simultaneously. Each overlay belongs to a different Bootstrap grid, yet the effect extends even to the empty spaces betw ...

Clicking on a radio button can trigger the selection of another radio button

I'm currently working on a form that includes 8 radio buttons - 4 for System A and 4 for System B. The options for the buttons are CF, ISO, ISO-B, and NW. My goal is to create a functionality where selecting a radio button in System A automatically se ...

How can I enable the "Open in a new tab" functionality while utilizing ng-click?

I've encountered an issue with my HTML table where each row is supposed to link to a different page, providing more detailed information. However, because I am using angularjs and utilizing ng-click on the rows, I am unable to right-click and select & ...

"Utilizing FileReader to seamlessly integrate data into FormData without the risk

Currently, I'm in the process of constructing an ajax file uploader. This is made possible thanks to the recently introduced FormData interface. Everything seems to work as expected when using the original file. However, I encounter issues when conver ...

"Displaying mongoose date in the HTML5 input type date format (dd/mm/yyyy) is a simple process that can

I have a structured data in MongoDB as shown below: var Person = new Schema({ "Name": { type: String, required: true }, "DOB": { type: Date, "default": Date.now } }); An instance of this schema is created using NodeJs with mongoose ODM: { "N ...

Trouble with PHP file uploads

Greetings! I am a developer coming from an ASP.NET background, new to PHP. Recently, I transitioned to PHP as I needed to create a website for a friend. However, I encountered a persistent error message while trying to upload music files to a specific fold ...

Css technique for changing color on mouse hover

I currently have a social media bar on my website with icons for Facebook, Twitter, Google+, and RSS. Here is how it looks: When I hover over the icons, I want the circle around the image to change color to blue. However, every attempt I've made end ...

I am looking to ensure that the ul li a() elements remain hidden until I hover over the h2 tag, at which point they will be displayed

Insert your code here : <table cellpadding="0" cellspacing="0" align="center" class="TblGreen"> <tr> <td> <h2><a href="#" class="AGreen">Sweater</a></h2> <p>The coding business</p> ...

How to handle unclickable buttons in Selenium testing

from selenium import webdriver from time import sleep from selenium.webdriver.common.by import By chrome_options = webdriver.ChromeOptions() driver = webdriver.Chrome(r'chromedriver.exe', options=chrome_options) url = 'https://rarible.com/c ...