CSS3 基础(009_按钮)

原始网址:http://www.w3schools.com/css/css3_buttons.asp

翻译:

CSS 按钮(CSS Buttons)


学习使用 CSS 如何样式化按钮。


基本按钮样式(Basic Button Styling)

.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.btn {
    background-color: #4caf50;
    border: medium none;
    color: #ffffff;
    font-size: 16px;
    margin: 16px 0 !important;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    transition-duration: 0.4s;
}
</style>
</head>
<body>
    <p>
        <button style="margin-right: 25px;">Default Button</button>
        <button class="btn w3-green">CSS Button</button>
    </p>
</body>
</html>

按钮颜色(Button Colors)

使用 属性改变按钮的背景色:

.button1 {background-color: #4CAF50;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7; color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7;color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */
</style>
</head>
<body>
    <h2>Button Colors</h2>
    <p>Change the background color of a button with the background-color property:</p>
    <button class="button">Green</button>
    <button class="button button2">Blue</button>
    <button class="button button3">Red</button>
    <button class="button button4">Gray</button>
    <button class="button button5">Black</button>
</body>
</html>

使用 font-size 属性改变按钮的大小:

.button1 {font-size: 10px;}
.button2 {font-size: 12px;}
.button3 {font-size: 16px;}
.button4 {font-size: 20px;}
.button5 {font-size: 24px;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    margin: 4px 2px;
    cursor: pointer;
}

.button1 {font-size: 10px;}
.button2 {font-size: 12px;}
.button3 {font-size: 16px;}
.button4 {font-size: 20px;}
.button5 {font-size: 24px;}
</style>
</head>
<body>
    <h2>Button Sizes</h2>
    <p>Change the font size of a button with the font-size property:</p>
    <button class="button button1">10px</button>
    <button class="button button2">12px</button>
    <button class="button button3">16px</button>
    <button class="button button4">20px</button>
    <button class="button button5">24px</button>
</body>
</html>

使用 padding 属性改变按钮的内边距:

.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
</style>
</head>
<body>
    <h2>Button Sizes</h2>
    <p>Change the padding of a button with the padding property:</p>
    <button class="button button1">10px 24px</button>
    <button class="button button2">12px 28px</button>
    <button class="button button3">14px 40px</button>
    <button class="button button4">32px 16px</button>
    <button class="button button5">16px</button>
</body>
</html>

圆角按钮(Rounded Buttons)

使用 border-radius 属性给按钮添加圆角:

.button1 {border-radius: 2px;}
.button2 {border-radius: 4px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button1 {border-radius: 2px;}
.button2 {border-radius: 4px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
</style>
</head>
<body>
    <h2>Rounded Buttons</h2>
    <p>Add rounded corners to a button with the border-radius property:</p>
    <button class="button button1">2px</button>
    <button class="button button2">4px</button>
    <button class="button button3">8px</button>
    <button class="button button4">12px</button>
    <button class="button button5">50%</button>
</body>
</html>

按钮边框色(Colored Button Borders)

使用 border 属性给按钮添加边框色:

.button1 {
    background-color: white;
    color: black;
    border: 2px solid #4CAF50; /* Green */
}
...
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button1 {
    background-color: white;
    color: black;
    border: 2px solid #4CAF50;
}

.button2 {
    background-color: white;
    color: black;
    border: 2px solid #008CBA;
}

.button3 {
    background-color: white;
    color: black;
    border: 2px solid #f44336;
}

.button4 {
    background-color: white;
    color: black;
    border: 2px solid #e7e7e7;
}

.button5 {
    background-color: white;
    color: black;
    border: 2px solid #555555;
}
</style>
</head>
<body>
    <h2>Colored Button Borders</h2>
    <p>Use the border property to add a border to the button:</p>
    <button class="button button1">Green</button>
    <button class="button button2">Blue</button>
    <button class="button button3">Red</button>
    <button class="button button4">Gray</button>
    <button class="button button5">Black</button>
</body>
</html>

按钮悬浮效果(Hoverable Buttons)

当移动鼠标指针悬停按钮之上的时候,使用 :hover 选择器改变按钮式样。
提示:使用 transition-duration 属性可确定 "hover" 效果的速率:

.button {
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
}

.button:hover {
    background-color: #4CAF50; /* Green */
    color: white;
}
...
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 16px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
    cursor: pointer;
}

.button1 {
    background-color: white;
    color: black;
    border: 2px solid #4CAF50;
}

.button1:hover {
    background-color: #4CAF50;
    color: white;
}

.button2 {
    background-color: white;
    color: black;
    border: 2px solid #008CBA;
}

.button2:hover {
    background-color: #008CBA;
    color: white;
}

.button3 {
    background-color: white;
    color: black;
    border: 2px solid #f44336;
}

.button3:hover {
    background-color: #f44336;
    color: white;
}

.button4 {
    background-color: white;
    color: black;
    border: 2px solid #e7e7e7;
}

.button4:hover {
    background-color: #e7e7e7;
}

.button5 {
    background-color: white;
    color: black;
    border: 2px solid #555555;
}

.button5:hover {
    background-color: #555555;
    color: white;
}
</style>
</head>
<body>
    <h2>Hoverable Buttons</h2>
    <p>Use the :hover selector to change the style of the button when
        you move the mouse over it.</p>
    <p>
        <strong>Tip:</strong> Use the transition-duration property to
        determine the speed of the "hover" effect:
    </p>
    <button class="button button1">Green</button>
    <button class="button button2">Blue</button>
    <button class="button button3">Red</button>
    <button class="button button4">Gray</button>
    <button class="button button5">Black</button>
</body>
</html>

按钮阴影(Shadow Buttons)

使用 box-shadow 属性给按钮添加阴影:

.button1 {
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}

.button2:hover {
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
}

.button1 {
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.button2:hover {
    box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}
</style>
</head>
<body>
    <h2>Shadow Buttons</h2>
    <p>Use the box-shadow property to add shadows to the button:</p>
    <button class="button button1">Shadow Button</button>
    <button class="button button2">Shadow on Hover</button>
</body>
</html>

按钮不可用(Disabled Buttons)

使用 opacity 属性给按钮添加透明效果(创建 "disabled" 外观)。
提示:你也可以添加值为 "not-allowed"cursor 属性,当你的鼠标指针悬停于按钮之上的时候,将呈现 “no parking sign”:

.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
</style>
</head>
<body>
    <h2>Disabled Buttons</h2>
    <p>Use the opacity property to add some transparency to the button (make it look disabled):</p>
    <button class="button">Normal Button</button>
    <button class="button disabled">Disabled Button</button>
</body>
</html>

按钮宽度(Button Width)

默认情况下,按钮的大小由文本内容确定(与之宽度相当)。使用 width 属性改变按钮的宽度:

.button1 {width: 250px;}
.button2 {width: 50%;}
.button3 {width: 100%;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.button1 {width: 250px;}
.button2 {width: 50%;}
.button3 {width: 100%;}
</style>
</head>
<body>
    <h2>Button Width</h2>
    <p>Use the width property to change the width of the button:</p>
    <p>
        <strong>Tip:</strong> Use pixels if you want to set a fixed width and
        use percent for responsive buttons (e.g. 50% of its parent element). Resize the browser window to see the effect.
    </p>
    <button class="button button1">250px</button>
    <br>
    <button class="button button2">50%</button>
    <br>
    <button class="button button3">100%</button>
</body>
</html>

Button Groups

去掉 margins,对每个按钮再添加 float:left 以创建 button group:

.button {
    float: left;
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    float: left;
}

.button:hover {
    background-color: #3e8e41;
}
</style>
</head>
<body>
    <h2>Button Groups</h2>
    <p>Remove margins and float the buttons to create a button group:</p>

    <button class="button">Button</button>
    <button class="button">Button</button>
    <button class="button">Button</button>
    <button class="button">Button</button>

    <p style="clear: both">
        <br>Remember to clear floats after, or else will this p element also float next to the buttons.
    </p>
</body>
</html>

Bordered Button Groups

使用 border 属性创建 bordered button group:

.button {
    float: left;
    border: 1px solid green
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    background-color: #4CAF50; /* Green */
    border: 1px solid green;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    float: left;
}

.button:hover {
    background-color: #3e8e41;
}
</style>
</head>
<body>

<h2>Bordered Button Group</h2>
<p>Add borders to create a bordered button group:</p>

<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>

<p style="clear:both"><br>Remember to clear floats after, or else will this p element also float next to the buttons.</p>

</body>
</html>

带有动画效果的按钮(Animated Buttons)

<!-- 悬停时添加箭头效果 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.button {
    display: inline-block;
    border-radius: 4px;
    background-color: #f4511e;
    border: none;
    color: #FFFFFF;
    text-align: center;
    font-size: 28px;
    padding: 20px;
    width: 200px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
}

.button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
}

.button span:after {
    content: "»";
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
}

.button:hover span {
    padding-right: 25px;
}

.button:hover span:after {
    opacity: 1;
    right: 0;
}
</style>
</head>
<body>
    <h2>Animated Button</h2>
    <button class="button" style="vertical-align: middle"><span>Hover </span></button>
</body>
</html>
<!-- 点击时添加涟漪效果 -->
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    position: relative;
    background-color: #4CAF50;
    border: none;
    font-size: 28px;
    color: #FFFFFF;
    padding: 20px;
    width: 200px;
    text-align: center;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
    text-decoration: none;
    overflow: hidden;
    cursor: pointer;
}

.button:after {
    content: "";
    background: #f1f1f1;
    display: block;
    position: absolute;
    padding-top: 300%;
    padding-left: 350%;
    margin-left: -20px !important;
    margin-top: -120%;
    opacity: 0;
    transition: all 0.8s
}

.button:active:after {
    padding: 0;
    margin: 0;
    opacity: 1;
    transition: 0s
}
</style>
</head>
<body>
    <h2>Animated Button - Ripple Effect</h2>
    <button class="button">Click Me</button>
</body>
</html>
<!-- 点击时添加按压效果 -->
<!DOCTYPE html>
<html>
<head>
<style>
.button {
    display: inline-block;
    padding: 15px 25px;
    font-size: 24px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    outline: none;
    color: #fff;
    background-color: #4CAF50;
    border: none;
    border-radius: 15px;
    box-shadow: 0 9px #999;
}

.button:hover {
    background-color: #3e8e41
}

.button:active {
    background-color: #3e8e41;
    box-shadow: 0 5px #666;
    transform: translateY(4px);
}
</style>
</head>
<body>
    <h2>Animated Buttons - "Pressed Effect"</h2>
    <button class="button">Click Me</button>
</body>
</html>
Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值