Border的简单用法

Border 是一个装饰的控件,此控件绘制边框及背景,它有着几个重要的属性

  1. Background:用用一个 Brush 对象来绘制背景 ;
  2. BorderBrush:用一个Brush 对象来绘制边框 ;
  3. BorderThickness:此属性设置 Border 边框的大小;
  4. CornerRadius:此属性设置 Border 的每一个角圆的半径;
  5. Padding:此r属性设置 Border 里的内容与边框的之间的间隔

例子:
效果图
在这里插入图片描述
上图的border的背景用了图片画笔,边框用了渐变色,边框粗细设置了3,角弧度设置了5,
页面代码如下:


<Window x:Class="wpf实验.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/ 2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:wpf borber"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Border Height="200" Margin="156,59,164.4,61.8" BorderThickness="3" CornerRadius="5" >
<!—border的背景-->
<Border.Background>
                <ImageBrush>
                    <ImageBrush.ImageSource>
                        <BitmapImage UriSource="/imager\01.jpg"/>
                    </ImageBrush.ImageSource>
                </ImageBrush>
            </Border.Background>
            <!--边框的渐变色-->
            <Border.BorderBrush>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="Blue" Offset="0"/>
                    <GradientStop Color="Red" Offset="0.5"/>
                    <GradientStop Color="Black" Offset="0.8"/>
                </LinearGradientBrush>
            </Border.BorderBrush>
        </Border>
    </Grid>
</Window>
### CSS `border-radius` 属性的使用方法 #### 什么是 `border-radius` `border-radius` 是一种用于创建圆角边框的 CSS 属性。通过该属性可以轻松地使矩形元素具有圆形或椭圆形的边缘效果。 --- #### 基本语法 ```css border-radius: length | percentage; ``` - **length**: 表示固定长度单位(如 px、em 等),用来指定圆角的半径大小。 - **percentage**: 百分比值相对于父容器的尺寸计算,通常基于宽高比例来决定圆角弧度。 --- #### 单一值应用 当仅提供一个数值时,它会均匀作用于四个角落。 ```html <!DOCTYPE html> <html> <head> <style> div { border: 2px solid blue; padding: 10px; width: 200px; height: 100px; border-radius: 20px; /* 所有四角均为相同半径 */ } </style> </head> <body> <div></div> </body> </html> ``` 此代码片段展示了如何利用单一值设定统一的圆角效果[^3]。 --- #### 多重值组合 可以通过传递多个参数分别控制各个角度的不同曲率。 ```html <!DOCTYPE html> <html> <head> <style> div { border: 2px solid green; padding: 10px; width: 200px; height: 100px; border-radius: 10px 40px 10px 40px; /* 上左、上右、下右、下左依次赋值 */ } </style> </head> <body> <div></div> </body> </html> ``` 这里演示了按顺序分配给顶部左侧至底部右侧每一边不同的弯曲程度。 --- #### 使用百分比形式 采用百分数作为输入方式能够依据对象自身的宽度与高度动态调整其形状特征。 ```html <!DOCTYPE html> <html> <head> <style> div { border: 2px solid orange; padding: 10px; width: 200px; height: 100px; border-top-left-radius: 25% 50%; border-bottom-right-radius: 25% 50%; } </style> </head> <body> <div></div> </body> </html> ``` 上述例子说明了怎样借助百分比率构建更加复杂的几何图形轮廓[^1]。 --- #### 动画过渡实例 下面的例子还包含了简单的动画功能展示随着时间推移改变圆角的过程。 ```css .animated-border { width: 100px; height: 100px; background-color: #e74c3c; border-radius: 0; animation: borderRadiusAnim 3s ease-in-out infinite; } @keyframes borderRadiusAnim { 0%, 100% { border-radius: 0; } 50% { border-radius: 50%; } } ``` 这一部分揭示了结合关键帧技术实现交互式的视觉反馈机制的可能性[^2]。 --- #### 不同水平和垂直半径设置 有时可能希望单独定义横向或者纵向上的具体数值,则需要用到斜杠分割的形式表达各自独立的要求。 ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"/> <title>border-radius示例</title> <style> .box { width: 200px; height: 150px; background-color: #4CAF50; border-radius: 20% 5% 20% 5% / 5% 20% 5% 20%; } </style> </head> <body> <h2>带有不同水平和垂直圆角的示例</h2> <div class="box"></div> </body> </html> ``` 这段脚本解释了分开处理X轴Y轴方向的具体做法及其实际应用场景下的表现形态[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值