css将对角线粘到另一个元素上

时间:2017-01-10 16:23:58

标签: javascript jquery html css

晚上好。 已经有一天我试图解决以下问题。我非常希望得到你的帮助。

enter image description here

有一条对角线,应粘贴在文本上,文本以块为中心。 网站自适应。在vh / vw和静态定位中展示的尺寸不合适。如何将一个元素“粘贴”到另一个元素?

是否有任何CSS或jQuery方法来实现此任务。 我的代码如下。

app.directive("productCount", ['ProductService', function(productService) {
  let render = function(count) {
    count = count || productService.getProductCount();
    return "<span>" + count + "</span>";
  }
  return {
    restrict: 'E',      
    template: function(elem, attr) {
      return render();
    },
    link: function($scope, elem, attrs) {
      $scope.$on(productService.PRODUCT_COUNT_DELTA, function($event, productCount) {
        elem.html(render(productCount));
      });
    }
  }
}]);
span.line {
  position: absolute;
  top: 0;
  width: 100%;
}
span.line:after {
  content: '';
  width: 1000px;
  height: 90vh;
  background-color: #fff;
  position: absolute;
  z-index: 1;
  top: 0;
  -moz-transform: rotate(45deg) translate(-96%, 28%);
  -webkit-transform: rotate(45deg) translate(-96%, 28%);
  -o-transform: rotate(45deg) translate(-96%, 28%);
  -ms-transform: rotate(45deg) translate(-96%, 28%);
  transform: rotate(45deg) translate(-100%, -5%);
  left: 25%;
  margin-left: 0;
  border-right: 1px solid #000;
  -webkit-transform-origin: 0% 0%;
  transform-origin: 0% 0%;
}
span.line:before {
  content: '';
  width: 10px;
  height: 10vh;
  background-color: transparent;
  position: absolute;
  z-index: 1;
  top: 0;
  -moz-transform: rotate(45deg) translate(-25%, -10%);
  -webkit-transform: rotate(45deg) translate(-25%, -10%);
  -o-transform: rotate(45deg) translate(-25%, -10%);
  -ms-transform: rotate(45deg) translate(-25%, -10%);
  transform: rotate(45deg) translate(0%, -25%);
  left: 21%;
  border-right: 1px solid #000;
}

.hello-block .content-block .wrap-header-block {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 15vh;
  position: relative;
  overflow: hidden;
}

.hello-block .content-block .wrap-header-block .page-title {
  overflow: hidden;
  padding: 24vh 0;
  padding-right: 10%;
  text-align: center;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap {
  display: inline-block;
  text-align: left;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap h1 {
  margin: 0;
  text-transform: uppercase;
  display: inline-block;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap h1 span.line:after {
  left: 24%;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap h1 span.line:before {
  left: 20%;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap .wrap-inner {
  position: absolute;
  margin-left: -10%;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap .wrap-inner h2 {
  text-transform: uppercase;
  font-size: 2rem;
  margin: 0 auto;
  line-height: 1;
  max-width: 450px;
  text-align: left;
  margin-bottom: 10px;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap .wrap-inner h2:before {
  content: '';
  width: 0;
  height: 0;
  border-top: 60px solid transparent;
  border-right: 60px solid transparent;
  float: left;
  shape-outside: polygon(100% 0, 0 0, 0 100%);
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap .wrap-inner .button {
  z-index: 150;
  position: relative;
  display: inline-block;
  clear: both;
  margin-left: -5%;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap .wrap-inner .button a {
  display: inline-block;
  color: #fff;
  padding: 5px 35px;
  font-size: 16px;
  font-style: italic;
  z-index: 100;
  text-decoration: none;
}

.hello-block .content-block .wrap-header-block .page-title .title-wrap .wrap-inner .button a:before {
  content: '';
  background-color: #31e0d2;
  transform: skew(-45deg, 0deg);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
}

0 个答案:

没有答案