Embedding a picture within a uniquely shaped container

I have multiple sets of skewed divs and I would like to include a separate image in each of them. However, when I attempt to insert an image, it also becomes skewed and distorted. Is there a way to prevent this from happening? Ideally, I want the images to be displayed in the black-colored area. Thank you in advance for your assistance!

.wrap {
  position: relative;
  width: 95vw;
  height: 20vw;
  margin-right: auto;
  margin-left: auto;
  background: white;
  overflow: hidden;
}
.button-skewed .button {
  width: 98%;
  height: 100%;
  background: black;
  display: inline-block;
  text-align: center;
  box-shadow: inset 0 0 0 1vw #008080, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button:hover ~ span {
  background: #007a7a !important;
}
.button-skewed .button:hover ~ span:before {
  background: #007a7a !important;
}
.button-skewed .button:hover {
  background: #007a7a;
  box-shadow: inset 0 0 0 1vw #007a7a, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button.left {
  margin-left: -1.7vw;
  position: absolute;
  left: 0%;
  transform: skewX(-20deg) translate(-50%, -50%);
  top: 50%;
}

.button-skewed .button.right {
  margin-right: 1.7vw;
  width: 200%;
  position: absolute;
  transform: skewX(-20deg) translate(100%, -50%);
  top: 50%;
  right: 50%;
}
.button-skewed .button .titleleft {
  position: absolute;
  top: 50%;
  left: 71%;
  transform: skewX(20deg) translate(-50%, -50%);
  display: inline-block;
  font-family: montserrat;
  color: white;
  font-size: 2.6vw;
  text-shadow: 2px 2px 5px #000;
}

.button-skewed .button .titleright {
  position: absolute;
  top: 50%;
  left: 12%;
  transform: skewX(20deg) translate(-50%, -50%);
  display: inline-block;
  font-family: montserrat;
  color: white;
  font-size: 2.6vw;

.button-skewed img {
   position: relative;
  background-size: cover;
}

.mask-outer-left {
  position: absolute;
  left: 0;
  top: 0;
  height: calc(100% - 2vw);
  margin-top: 1vw;
  margin-bottom: 1vw;
}
.mask-outer-left:before {
  content: '';
  background: white;
  position: absolute;
  height: 200%;
  width: 100%;
  top: 50%;
  left: 49%;
  transform: translate(-50%, -50%);
}
.mask-outer-right {
  position: absolute;
  right: 0;
  top: 0;
  height: calc(100% - 2vw);
  margin-top: 1vw;
  margin-bottom: 1vw;
}
.mask-outer-right:before {
  content: '';
  background: white;
  position: absolute;
  height: 200%;
  width: 100%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
<div class="wrap">
  <div class="button-skewed"><a class="button left" href="#"><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>
<br>
<div class="wrap">
  <div class="button-skewed"><a class="button left" href="#"><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>

Answer №1

If you want to achieve a skewed effect, you can add a second CSS class that skews the element in the opposite direction. Here is a possible solution:

.button-skewed .button img {
  transform: skewX(20deg)
}

.wrap {
  position: relative;
  width: 95vw;
  height: 20vw;
  margin-right: auto;
  margin-left: auto;
  background: white;
  overflow: hidden;
}
.button-skewed .button {
  width: 98%;
  height: 100%;
  background: black;
  display: inline-block;
  text-align: center;
  box-shadow: inset 0 0 0 1vw #008080, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button:hover ~ span {
  background: #007a7a !important;
}
.button-skewed .button:hover ~ span:before {
  background: #007a7a !important;
}
.button-skewed .button:hover {
  background: #007a7a;
  box-shadow: inset 0 0 0 1vw #007a7a, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button.left {
  margin-left: -1.7vw;
  position: absolute;
  left: 0%;
  transform: skewX(-20deg) translate(-50%, -50%);
  top: 50%;
}

.button-skewed .button.right {
  margin-right: 1.7vw;
  width: 200%;
  position: absolute;
  transform: skewX(-20deg) translate(100%, -50%);
  top: 50%;
  right: 50%;
}
.button-skewed .button .titleleft {
  position: absolute;
  top: 50%;
  left: 71%;
  transform: skewX(20deg) translate(-50%, -50%);
  display: inline-block;
  font-family: montserrat;
  color: white;
  font-size: 2.6vw;
  text-shadow: 2px 2px 5px #000;
}

.button-skewed .button .titleright {
  position: absolute;
  top: 50%;
  left: 12%;
  transform: skewX(20deg) translate(-50%, -50%);
  display: inline-block;
  font-family: montserrat;
  color: white;
  font-size: 2.6vw;
  text-shadow: 2px 2px 5px #000;
}

.button-skewed img {
  position: relative;
  background-size: cover;
}

.mask-outer-left {
  position: absolute;
  left: 0;
  top: 0;
  height: calc(100% - 2vw);
  margin-top: 1vw;
  margin-bottom: 1vw;
}
.mask-outer-left:before {
  content: '';
  background: white;
  position: absolute;
  height: 200%;
  width: 100%;
  top: 50%;
  left: 49%;
  transform: translate(-50%, -50%);
}
.mask-outer-right {
  position: absolute;
  right: 0;
  top: 0;
  height: calc(100% - 2vw);
  margin-top: 1vw;
  margin-bottom: 1vw;
}
.mask-outer-right:before {
  content: '';
  background: white;
  position: absolute;
  height: 200%;
  width: 100%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.button-skewed .button img {
  transform: skewX(20deg)
}
<div class="wrap">
  <div class="button-skewed"><a class="button left" href="#"><img src="https://fxfactory.com/downloads/docs/noiseindustries/fxfactorypro/Thumbnails/Stripes.jpg"/><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>
<br>
<div class="wrap">
  <div class="button-skewed"><a class="button left" href="#"><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</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

Join together a pair of php variables

I am currently extracting text and color values from a form structured like this: Here are the codes in management.php: <form method="post" action=""> <input type="color" name="color"> <input type="text" name="text"> <input ...

When is the appropriate time to nest CSS class selectors within other class selector definitions?

REVISED 1 After receiving feedback, I made the following changes: .lower-container { justify-content: center; position: absolute; width: 92vw; // height: 46vh; <--- no set height /* nested classes for adjusting position and height of low ...

Incorporating OTP verification into the registration process

I'm struggling with incorporating the "send OTP" feature into my registration form. I received an API from an SMS provider, but I'm unsure how to integrate it into my form. After verifying the OTP, I need the user's data to be stored in my d ...

Aligning image vertically

I'm working on aligning an image vertically in my header. Currently, it's horizontally centered. header { background-color: blue; height: 118px; width: 1024px; text-align: center; } .container { margin-left: auto; margin-right: aut ...

What steps do I need to take in order to show the present value using a range input?

Hey there! I'm working on a code in HTML that includes an input of type range. Here's what it looks like: This is my input: <input type="range" min="1" max="100" value="50" class="slider" id="myRange"> Unfortunately, I'm unable to s ...

What are some ways to eliminate the excess white space beneath the footer in HTML?

After creating a responsive webpage that works flawlessly on mobile devices and tablets, I noticed a problem with the footer when viewed on desktop. There is an empty white space at the end of the webpage, and upon inspecting the browser, it focuses on the ...

AngularJS Material Design sticky header MD table container

I am looking to create a table container to display records with a unique requirement - when the table reaches the top of the screen, its header should stick in place. Can you provide guidance on how to implement this feature? For reference, please check ...

Adding a half circle connector in HTML can be accomplished by using SVG (Scal

My task is to replicate the construction shown in this image: https://i.sstatic.net/kaRMO.png I have written the entire code but I am unsure how to include a half circle next to the full circle and connect it with a line connector. Here is my code: .ps- ...

parsing objects within an HTML component in Angular

Is there a way to utilize an object as the @input parameter in HTML? For example: <app-home [param]="user.salary"></app-home> However, the type of my user object is structured like this: user:Person=new Employee(); The classes invol ...

Incorrect height of div on iPhone 6 and 7 is observed when utilizing flexbox and setting the height to 100% dimensions

I'm experiencing an issue with the display on iOS devices, specifically iPhone 6 and 7. I am creating a news card layout where I set the content height to 100%. However, on these specific iPhone models, the height is being displayed incorrectly (as se ...

What could be causing the malfunction of my navbar and carousel functionality?

I am currently facing some challenges with the carousel in my HTML code. I am unable to get it to display images properly. Additionally, there is an issue with the background color of my navigation bar - it doesn't stay at 100% width. Also, when using ...

Internet Explorer 11 fails to interpret the attribute attr.xlink:href

I am a beginner in Angular 2 and I'm working on creating an icon component. The code I have below works perfectly in Chrome and Firefox, but unfortunately, it's not functioning in Internet Explorer 11. Here is what my component looks like: @Com ...

Is it possible to resume CSS animation when the page is first loaded?

I'm looking for a way to ensure that my CSS animations on the elements in my header.php file continue smoothly when navigating to different pages. For example, if I have a 200-second looped animation and navigate to the "about us" page 80 seconds int ...

Creating a customized notification icon featuring a count of notifications

I am trying to add a notification icon to my website similar to Facebook. On Facebook, the notification icon is displayed in the top left corner with a number indicating the total notifications. I would like to replicate this feature on my site as well. Be ...

The use of the display property with inline-block is not functioning correctly on mobile devices

Can anyone help me figure out why my divs are displaying differently on PC versus phone? They line up well on the computer, but on the phone, the last div is on a new line. Here is a snippet of my code and screenshots for reference. Thank you in advance fo ...

Sticky full-height slider with horizontal scrolling

I've been working on creating a horizontal slider animation that smoothly scrolls, inspired by the one showcased on The slider on weltio remains sticky as you scroll, showcasing images and content within. On my page, I have a lot of content and my g ...

Creating a dynamic element in real-time with CSS

I need help with a styling issue involving multiple spans enclosed in a center tag. I want each span to enlarge when hovered over by a user, but the problem is that when I increase the size of one span, it pushes aside all the other elements and disrupts t ...

Can you show me how to recreate a 502 gateway timeout error?

Looking for suggestions on how to create a page that exceeds 600 seconds to load? Any tips on triggering a 502 gateway timeout error would be helpful as well. ...

Is Bootstrap revolutionizing the world of flex-box layouts?

I'm currently in the process of creating a Simon game, and everything is going smoothly until I introduce Bootstrap into the mix. Suddenly, my "Simon board" starts acting strangely. Here's the troublesome code: HTML: <div class="simon"> ...

Challenges with z-index in Chrome/Safari and Firefox when nesting elements

In the current setup, it seems that .second needs to be positioned above .third, which is only happening in Firefox. Unfortunately, I am facing difficulty as I cannot separate .second from .fifth. Just to provide some context: .third is intended to act as ...