如何创建带有倾斜文本的div?

时间:2018-10-13 15:09:18

标签: html css

好的,我尝试了很多方法,想知道你们的想法。现在,我正在使用浮动控件来使它正常工作,但是这使我无法使用flexbox在右边的职位发布中设置样式。这是我要创建的内容:

enter image description here

到目前为止,这是我的CSS(底部的Codepen链接):

.home #slider .item {
    height: 560px;
    display: flex;
    align-items: center;
    color: #fff;
    font-size: 1rem;
    background-attachment: fixed;
    background-position: cover;
    box-shadow: inset 0 0 0 1000px rgba(170, 0, 0, 0.4);
}

.home #slider .item #sliderTextContainer {
    height: 560px;
    float: left;
    width: 70%;
    margin-top: 0;
    -webkit-shape-outside: polygon(0 0, 100% 0, 90% 100%, 0 100%);
    shape-outside: polygon(0 0, 100% 0, 90% 100%, 0 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
}

.home #slider .item #sliderText {
    width:60%;
    align-self: center;
}

.home #slider .item .slide_title {
    font-family: Montserrat;
    font-size: 2em;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.home #slider .item .slide_title span {
    font-size: 2.3em;
    line-height: 1;
    font-family: Montserrat;
    font-weight: 600;
    padding-left: 135px;
    background-image: url(../../pages/home/img/woosh.png);
    background-repeat: no-repeat;
    background-position: left center;
}

.home #slider .item .slide_body {
    font-size: 1.5em;
    font-weight: 100;
}

.home #slider .item .btn-lg {
    padding: 12px 30px;
}

.home #slider .item #sliderJobsContainer {
    padding-right: 25px;
    height: 560px;
    background-color: rgb(214,214,214);
    clip-path: polygon(69% 0, 100% 0%, 100% 100%, 62% 100%);
}

.home #slider .item #sliderJobs {
    color: black;
}

codepen

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

您可以使用linear-gradient()shape-outside属性来实现这种效果。

演示:

.content {
  display: flex;
  background: linear-gradient(95deg, rgba(139, 0, 0, 0.8) 60%, grey 60%), url(https://loremflickr.com/2400/768/truck) no-repeat 0 0 /cover;
  height: 560px;
}

.info {
  flex: 1;
}

.jobs {
  width: 40%;
}

.jobs .shape {
  width: 3em;
  height: 100%;
  float: left;
  shape-outside: polygon(0 0, 100% 0, 0 100%);
}

body {
  margin: 0;
}
<div class="content">
  <div class="info">
  </div>

  <div class="jobs">
    <div class="shape"></div>
    <div class="job">
      <h5>TITLE</h5>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla ipsa iusto eligendi eum libero ipsum, beatae debitis atque praesentium.</p>
    </div>

    <div class="job">
      <h5>TITLE</h5>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla ipsa iusto eligendi eum libero ipsum, beatae debitis atque praesentium.</p>
    </div>
  </div>
  
  <div style="clear: both;"></div>
</div>

答案 1 :(得分:0)

我最终使用了另一种方法,因为渐变在两个部分之间形成了锯齿状的线。同样,对所有内容使用一个容器将使我无法将背景图像固定在左侧。

代码如下:

    <div id="slider">
        <div id = "info">
            <div id="infoContainer">
            <p class="slide_title">
            Thinking the way<br /><span>Forward.</span>
            </p>
            <p class="slide_body">
            Palumbo Trucking of Connecticut is a rapidly growing family owned and operated transportation business, dedicated to offering reliable customer service, pristine equipment and highly trained and qualified drivers.
            </p>
            <a class="btn btn-dark btn-lg" href="./?page=locations">GET A FREE QUOTE</a>  
            </div>  
        </div>

CSS:

<div id = "jobs">
              <a class = "job" href = "/?page=employment">
              <h5>CDL Class A Tractor Trailer Drivers</h5>
              <p>Must have 3 years experience and clean driving record.  Experience with pneumatic tanks a plus, training is available.</p>
              </a>

              <hr>

              <a class = "job" href = "/?page=employment">
              <h5>CDL Class A Dump Trailer Driver</h5>
              <p>3 years experience and clean driving record.</p>
              </a>

              <hr>

              <a class = "job" href = "/?page=employment">
              <h5>Rail Yard Transloader</h5>
              <p>Yard master needed for New Haven and Wallingford locations to transload material from rail cars into pneumatic tanks.  Monday through Saturday, 8-10 hours a day.</p>
              </a>

              <hr>

              <a class = "job" href = "/?page=employment">
              <h5>Fleet PM Service and Trailer Mechanic</h5>
              <p>Full time, various shifts available.</p>
              </a>
            </div>  
        </div>

CSS:

.home #slider {
    background: #aa0000;
    border-bottom: 5px solid #FECA0B;
}

#infoContainer {
    width:60%;
    align-self: center;
}

#info {
    background-image: url('../../pages/home/img/bg-big-head.png');
    height: 560px;
    width: 70%;
    display: flex;
    align-items: center;
    color: #fff;
    font-size: 1rem;
    background-attachment: fixed;
    background-position: 0 80px;
    box-shadow: inset 0 0 0 1000px rgba(170, 0, 0, 0.4);
    float: left;
    -webkit-shape-outside: polygon(0 0, 100% 0, 90% 100%, 0 100%);
    shape-outside: polygon(0 0, 100% 0, 90% 100%, 0 100%);
    flex-direction: column;
    justify-content: center;
    text-align: center;
    -webkit-clip-path: polygon(0% 0%, 98% 0%, 85% 100%, 0% 100%);
    clip-path: polygon(0% 0%, 98% 0%, 85% 100%, 0% 100%);
}

.home #slider #info .slide_title {
    font-family: Montserrat;
    font-size: 2em;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.home #slider #info .slide_title span {
    font-size: 2.3em;
    line-height: 1;
    font-family: Montserrat;
    font-weight: 600;
    padding-left: 135px;
    background-image: url(../../pages/home/img/woosh.png);
    background-repeat: no-repeat;
    background-position: left center;
}

.home #slider #info .slide_body {
    font-size: 1.5em;
    font-weight: 100;
}

.home #slider #info .btn-lg {
    padding: 12px 30px;
}

#jobs {
    color: black;
    padding-top: 60px;
    padding-right: 45px;
    height: 560px;
    background-color: rgb(214,214,214);
}

.job {
    margin-top:40px;
    text-decoration: none;
    color: black;
    display: block;
}

.job:hover {
    text-decoration: none;
    color: black;
}

#jobs a h5 {
    font-family: Montserrat;
    font-weight: bold;
}

#jobs p {
    color: #727272;
    font-weight: 400;
}

#jobs hr {
    position: absolute;
    right: 50px;
    margin:0;
}

#jobs hr:nth-of-type(1) {
    width: 29%;
}

#jobs hr:nth-of-type(2) {
    width: 30%;
}

#jobs hr:nth-of-type(3) {
    width: 31%;
}

.job:nth-of-type(1)  {
    margin-top:0;  
}