Css夹替代

时间:2018-03-25 23:02:55

标签: css

请参阅下面的代码段中的我的案例。我已经使用CSS clip属性来剪切按钮的左侧圆角部分,但是我read强烈推荐使用此属性。如何在没有剪辑的情况下做同样的事情?将输入框放在按钮顶部不会遮盖按钮的阴影。此外,由于浏览器支持不佳,clip-path也不是一种选择。

.container {
	position:relative;
	width:250px;
	height:30px;
	background-color:#e0e0e0;
	padding:10px;
}

.myButton {
	position:absolute;
	z-index:1;
	top:10px;
	left:165px;	
	box-shadow:0 2px 2px 0 #c0c0c0;
	border-radius:5px;
	border:1px solid #888;	
	font-weight:600;
	text-decoration:none !important;
	cursor:pointer;
	text-align:center;
	font-family:"Segoe UI", Arial, Helvetica, sans-serif;
	font-size:14px;
	line-height:18px;
	clip: rect(0px,100px,200px,5px);	
}

.myButton span {
	display:block;
	line-height:23px;
	height:23px;
	font-size:13px;
	padding:0 8px 0 12px	
}

.myButton {
	color:#fff;
	background:linear-gradient(to bottom,#79d1ff 0%, #389ee5 100%);	

}

.myButton:hover {
	background:linear-gradient(to bottom, #ec7ebf 0%,#d85da5 35%,#b5006c 70%,#b5006c 100%);
	color:#FFF	
}

.myInput {
	position:absolute;
	top:10px;
	width:166px;
	height:19px;
}
<div class="container">
  <input name="name" class="myInput" type="text" />
  <a href="javascript:;" class="myButton"><span>Submit</span></a>
</div>

1 个答案:

答案 0 :(得分:0)

简单地依靠一些带有负余量的溢出。以下是您的代码更新:

&#13;
&#13;
.container {
  position: relative;
  width: 250px;
  height: 30px;
  background-color: #e0e0e0;
  padding: 10px;
}

.myButton {
  position: absolute;
  z-index: 1;
  top: 5px;
  left: 165px;
  font-weight: 600;
  text-decoration: none !important;
  cursor: pointer;
  text-align: center;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 18px;
  overflow:hidden; /*Added This code */
  padding:5px 5px 5px 0;
}

.myButton span {
  display: block;
  box-shadow: 0 2px 2px 0 #c0c0c0;
  border-radius: 5px;
  border: 1px solid #888;
  line-height: 23px;
  height: 23px;
  font-size: 13px;
  padding: 0 8px 0 12px;
  color: #fff;
  background: linear-gradient(to bottom, #79d1ff 0%, #389ee5 100%);
  margin-left:-8px; /* Added this code*/
}

.myButton:hover span {
  background: linear-gradient(to bottom, #ec7ebf 0%, #d85da5 35%, #b5006c 70%, #b5006c 100%);
  color: #FFF
}

.myInput {
  position: absolute;
  top: 10px;
  width: 166px;
  height: 19px;
}
&#13;
<div class="container">
  <input name="name" class="myInput" type="text">
  <a class="myButton"><span>Submit</span></a>
</div>
&#13;
&#13;
&#13;