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:

https://i.sstatic.net/0vqlk.png

However, my current implementation looks like this:

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

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%);
}

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

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

Styling a specific element in Svelte without needing a globally unique identifier

How can I target just the outer div using a css selector? <div> <div>...</div> <div>...</div> </div> <style> OUTER.DIV.ONLY { background: url(outer.png); } </style> Alternatively, I& ...

Loading CSS files conditionally in Angular2's index.html

Currently, my index.html page features a dark theme: <base href="/"> <html> <head> <title>XXX</title> </head> <body> <link rel="stylesheet" type="text/css" href="assets/dark_room.css"> <my-app ...

iOS exhibits a flashy display of Material Select lighting up

In my attempt to develop a website using Material Design, I encountered an issue with the Material Select component. Whether I utilize MDB (Material Design for Bootstrap) or the Materialize CSS framework, both function well on Windows/OSX/Android devices. ...

In Vue.js2, you can easily compare two arrays of objects that have the same values and then make changes or add properties from one array to the other

I am working with an array of objects fetched from an API (), which is linked to a variable that serves as the v-model for an input. Whenever the variable changes, so does the array through a function that triggers the API call on @keyup. The structure of ...

Learn how to retrieve an array within an object by clicking on a specific button

Currently, I am in the process of creating a filter and its corresponding labels. The objective is to allow users to select from various options when they click on the first row. While I have successfully implemented the functionality to display choices fo ...

Limit text to two lines inside a cell in a table

Apologies for not providing any evidence of my own efforts. I'm looking to wrap text in a table cell, but limit it to just 2 lines. Expanding the width is not possible. Any suggestions on how to achieve this? ...

Identify and target a particular DIV based on the URL for customization

My webpage has a collection of frequently asked questions (FAQs) on a page called faq.html. Here is an example structure: <div id="faq1">...</div> <div id="faq2">...</div> I am looking to create a pulsating or highlighting effect ...

Error code TS7053 occurs when an element implicitly has an 'any' type because a string expression cannot be used to index an empty object

I have implemented a code snippet that sorts items into groups based on their first character. For example, if the array of item looks like this: {name: 'Foo'} {name: 'Bar'} {name: 'Baz'} The expected result should be: B: ...

Tips for utilizing JavaScript getElementByClassName to retrieve all the elements within a ul without having to specify the class name in each li

Looking to tidy up my HTML/CSS. Is there a way to keep this JavaScript functioning without needing to add the class name to every li element within the ul? Any suggestions on how to improve the visual appeal and readability of the HTML code? const Profi ...

The VueJS Chosen directive fails to refresh when new options are selected

Struggling to populate my jQuery Chosen dropdown field with AJAX data using VueJS. Unfortunately, when trying to update the values, the Chosen dropdown does not reflect the changes. I've experimented with different approaches, including manually trig ...

Modifying SASS variable within an Angular 2 TypeScript project

How can I update the Sass color variable based on user input in Angular 2? I came across a helpful resource, but it doesn't include any examples specifically for Angular 2. Any assistance would be greatly appreciated. Thank you! ...

Tips for resolving a lack of 'Access-Control-Allow-Origin' header on the requested resource issue

Currently, I am utilizing Vue.js for the frontend and Laravel for the backend of my project. My goal is to access an API endpoint by using "". However, when attempting to connect to this API, I encounter an error within my browser as shown below: https://i ...

Singling out a particular navigation tab

When attempting to link specific table IDs so that the corresponding tab is active when opened (i.e. www.gohome.com/html#profile), I am facing an issue where the active tab remains unchanged. Even after specifically calling out tab IDs, there seems to be n ...

Struggling to see the Vuetify 'v-select' component on the screen

Welcome to my personal website <template> <v-form> <v-select outlined label="Select a segment from the AI/ML model" :items="options"> </v-select> <v-text-field label="Enter User ID" required>&l ...

Step-by-step guide for inputting information into a designated user profile

Having recently started working with Firebase and Vue.js, I encountered an issue on how to include symptoms in the user collection based on their ID. Check out how it looks in the Firebase User collection here. This is the user interface where users can s ...

Keeping the header fixed on a sticky div (tocbot)

While working on my website, I decided to implement a Table of Contents section using tocbot. However, I encountered an issue where the Title I added above the table doesn't stay fixed when scrolling. https://i.stack.imgur.com/vCm1K.gif Here's ...

Switch the navbar background color from see-through to black

On my website, I have set up a navbar navigation that transitions between a transparent background and a black background as the user scrolls down. However, I would like the black background to be present at all times for the navbar. I built the website us ...

Increasing the size of the .ui-btn-left component

Seeking advice on a Javascript query that I can't seem to resolve online. As a beginner in Javascript, I'm struggling with what seems like a simple issue. My dilemma lies in enlarging the close button on a jQuery page. .ui-dialog .ui-header .ui- ...

Position on the chart in the Highcharts

I have developed 2 highcharts in the code below: <div> <p id="container"> </p> <p id="cont"> </p> </div> I specified the width and height as follows: $('#cont').highcharts({ char ...

Basic color scheme

I'm attempting to change the background color behind a partially transparent .png div. The CSS class that modifies the div is ".alert". Manually editing the .alert class background color works perfectly, and now I want to automate this on a 1-second c ...