0
votes

I want to skew a div in CSS. I've been finally been able to do it (beginner), BUT, if I add a background-image to it, the image will also skew. the image needs to stay straight.
Can you please help me?

Thank you

*{
    padding: 0;
    margin: 0;
}
body{
    background-color: #EFEFEF;
}
.fullwidth {
    width: 100%;
    height: auto;
    position: fixed;
}

.mid-container {
    width: 1150px;
    padding: 75px 0px;
}

.top_image {
    width: 50%;
    height: 800px;
    background-image:url(https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg);
    border-bottom-right-radius: 38px;
    transform: skew(14deg, -13deg) ;
    -webkit-transform: skew(14deg, -13deg) ;
    -moz-transform: skew(14deg, -13deg) ;
    -o-transform: skew(14deg, -13deg) ;
    -ms-transform: skew(14deg, -13deg) ;
    margin: -120px 0 0 -101px;

}
.nav{
    width: 88%;
    height: auto;
    padding: 40px 0px;
    background-color: #ffffff;
    margin: 0 auto;
}
.stroke {
    width: 80%;
    height: 5px;
    background-color: #000000;
    margin: 0 auto;
    opacity: 0.35;
    
}
<!DOCTYPE html>
<html>
<head>
    <title>Hakan Topac</title>
    <meta charset="utf-8"/>
    <link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
      <div class="top_image"></div>
</body>
</html>
2

2 Answers

0
votes

You will need to have the img in a separate element to do that.

* {
  padding: 0;
  margin: 0;
}
body {
  background-color: #EFEFEF;
}
.fullwidth {
  width: 100%;
  height: auto;
  position: fixed;
}
.mid-container {
  width: 1150px;
  padding: 75px 0px;
}
.top_image {
  width: 50%;
  height: 800px;
  border-bottom-right-radius: 38px;
  transform: skew(14deg, -13deg);
  -webkit-transform: skew(14deg, -13deg);
  -moz-transform: skew(14deg, -13deg);
  -o-transform: skew(14deg, -13deg);
  -ms-transform: skew(14deg, -13deg);
  margin: -120px 0 0 -101px;
}
.h {
  background-image: url(https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg);
  display: inline-block;
  width: 100%;
  height: 100%;
  border-bottom-right-radius: 38px;
  transform: skew(-14deg, 13deg);
  -webkit-transform: skew(-14deg, 13deg);
  -moz-transform: skew(-14deg, 13deg);
  -o-transform: skew(-14deg, 13deg);
  -ms-transform: skew(-14deg, 13deg);
}
.nav {
  width: 88%;
  height: auto;
  padding: 40px 0px;
  background-color: #ffffff;
  margin: 0 auto;
}
.stroke {
  width: 80%;
  height: 5px;
  background-color: #000000;
  margin: 0 auto;
  opacity: 0.35;
}
<!DOCTYPE html>
<html>

<head>
  <title>Hakan Topac</title>
  <meta charset="utf-8" />
  <link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <div class="top_image"><span class="h"></span>
  </div>
</body>

</html>
-1
votes

you give the background under z-index:2; like that it stay underthe cild

I did it cover but you do like you need it

*{
    padding: 0;
    margin: 0;
}
body{
    background-color: #EFEFEF;
}
.under{
  background-image:url(https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg);
  background-size:cover;
  height:100%;
  width:100%;
  z-index:2;
}
.fullwidth {
    width: 100%;
    height: auto;
    position: fixed;
}

.mid-container {
    width: 1150px;
    padding: 75px 0px;
}

.top_image {
    width: 50%;
    height: 800px;
    background-image:url(https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg);
    border-bottom-right-radius: 38px;
    transform: skew(14deg, -13deg) ;
    -webkit-transform: skew(14deg, -13deg) ;
    -moz-transform: skew(14deg, -13deg) ;
    -o-transform: skew(14deg, -13deg) ;
    -ms-transform: skew(14deg, -13deg) ;
    margin: -120px 0 0 -101px;

}
.nav{
    width: 88%;
    height: auto;
    padding: 40px 0px;
    background-color: #ffffff;
    margin: 0 auto;
}
.stroke {
    width: 80%;
    height: 5px;
    background-color: #000000;
    margin: 0 auto;
    opacity: 0.35;
    
}
<body>
  <div class="under">
      <div class="top_image"></div>
  </div>        
</body>