问题描述
如何用 css 创建这个
仅左边框线性渐变,其他3边正常边框,内容居中
解决方法
你可以使用伪元素来做到这一点
$myModel
public class SplashActivity extends Activity {
RelativeLayout splash;
Handler handler;
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
startActivity(new Intent(getApplicationContext(),LoginActivity.class));
finish();
return super.dispatchTouchEvent(ev);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashfile);
handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(getApplicationContext(),LoginActivity.class));
finish();
}
},10000);
/*splash=findViewById(R.id.splash);
splash.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view,MotionEvent motionEvent) {
startActivity(new Intent(getApplicationContext(),LoginActivity.class));
finish();
return true;
}
});*/
}
}
您还可以使用名为 border-image border-image 的属性,从文档中了解更多相关信息。
如果这没有帮助,请告诉我。
,改用 linear-gradient
背景。我不建议使用 border-image
,因为您不能将 border-radius 与它一起使用。
.box {
--left-border-size: 10px;
--border-size: 1px;
padding: 20px;
padding-left: calc(20px + var(--left-border-size));
width: 400px;
font-size: 1.2rem;
line-height: 1.5;
background: linear-gradient(to bottom,red,green,blue) 0 0/ var(--left-border-size) 100%,linear-gradient(#000,#000) 0 0 / 100% var(--border-size),#000) 0 100% / 100% var(--border-size),#000) 100% 0 / var(--border-size) 100%;
/* ↑ we're using backgrounds to create other borders too,because they should be appear under the left border */
background-repeat: no-repeat;
}
<div class="box">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt similique quo quisquam hic? In est enim sit voluptates tempore ducimus praesentium animi numquam veniam mollitia architecto,nulla accusantium sapiente quos!
</div>