试图创建带箭头的头,并呼吁采取行动

问题描述 投票:0回答:3

我几乎有拖网各种CSS网站和这一个之后,但也许需要一些专家的意见。

我试图创建一个节头的网站,有3个部分:

  1. 标题与按钮可能的工具提示
  2. 描述
  3. 号召性按钮

样机附后。

我试图调整箭头宽度所以它不是那么“尖尖”,因为它占用的下一个区域的额外空间。

Mockup

我至今是:

* {
  box-sizing: border-box;
}

#RPheader {
  float: left;
  position: relative;
  width: 40%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background: #004851;
}

#RPheader:after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
}

#RPheader:before {
  content: "";
  position: absolute;
  right: -20px;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 20px solid #004851;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  z-index: 1;
}

#RPdesc {
  float: left;
  position: relative;
  width: 50%;
  padding: 10px;
  height: 40px;
  color: #555555;
  background-color: #F1ECEA;
}

#RPdesc:after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
}

#RPdesc:before {
  content: "";
  position: absolute;
  right: -20px;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 20px solid #F1ECEA;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
}

#RPheaderButton {
  float: left;
  width: 10%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background-color: #00afd7;
}
<div id="RPheaderRow">
  <div id="RPheader">Header title here</div>
  <div id="RPdesc">This is where my description will go...</div>
  <div id="RPheaderButton"> CTA </div>
</div>

我没有做过提示部分尚未...我会尝试找出答案后,这是done..yikes!

任何帮助非常赞赏。

克里斯。

html css
3个回答
1
投票

你几乎没有,只是需要对border-left元素:before调整到10px值,然后改变right财产所有权以及对-10px。我也更新了RPDesc元素和RPheaderButton元素上的左右填充。

https://jsfiddle.net/disinfor/evy952bc/10/

* {
  box-sizing: border-box;
}

#RPheader {
  float: left;
  position: relative;
  width: 40%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background: #004851;
}

#RPheader:after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
}

#RPheader:before {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 5px solid #004851;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  z-index: 1;
}

#RPdesc {
  float: left;
  position: relative;
  width: 50%;
  padding: 10px 20px;
  height: 40px;
  color: #555555;
  background-color: #F1ECEA;
}

#RPdesc:after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
}

#RPdesc:before {
  content: "";
  position: absolute;
  right: -10px;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 10px solid #F1ECEA;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
}

#RPheaderButton {
  float: left;
  width: 10%;
  padding: 10px 10px 10px 20px;
  height: 40px;
  color: #FFFFFF;
  background-color: #00afd7;
}
<div id="RPheaderRow">
  <div id="RPheader">Header title here</div>
  <div id="RPdesc">This is where my description will go...</div>
  <div id="RPheaderButton"> CTA </div>
</div>

您可以根据需要调整这两个值,但将让你更接近你想要什么。


1
投票

你可以考虑后台,无需伪元素很容易实现这一点:

* {
  box-sizing: border-box;
}

#RPheader {
  float: left;
  width: 40%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background: 
    linear-gradient(to top right   ,transparent 49.8%,#F1ECEA 50%) top   right/20px 50%,
    linear-gradient(to bottom right,transparent 49.8%,#F1ECEA 50%) bottom right/20px 50%,
    #004851;
  background-repeat:no-repeat;
}



#RPdesc {
  float: left;
  width: 50%;
  padding: 10px;
  height: 40px;
  color: #555555;
  background:
    linear-gradient(to top right   ,transparent 49.8%,#00afd7 50%) top   right/20px 50%,
    linear-gradient(to bottom right,transparent 49.8%,#00afd7 50%) bottom right/20px 50%,
   #F1ECEA;
  background-repeat:no-repeat;
}
#RPheaderButton {
  float: left;
  width: 10%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background-color: #00afd7;
}
<div id="RPheaderRow">
  <div id="RPheader">Header title here</div>
  <div id="RPdesc">This is where my description will go ...</div>
  <div id="RPheaderButton"> CTA </div>
</div>

您还可以优化如下面的代码:

* {
  box-sizing: border-box;
}
#RPheaderRow > div {
 float: left;
  padding: 10px;
  height: 40px;
  color:#fff;
  background: 
    linear-gradient(to top right   ,transparent 49.5%,var(--c,transparent) 50%) top    right/var(--s,20px) 50%,
    linear-gradient(to bottom right,transparent 49.5%,var(--c,transparent) 50%) bottom right/var(--s,20px) 50%;
  background-repeat:no-repeat;
}

div#RPheader { 
  width: 40%;
  --c:#F1ECEA; /*adjust the color*/
  background-color:#004851;
}
div#RPdesc {
  width: 50%;
  color: #555555;
  --c:#00afd7;
  --s:10px; /*adjust the size of the arrow*/
  background-color:#F1ECEA;
}
div#RPheaderButton {
  width: 10%;
  background-color: #00afd7;
}
<div id="RPheaderRow">
  <div id="RPheader" >Header title here</div>
  <div id="RPdesc" >This is where my description will go ...</div>
  <div id="RPheaderButton" > CTA </div>
</div>

0
投票

我将在部分中添加箭头顶部和底部箭头前模拟这个AROW你正在试图获得。

* {
  box-sizing: border-box;
}

#RPheader {
  float: left;
  position: relative;
  width: 40%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background: #004851;
}

#RPheader:after {
  content: "";
  position: absolute;
  right: -20px;
  bottom: 0;
  width: 0;
  height: 0;
  border-bottom: 20px solid #F1ECEA;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
}

#RPheader:before {
  content: "";
  position: absolute;
  right: -20px;
  top: 0;
  width: 0;
  height: 0;
  border-top: 20px solid #F1ECEA;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
}

#RPdesc {
  float: left;
  position: relative;
  width: 50%;
  padding: 10px;
  height: 40px;
  color: #555555;
  background-color: #F1ECEA;
}

#RPdesc:after {
  content: "";
  position: absolute;
  right: -20px;
  bottom: 0;
  width: 0;
  height: 0;
  border-bottom: 20px solid #00afd7;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
}

#RPdesc:before {
  content: "";
  position: absolute;
  right: -20px;
  top: 0;
  width: 0;
  height: 0;
  border-top: 20px solid #00afd7;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
}

#RPheaderButton {
  float: left;
  width: 10%;
  padding: 10px;
  height: 40px;
  color: #FFFFFF;
  background-color: #00afd7;
}
<div id="RPheaderRow">
  <div id="RPheader">Header title here</div>
  <div id="RPdesc">This is where my description will go...</div>
  <div id="RPheaderButton"> CTA </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.