Tạo button theo phong cách trang Facebook với CSS3

0
0
(0)

Hàng ngày chúng ta đều lướt facebook và có lẽ các bạn cũng đã quen thuộc với các button trên trang này, việc tạo các button giống như thế cho website của mình, sẽ tạo cảm giác thân thuộc cho người dùng và người dùng có thể sẽ ở lại lâu hơn trên trang web, blog của các bạn. Hôm nay mình sẽ chia sẻ cho các bạn tạo các button theo phong cách facebook mà không cần phải làm gì nhiều, chỉ việc copy theo nguyên mẫu mà mình giới thiệu cho các bạn sau đây.

Tạo button theo phong cách trang Facebook với CSS3

Xem Demo | Download

 

CSS

Trong bài viết này có 1 file hình dùng để tạo icon, các bạn có thể save về máy file này :  .

Để tạo các button, các bạn chỉ cần copy nguyên đoạn css sau :

001

002

003

004

005

006

007

008

009

010

011

012

013

014

015

016

017

018

019

020

021

022

023

024

025

026

027

028

029

030

031

032

033

034

035

036

037

038

039

040

041

042

043

044

045

046

047

048

049

050

051

052

053

054

055

056

057

058

059

060

061

062

063

064

065

066

067

068

069

070

071

072

073

074

075

076

077

078

079

080

081

082

083

084

085

086

087

088

089

090

091

092

093

094

095

096

097

098

099

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

.uibutton,

.uibutton:visited {

    position: relative;

    z-index: 1;

    overflow: visible;

    display: inline-block;

    padding: 0.3em 0.6em 0.375em;

    border: 1px solid #999;

    border-bottom-color: #888;

    margin: 0;

    text-decoration: none;

    text-align: center;

    font: bold 11px/normal 'lucida grande', tahoma, verdana, arial, sans-serif;

    white-space: nowrap;

    cursor: pointer;

    /* outline: none; */

    color: #333;

    background-color: #eee;

    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#f5f6f6), to(#e4e4e3));

    background-image: -moz-linear-gradient(#f5f6f6, #e4e4e3);

    background-image: -o-linear-gradient(#f5f6f6, #e4e4e3);

    background-image: linear-gradient(#f5f6f6, #e4e4e3);

    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f5f6f6', EndColorStr='#e4e4e3'); /* for IE 6 - 9 */

    -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #fff;

    -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #fff;

    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #fff;

    /* IE hacks */

    zoom: 1;

    *display: inline;

}

 

.uibutton:hover,

.uibutton:focus,

.uibutton:active {

    border-color: #777 #777 #666;

}

 

.uibutton:active {

    border-color: #aaa;

    background: #ddd;

    filter: none;

    -webkit-box-shadow: none;

    -moz-box-shadow: none;

    box-shadow: none;

}

 

/* overrides extra padding on button elements in Firefox */

.uibutton::-moz-focus-inner {

    padding: 0;

    border: 0;

}

 

/* ............................................................................................................. Icons */

 

.uibutton.icon:before {

    content: "";

    position: relative;

    top: 1px;

    float:left;

    width: 10px;

    height: 12px;

    margin: 0 0.5em 0 0;

    background: url(fb-icons.png) 99px 99px no-repeat;

}

 

.uibutton.edit:before  { background-position: 0 0; }

.uibutton.add:before  { background-position: -10px 0; }

.uibutton.secure:before  { background-position: -20px 0; }

.uibutton.prev:before  { background-position: -30px 0; }

.uibutton.next:before  { float:right; margin: 0 -0.25em 0 0.5em; background-position: -40px 0; }

 

/* ------------------------------------------------------------------------------------------------------------- BUTTON EXTENSIONS */

 

/* ............................................................................................................. Large */

 

.uibutton.large {

    font-size: 13px;

}

 

/* ............................................................................................................. Submit, etc */

 

.uibutton.confirm {

    border-color: #29447e #29447e #1a356e;

    color: #fff;

    background-color: #5B74A8;

    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#637bad), to(#5872a7));

    background-image: -moz-linear-gradient(#637bad, #5872a7);

    background-image: -o-linear-gradient(#637bad, #5872a7);

    background-image: linear-gradient(#637bad, #5872a7);

    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#637bad', EndColorStr='#5872a7'); /* for IE 6 - 9 */

    -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #8a9cc2;

    -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #8a9cc2;

    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #8a9cc2;

}

 

.uibutton.confirm:active {

    border-color: #29447E;

    background: #4F6AA3;

    filter: none;

    -webkit-box-shadow: none;

    -moz-box-shadow: none;

    box-shadow: none;

}

 

/* ............................................................................................................. Special */

 

.uibutton.special {

    border-color: #3b6e22 #3b6e22 #2c5115;

    color: #fff;

    background-color: #69a74e;

    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#75ae5c), to(#67a54b));

    background-image: -moz-linear-gradient(#75ae5c, #67a54b);

    background-image: -o-linear-gradient(#75ae5c, #67a54b);

    background-image: linear-gradient(#75ae5c, #67a54b);

    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#75ae5c', EndColorStr='#67a54b'); /* for IE 6 - 9 */

    -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #98c286;

    -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #98c286;

    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 #98c286;

}

 

.uibutton.special:active {

    border-color: #3b6e22;

    background: #609946;

    filter: none;

    -webkit-box-shadow: none;

    -moz-box-shadow: none;

    box-shadow: none;

}

 

/* ............................................................................................................. Disable */

 

.uibutton.disable {

    z-index: 0;

    border-color: #c8c8c8;

    color: #b8b8b8;

    background: #f2f2f2;

    cursor: default;

    -webkit-box-shadow: none;

    -moz-box-shadow: none;

    box-shadow: none;

}

 

.uibutton.confirm.disable {

    color: #fff;

    border-color: #94a2bf;

    background: #adbad4;

}

 

.uibutton.special.disable {

    color: #fff;

    border-color: #9db791;

    background: #b4d3a7;

}

 

.uibutton.disable.icon:before,

.uibutton.disable.icon:after {

    opacity: 0.5;

}

 

/* ------------------------------------------------------------------------------------------------------------- BUTTON GROUPS */

 

.uibutton-group {

    display: inline-block;

    list-style: none;

    padding: 0;

    margin: 0;

    /* IE hacks */

    zoom: 1;

    *display: inline;

}

 

.uibutton + .uibutton,

.uibutton + .uibutton-group,

.uibutton-group + .uibutton,

.uibutton-group + .uibutton-group {

    margin-left: 3px;

}

 

.uibutton-group li {

    float: left;

    padding: 0;

    margin: 0;

}

 

.uibutton-group .uibutton {

    float: left;

    margin-left: -1px;

}

 

.uibutton-group .uibutton:hover,

.uibutton-group .uibutton:focus,

.uibutton-group .uibutton:active {

    z-index:2;

}

 

.uibutton-group > .uibutton:first-child,

.uibutton-group li:first-child .uibutton {

    margin-left: 0;

}

 

/* ------------------------------------------------------------------------------------------------------------- BUTTON CONTAINER */

/* For mixing buttons and button groups, e.g., in a navigation bar */

 

.uibutton-toolbar {

    padding: 6px;

    border-top: 1px solid #ccc;

    background: #f2f2f2;

}

 

.uibutton-toolbar .uibutton,

.uibutton-toolbar .uibutton-group {

    vertical-align: bottom;

}

HTML

Sau khi đã copy đoạn css, giờ đây để tạo button, chúng ta chỉ việc tạo theo từng cấu trúc html mà các bạn mong muốn như sau :

Default buttons

1

2

3

<p><a class="uibutton" href="#button">Change picture</a></p>

<p><input class="uibutton confirm" type="submit" value="Publish"></p>

<p><button class="uibutton special">Request an invitation</button></p>

Large buttons

1

2

3

<p><a class="uibutton large" href="#button">Change picture</a></p>

<p><input class="uibutton large confirm" type="submit" value="Publish"></p>

<p><button class="uibutton large special">Request an invitation</button></p>

Grouped buttons

01

02

03

04

05

06

07

08

09

10

<div class="uibutton-toolbar">

            <a class="uibutton" href="#button">Mark as unread</a>

 

            <div class="uibutton-group">

                <a class="uibutton" href="#button">Report spam</a>

                <a class="uibutton" href="#button">Delete</a>

            </div>

 

            <a class="uibutton" href="#button">Unsubscribe</a>

 </div>

Buttons with icons

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

<table>

            <thead>

                <tr>

                    <th scope="col">Class</th>

                    <th scope="col">Example</th>

                </tr>

            </thead>

            <tr>

                <td scope="row"><code>.edit</code></td>

                <td><a class="uibutton icon edit" href="#button">Edit post</a></td>

            </tr>

            <tr>

                <td scope="row"><code>.add</code></td>

                <td><a class="uibutton icon add" href="#button">Add a photo</a></td>

            </tr>

            <tr>

                <td scope="row"><code>.secure</code></td>

                <td><a class="uibutton icon secure" href="#button">Private account</a></td>

            </tr>

            <tr>

                <td scope="row"><code>.prev</code></td>

                <td><a class="uibutton icon prev" href="#button">Back to messages</a></td>

            </tr>

            <tr>

                <td scope="row"><code>.next</code></td>

                <td><a class="uibutton icon next" href="#button">Get more info</a></td>

            </tr>

</table>

MÌnh hy vọng là với bài viết này, nó sẽ giúp ích cho các bạn giảm thiểu đáng kể thời gian thiết kế của mình.

Chúc các bạn thành công !

 

 

Nguồn : https://www.thuthuatweb.net/

 

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Leave A Reply

Your email address will not be published.