Creating diagonal background cutouts using CSS

Can you create a diagonal cut in a background color using CSS?

Check out this example

https://i.sstatic.net/vtpYf.jpg

.item {
  color: #fff;
  font-size: 30px;
  background-color: #565453;
  padding: 10px 10px 10px 10px;
  width: 52%;
  text-align: center;
  display: inline-block;
}
<div class="item">New Music</div>

Answer №1

To create a gradient effect, utilize the linear-gradient property starting with transparent as the initial color-stop.

.item {
  color: #fff;
  font-size: 30px;
  background: linear-gradient(225deg, transparent 0, transparent 50px, #565453 0, #565453 100%);
  padding: 10px 10px 10px 10px;
  width: 52%;
  text-align: center;
  display: inline-block;
}
<div class="item">New Music</div>

Answer №2

If Fabrizios solution doesn't work for you, consider using the clip-path property to address your issue.

.item {
  color: #fff;
  font-size: 30px;
  background-color: #565453;
  padding: 10px 10px 10px 10px;
  width: 52%;
  text-align: center;
  display: inline-block;

  clip-path: polygon(0 0, calc(100% - 50px) 0, 100% 100%, 0% 100%);
}
<div class="item">New Music</div>

For more path options, try this helpful tool:

Answer №3

If you're looking to achieve the desired background color, you can utilize this code snippet:

#AboutUs {
  height: 30px;
  width: 400px;
  background: linear-gradient(45deg, #4C4C4C 90%, #E3E3E3 10%);
  padding: 5px;
  font-weight: bold;
  color: white;
  font-size: 20px;
}

#text {
  margin-left: 150px;
  height: 30px;
  width: 190px;
  font-weight: bold;
  font-size: 20px;
}
<div id="AboutUs">New Music

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

Achieving dynamic height in a parent div with a sticky header using mui-datatables

Here are the settings I've configured for my mui-datatables: const options = { responsive: "standard", pagination: false, tableBodyHeight: '80vh', }; return ( <MUIDataTable title={"ACME Employee ...

Include text for both the button label before and after a bootstrap toggle button

Is there a way to change the button label on a bootstrap toggle switch/button before and after clicking it without using jquery or javascript? It seems like there should be a feature in bootstrap for this. Initially, the label reads: Show list After clic ...

Tips for avoiding accidental unit conversion in jQuery

Imagine having the following code: var $element = $('<div/>'); $element.css("margin-left", "2cm"); console.log($element.css("margin-left")); When tested in Chrome, it doesn't return anything, but Firefox shows "75.5833px". Any sugges ...

Expanding to a full width of 100%, images on desktop screens are displayed larger than their original

I am facing a challenge with my three images lined up in a row, each with a width of 323px. In order to make my website responsive, I decided to switch from using width: 323px; to width: 100%;. While this adjustment worked well on mobile devices, I encoun ...

Unable to access account: HTML Javascript login issue

Problem with Login Code As a newcomer to HTML, CSS, and almost unknown in Javascript, I sought help from others to create a login code. The code was working fine earlier, but now it's not functioning as expected. Despite checking everything, I can&ap ...

Seeking a template for a server-side programmer who lacks proficiency in CSS and design?

Hey there all you wise folks! So here's the deal - I'm a PHP/JavaScript wizard when it comes to logic and server-side stuff, but I really suck at design, CSS, and all things arty. Does anyone have any recommendations for a template or tool that ...

Tips for customizing text field appearance in Safari and Chrome

I haven't had a chance to test it on IE yet. My goal is to create a unique style for the background image and text box shape, along with borders, for the search bar on my website, [dead site]. If you check it out on Firefox or Opera and see the sear ...

I am encountering a horizontal scroll bar despite setting the width to 100%

I am just starting out as a beginner in web development. I decided to create a webpage to practice my HTML and CSS skills. However, when I set the width of all elements to 100%, I noticed that I am getting a horizontal scroll bar. I have tried troubleshoot ...

Set the position of a div element to be fixed

I am currently working on a straightforward application that requires implementing a parallax effect. Here are the methods I have experimented with so far: - Inserting an image within a div with the class parallax. - Subsequently, adding an overlay div ...

What is the best way to keep a dropdown list menu next to the selected dropdown button as the user scrolls?

I recently encountered a problem similar to the one on this page within my App. Upon selecting the drop-down list, the corresponding menu opens as expected. However, when the user scrolls down the page, the drop-down menu remains in its original position. ...

Hiding elements in dark mode using `hidden` or `block` in Tailwind will not override its own hidden selector

To switch between dark and light mode for these two images, the dark:block selector does not override the hidden class. <div className="ml-5 content-center"> <img className="hidden dark:block h-6 w-auto my-1" src="/stati ...

My custom CSS being overridden by Bootstrap styles

I'm currently working with Twitter Bootstrap's CSS, but it seems to be overriding some of my custom classes. Initially, I placed it before my own CSS in the HTML header (I am using jade and stylus template engines): doctype html html head ...

Creating a dynamic dropdown menu using jQuery animation

I am looking to add animation to my top navigation bar. Currently, the dropdown menus just appear suddenly when hovering over the links in the top nav. Development site: I have attempted the following: <script> jQuery(document).ready(function() { ...

Arrange the child elements of a div to be displayed on top of one another in an HTML document

I am struggling with a div containing code .popupClass { width: 632px; height: 210px; position: absolute; bottom:0; margin-bottom: 60px; } <div class="popupClass"> <div style="margin-left: 90px; width: 184px; hei ...

Are there any methods to create a circular z-index?

Is there a way in CSS to arrange #element-one above #element-two, then #element-two above #element-three, and finally #element-three above #element-one? Are there alternative methods to achieve this layout? ...

Creating an interactive button using RichFaces and Bootstrap for seamless Ajax functionality

I have a challenge with making a fully clickable span or button that includes a Bootstrap refresh glyph-icon. The current code I have inherited only allows the icon itself to be clicked, leaving the area between the icon and button border unclickable. This ...

Is there a way to prevent one accordion pattern from automatically closing when another one is opened?

I'm currently working on a code that involves accordion patterns, and I've encountered an issue where opening and closing one accordion automatically closes another. I want all accordions to remain open until the user explicitly clicks to close t ...

children blocking clicks on their parents' divs

I previously asked a question about a parent div not responding to click events because its children were blocking it. Unfortunately, I couldn't recreate the issue without sharing a lot of code, which I didn't want to do. However, since I am stil ...

Adjust the space between spans by utilizing the margin

There are two spans (although there could be many more) on this web page that I need to adjust the distance between. I tried using the margin-bottom attribute, but it doesn't seem to have any effect. The spans remain in their original positions, which ...

Using z-index to position a paragraph element behind other elements in a webpage

I am facing a challenge where I want to hide a paragraph within an element, and layer it behind another element. Despite my attempts with z-index, I have been unsuccessful in achieving this effect between the elements. Could someone shed some light on why ...