Creating a Rectangular Trapezoid Shape with CSS - Eliminating Unnecessary Spacing

I'm trying to create a trapezoid button using CSS.

Here is the intended look:

However, my current implementation looks like this:

The button appears fine but there seems to be some excess space below it. It's almost like an unwanted margin, even though I haven't added any margin in the code.

My button code snippet is as follows:

<template>
  <div class="trapezoid">
    <button :form="form" :type="props.type">{{ props.text }}</button>
  </div>
</template>

<script setup>
...
</script>

<style>
button {
  width: 220px;
  height: 50px;
  font-size: 20px;
  background-color: $colorPrimary;
  text-transform: uppercase;
  color: $colorTextSecondary;
  font-weight: 500;
}

.trapezoid {
  height: 120px;
  clip-path: polygon(0 0, 100% 0, 84% 41%, 16% 41%);
}
</style>

When I decrease the height of the trapezoid class, the extra space diminishes. However, this adjustment causes the text to become invisible...

.trapezoid {
  height: 60px; // adjusted from 120px
  clip-path: polygon(0 0, 100% 0, 84% 41%, 16% 41%);
}

Answer №1

Adjust the dimensions and update the 41% to 100%

button {
  width: 100%;
  height: 50px;
  font-size: 20px;
  background-color: red;
  text-transform: uppercase;
  border: none;
  font-weight: 500;
}

.trapezoid {
  width: 220px;
  clip-path: polygon(0 0, 100% 0, 84% 100%, 16% 100%);
}
<div class="trapezoid">
  <button :form="form" :type="props.type">text</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

endless update cycle in Vue

I'm currently working on developing a custom component. And I have an idea of how I want to use it: let app = new Vue({ el:'#app', template:` <tab> <tab-item name='1'> <h1> This is tab item 1& ...

How can I modify the appearance of a slider's range?

I'm struggling with customizing the style of a price slider input range. No matter what I do, the changes don't seem to take effect. Can anyone pinpoint where I may be going wrong? Appreciate any guidance on this! Thank you! <div class=" ...

What is the best way to arrange list items in this manner?

I am facing challenges with aligning elements properly on the navigation bar. I would like the words (home, players, about, contact) to be vertically centered in relation to the heart logo. Here is how it currently appears: This is how I want it to look ...

"Delve into the art of utilizing negative space between elements with

Looking to implement hover detection between rows in a grid container, rather than on individual items. The number of items in the container and per row may vary. It's important to note that the item count in the container and rows is dynamic. The c ...

What is the best way to ensure my hover caption spans the entire size of the image?

I'm currently working on creating a hover caption that adjusts itself to fit the full width and height of an image even when it is resized. I attempted to implement a jQuery solution that I came across, but unfortunately, I am struggling to get it to ...

Making modifications to the CSS within an embedded iframe webpage

Assigned with the task of implementing a specific method on a SharePoint 2013 site. Let's dive in. Situation: - Within a page on a SharePoint 2013 site, there is a "content editor" web part that displays a page from the same domain/site collection. T ...

Trigger a Nuxt/Vuejs event upon completion of rendering all page components

Is there a way to trigger an event after all components on a page have finished rendering? I've attempted using the page mounted event, but it only fires the first time. I need an event to be triggered each time the route changes on the client side an ...

Avoid activating jQuery functions based on certain screen widths for menu/navigation system

Recently, I've delved into the world of jQuery and attempted to create a simple menu system. The menu is designed to expand its submenu when hovering over the list item at screen widths larger than 480px, and to expand when clicking on the list item a ...

Display a horizontal progression indicator during the page download process

Occasionally, website pages may take a while to download without the user even realizing it. This can be problematic if the user clicks on an image or button with an event handler attached, as it may break the page functionality. To address this issue, I ...

Is it possible for me to include additional fields in a vuetify calendar event?

Is there a method to incorporate additional fields, such as a description, in addition to the name and start/end time for an event on the v-calendar's day view? ...

Displaying Font Awesome icon within a loop in a Vue.js component

I am trying to display icons within a v-for loop. The data for the links and icons is stored in a JSON file. However, I am facing an issue when trying to use Font Awesome icons with Vue.js. When I include Font Awesome via CDN, everything works fine. But wh ...

Connect an attribute to an image source in pug using vue

In my component, I have created two props: 'iconSrc' for the image source that I want to keep and 'icon' as a boolean condition. The purpose is to only display the image if the condition is true. props: { iconSrc: { type: Stri ...

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 Datatable component does not display the data as expected when integrating it with Vue.js and fetching data from

Looking for a template on how to implement a Vue.js DataTable in an HTML page, fetching data from an API and including features like a search box and pagination. ...

Animating Elements with CSS and HTML

Struggling with my website project, specifically creating a login page. The issue arises when resizing the browser, causing elements to look misaligned and chaotic. Before: view image here After: view image here /* Bordered form */ form { margin-l ...

Ensuring the child div's height does not overflow beyond the parent div

When dealing with a parent div and a child div, both having different heights, how can I specifically retrieve the height of the portion of the child div that is within the boundaries of the parent div? Using document.getElementById("id").style.height prov ...

What is the best way to incorporate a gratitude note into a Modal Form while ensuring it is responsive?

Currently, I have successfully created a pop-up form, but there are two issues that need fixing. The form is not responsive. After filling/submission, the form redirects to a separate landing page for another fill out. Expected Outcome: Ideally, I would ...

Troubleshooting Issue with jQuery replaceWith in Loop

Trying to make it so that when the update button is clicked, the text on the left side becomes an input box: Click the update button and the text on the left will be an input box However, instead of just one input box appearing, all the text on the left s ...

Acquiring a value from a RefImpl using the Vue 3 composition API

When using the useGeolocation function from @vueuse/core in my code, I encountered an issue where it returned an Infinity value when trying to retrieve latitude and longitude coordinates. What could be causing this problem, and how can I ensure it returns ...

Jumbotron causes navigation bar to malfunction on mobile site

I'm experiencing an issue with Bootstrap Jumbotrons on my website - they extend beyond the container, causing the navbar on the mobile version to not fill the screen. This problem only occurs on pages with a jumbotron present. Attempting to use a Car ...