Thứ Tư, 30 tháng 9, 2015

15 mẹo giúp sử dụng Chrome DevTools hiệu quả

15 mẹo giúp sử dụng Chrome DevTools hiệu quả

15-chrome-devtools-tips-and-tricks
Google Chrome là trình duyệt web phổ biến thường được nhiều lập trình viên sử dụng. Trong đó có nhiều tính năng hỗ trợ nổi bật như trực tiếp chỉnh sửa CSS (live-editing CSS), sử dụng console và debugger. Trong bài viết này, SSS sẽ giới thiệu đến bạn 15 mẹo giúp sử dụng Chrome DevTools hiệu quả và cải thiện quy trình làm việc tốt hơn.

1. Nhanh chóng chuyển đổi file

Nếu sử dụng Sublime Text, chắc hẳn bạn đã quá quen thuộc với overlay “Go to anything”. Tin vui là Chrome DevTools cũng có tính năng này. Bạn chỉ cần nhấn tổ hợp phím Ctrl+P (hoặc Cmd+P với máy Mac) để nhanh chóng tìm kiếm và mở bất kì file nào trong project của mình.
1

2. Tìm kiếm trong source code

Nếu bạn muốn tìm kiếm trong source code thì phải làm sao? Để tìm kiếm một chuỗi cụ thể trong tất cả các files được tải trên page, hãy nhấn Ctrl+Shift+F (hoặc Cmd+Opt+F). Phương thức tìm kiếm này cũng hỗ trợ cả trên Regular expression (Biểu thức chính quy).
2.SearchAll

3. Di chuyển tới dòng lệnh

Sau khi mở một file trong tab Sources, DevTools cho phép bạn dễ dàng đi tới bất kì dòng lệnh nào bằng cách nhấn Ctrl+G (hoặc Cmd+L) và gõ số thự tự dòng bạn muốn đến.
Hoặc theo cách khác, bạn có thể nhấn Ctrl+O (Cmd+O) rồi nhập :số thứ tự dòng cần đến.
3.JumpToLine

4. Chọn các elements trong console

DevTools console cũng hỗ trợ 1 vài hàm và biến giúp chọn nhanh các DOM element: (The DevTools console supports some handy magic variables and functions selecting DOM elements:)
  • $() – viết tắt của document.querySelector(). Trả về element đầu tiên hợp với CSS selector trong ngoặc (Ví dụ: Nếu bạn gõ $(‘div’) thì sẽ trỏ về element div đầu tiên của page).
  • $$() – viết tắt của document.querySelectorAll(). Trả về 1 chuỗi các element hợp với CSS selector trong ngoặc.
  • $0 – $4 – Khi gõ $0 sẽ hiển thị DOM element mới nhất được chọn trong bảng điều khiển element. $1 – $4 sẽ lần lượt hiển thị DOM element thứ hai đến thứ 5.
4.
Nếu muốn tìm hiểu nhiều hơn về Console commands, bạn có thể đọc thêm Command Line API.

5. Sử dụng đa dạng carets & selections

Đây là 1 tính năng tương tự Sublime Text khác. Trong khi chỉnh sửa file, bạn có thể thiết lập đa dạng carets bằng cách giữ phím Ctrl (Cmd với Mac) và click vào bất kì chỗ nào bạn muốn,  vì vậy cho phép bạn cùng lúc viết code ở nhiều dòng khác nhau.
5.MultipleSelectClick

6. Preserve Log

Bạn có thể giữ lại log trong DevTools Console thay vì xóa chúng mỗi lần load page bằng cách check vào tùy chọn ☑Preserve Log trong Tab Console. Tính năng này khá tiện dụng khi bạn muốn kiểm tra những bugs xuất hiện ngay trước khi page unload.
6.PreserveLog

7. Pretty Print {}

Chrome DevTools  cung cấp sẵn công cụ “làm đẹp” code giúp bạn định dạng những đoạn code rút gọn thành những đoạn code dễ đọc hiểu. Để làm được điều này, trong tab Sources, bạn nhấp chọn ký hiệu {} ở góc trái bên dưới file đang mở.
7.PrettyPrint

8. Device mode

DevTools cũng cung cấp trang lập trình thân thiện với điện thoại di động. Clip từ Google dưới đây sẽ giới thiệu 1 vài tính năng chính của Device mode như điều chỉnh màn hình, mô phỏng chạm cảm ứng và mô phỏng trạng thái kết nối network trục trặc (bad network connections simulator).

9. Thiết bị mô phỏng cảm biến Device emulation sensors

Một tính năng khá “cool” khác của Device Mode là cho phép lựa chọn mô phỏng cảm biến của các thiết bị di động như chạm cảm ứng màn hình hay accelerometers (gia tốc kế). Thậm chí bạn có thể giả lập vị trí địa lý của mình. Để làm được điều này, bên dưới tab Elements, bạn chọn tab Emulation -> Sensors.
9.Sensors

10. Color Picker

Khi chọn 1 màu trong Style editor, bạn có thể nhấp chuột vào color preview và pop-up picker sẽ hiện ra. Trong khi color picker đang chạy, nếu bạn rê chuột trên page, trỏ chuột của bạn sẽ trở thành một kính lúp để chọn màu chuẩn xác đến từng pixel.
10.ColorPicker

11. Force element state

DevTools cung cấp 1 tính năng giúp giả lập trạng thái CSS trên các elements như :hover :focus, giúp dễ dàng tạo kiểu cho các element này.
11.SimulateHover

12. Visualize the shadow DOM

Các textbox, button hoặc input ngoài các element cơ bản thường bị ẩn đi. Tuy nhiên, bạn có thể vào Settings -> General và chọn Show user agent shadow DOM để giúp chúng hiển thị cụ thể. Thậm chí bạn có thể tạo kiểu (style) riêng cho các textbox, button hoặc input này, giúp dễ dàng tùy chỉnh theo ý muốn.
Ví dụ: Thông thường, bạn chỉ nhìn thấy . Nhờ tính năng này, bạn có thể thấy được chuỗi code tạo nên input đó.
12.ShadowDOM

13. Chọn các occurrence tiếp theo Select next occurrence

Nếu bạn chọn 1 từ gốc bất kì, sau đó giữ Ctrl+D (Cmd+D) trong khi chỉnh sửa các tập tin trong Tab Sources, thì những từ (giống từ gốc) còn lại sẽ được chọn, giúp bạn chỉnh sửa tất cả cùng lúc.
If you press Ctrl + D (Cmd + D) while editing files in the Sources Tab, the next occurrence of the current word will be selected as well, helping you edit them simultaneously.
13.MultiSelect

14. Thay đổi định dạng màu sắc

Giữ Shift và nhấp chọn vào ô hiển thị màu mẫu để thay đổi định dạng giữa các bảng mã rgba, hsl và hexadecimal.
14.ColorFormat

15. Chỉnh sửa các tập tin local nhờ Workspaces

Workspaces là một tính năng hữu ích của Chrome DevTools, giúp công cụ này trở thành một IDE (Integrated Development Environment – Môi trường phát triển tích hợp) thực thụ. Workspaces kết nối các tập tin trong tab Sources với các tập tin trong local project, vì vậy bạn có thể chỉnh sửa và lưu trực tiếp mà không cần copy/paste (sao chép/dán) những thay đổi của mình vào text editor bên ngoài.
Để thiết lập cấu hình Workspaces, bạn vào tab Sources và nhấp chuột phải vào bất kì đâu trên panel bên trái và chọn Add Folder To Worskpace, hoặc chỉ cần kéo và thả toàn bộ project folder vào Developer Tools. Giờ thì các sub directories và tất cả files của folder được chọn đã sẵn sàng để chỉnh sửa bất kể bạn đang ở trên page nào. Thậm chí, bạn có thể liên kêys các file trong folder của mình với các file của page để  chỉnh sửa trực tiếp và lưu trữ dễ dàng hơn. To make it even more useful, you can then map files in your folder to those used by the page, allowing for live editing and easy saving.
Bạn có thể tìm hiểu thêm về Workspaces tại đây.
Dịch từ tutorialzine.com.

Form Success Message Best Practices and Examples

Form Success Message Best Practices and Examples

form success message

Give each form its own success message

It doesn’t matter what kind of website you have, if you do not have forms that let people contact you, you are not making the most of your website. I would go so far as to suggest that every page on your website ought to have some kind of form. And once visitors complete and submit their form there MUST be a success message.

Saying thank you is not always enough

Here are four examples of simple success messages:

Thank you!

Your message has been successfully sent. We will contact you very soon!

Thank you for contacting us.

You are very important to us, all information received will always remain confidential. We will contact you as soon as we review your message.

Thanks!

We appreciate that you’ve taken the time to write us. We’ll get back to you very soon. Please come back and see us often.

Thank you for contacting us.

We have received your enquiry and will respond to you within 24 hours. For urgent enquiries please call us on one of the telephone numbers below.
These thank you messages are not very inspiring at all. The reason is that they don’t give a specific answer, they are vague. Very soon when? Why should I come back and see you often? You will respond within 24 hours with what?

Give instructions to ensure proper completion

Success messages can go further. Good messages don’t just end the form submittal process: they help the user make sure that the form was completed correctly. Here are a few examples:

Thank you for contacting us

We have sent a verification email to the address you used when you filled in the form.

You haven’t received your verification email? Let us give you a hand!

Follow these simple steps:
  1. Is the email you used “email@email.com” correct? Are you checking the right email account.?
  2. Check your email spam folder for your confirmation email. It can lose its way to your inbox and wind up trapped in there!
  3. Keep in mind, it can take a while, even a few hours for you to receive your email confirmation. We ask you to be patient for at least two hours
  4. You can try to fill in the form once again, remember to make sure your email address is correct.
  5. After following these steps, if you still have not received a confirmation email or if the confirmation link that your received is not working you can let us know by sendig us an email at the following address. We’ll be happy to help you out!

Thank you for your request!

Your Service Request Form will be reviewed shortly and a response made to the email address or phone number given. Please check your email, and open the email from info@servicerequest.com titled “Re: Your Service Request Form.” If you do not see the email in a few minutes, check your “junk mail” folder or “spam” folder. We make every effort to ensure that these emails are delivered.  If you do not see the email in your inbox, please check your junk mail folder and addinfo@servicerequest.com” to your White List or Safe Sender List. If you do not receive a confirmation email try submitting the form again. If  you still don’t receive an email, then write to  info@servicerequest.com explaining the problem. We will do our best to answer your request as soon as possible.

Use the input data in the the success message

Using the input data directly lets the person see in real time if the form was filled in correctly. This is a feature available in many form building plugins.WordPress Contact Forms has a token system just for this purpose:

Thank You {Name} {Email}

Your message was sent to our Support Team. You should receive a reply from a representative of our web site by the end of the next business day by email at {Email}. Occasionally we receive a very large number of messages, and your response may take a little longer. If this occurs, we appreciate your patience, and we assure you that you will receive a response. Thank you for taking the time to contact us. Have a great day, Ourwebsite.com Support Team

Tell visitors where to go next

Thanks for contacting us.

This email is checked regularly during business hours (9-5 EST). We’ll get back to you as soon as possible, usually within a few hours. Either John or Jay will respond to your email.
Until then, make sure to check out the following resources:
Frequently Asked Questionswww.ourwebsite.com/faqs/and
Try searching for your problem: www.ourwebsite.com/search/
Also check the Tutorials page: www.ourwebsite.com/tutorials/

Give visitors something special

You can decide to give something right away:

Thank you for filling in the form.

But it is better to send a link in the email notification as it ensures that the visitor will give you a working email address:
Or maybe give certain results within the thank you page.

Test completed. You scored 5 out of 6

Other important notes for form success messages

Here are a few other considerations:
  • No Thank You or Form Success Message means inflexibility and user confusion at best.
  • All of the success message approaches above can be mixed and matched to better suit the form you have built.
  • It is advisable that the message appear on the same page as the form. If you redirect to thank you pages make sure that the page is not accessible other than when a form has been filled in. This is a much overlooked detail as many thank you pages appear on SERPS (Search Engine Result Pages). Let me repeat:  thank you messages should not be indexed in goolge or accessible by visitors who have not filled in the form.
  • Email verification when the user is filling in a form is great but it is not always enough. Sending a message to the email helps make sure that the user receives confirmation that he filled in a form but it is not enough. The surest way is to ask  for email address in the email he receives. sort of like doble opt in. in the thank you page remind him of the email he used so he gets another chance to check the spelling of the email
WordPress Contact Forms and many other contact form plugins give you the choice to be creative with your thank you messages.

Now it’s up to you. Download WordPress Contact Forms Plugin »

Speak Your mind! Share this post or add your own Comment. I will do my best to answer.

Thứ Ba, 22 tháng 9, 2015

10 Useful Techniques To Improve Your User Interface Designs

10 Useful Techniques To Improve Your User Interface Designs

1. Padded block links 
Web design consists, for the most part, of interface design. There are many techniques involved in crafting beautiful and functional interfaces. Here’s my collection of 10 that I think you’ll find useful in your work. They’re not related to any particular theme, but are rather a collection of techniques I use in my own projects. Without further ado, let’s get started.
Links (or anchors) are inline elements by default, which means that their clickable area spans only the height and width of the text. This clickable area, or the space where you can click to go to that link’s destination, can be increased for greater usability. We can do this by adding padding and, in some cases, also converting the link into a block element. Here’s an example of inline and padded links, with their clickable areas highlighted to show the difference:
Inline and padded links
Obviously, the larger the clickable area is, the easier it is to click on the link because there is less of a chance of missing it. Converting links into block elements makes the text area span the whole width of the container, unless the width is specified otherwise. This makes it ideal for links located in sidebars. We can do it with the following code:
a {
 display: block;
 padding: 6px;
}
Make sure to also add a healthy dose of padding to the links, because converting a link into a block only affects its behavior and width; adding padding ensures that the link is high enough and has some room to breathe.

2. Typesetting buttons Link

Attention to every detail is what separates a great product from a mediocre one. Interface elements such as buttons and tabs are clicked on many times a day by your users, so it pays to typeset them properly; and by typesetting I mean positioning the label. Here’s a couple of examples of the kind of misplaced labels I sometimes notice:
Badly typeset button labels
At first glance they look okay, but notice that the text is placed too high because the lowercase letters have been used as a guide to align the text vertically in the center, like so:
Badly typeset button labels
However, if we use uppercase letters as well as lowercase letters with ascenders (“t,” “d,” “f,” “h,” “k” and “l”), the balance shifts upwards, making the label appear too high on the button. In such cases, we should set the type using the uppercase height as a guide — or set it a little bit higher if most of the letters are lowercase. Here’s what I mean:
Badly typeset button labels
This gives the whole button a more balanced look and feel. Little touches like this go a long way towards making your interface more polished and satisfying to use.

3. Using contrast to manage focus Link

Similarly, you can also manage the focus of your visitors’ attention with contrast between elements. Here’s an example of a post headline and some meta information underneath regarding who posted the article and its date:
A typical blog post headline
All the text is set in black. Let’s decrease the contrast between the meta information (the date and author’s name) and the background by putting the text in a light shade of gray:
Headline with adjusted contrast
The highest contrast element here is the headline, so it literally pops out at us. The other elements fade into the background. Here, I’ve chosen the author as the second-most important element, and the date as the least. The font also differs in size and style, but the contrast level can be very powerful. Let’s reverse the order of importance to date, author and headline:
Another headline with adjusted contrast
You can see how effective it is in shifting focus: the date now pops out at you, while the headline fades away. This technique comes in very handy for information-heavy websites, such as blogs, forums and social networks, in which you want to make a lot of information easily scannable while still showing a lot of additional things, like dates. Fading the extras allows visitors to easily focus their attention on the most important pieces of text.

4. Using color to manage attention Link

Color can also be used to effectively focus your visitors’ attention on important or actionable elements. For example, during the US presidential election, pretty much all of the candidates’ websites had the donation button colored red. Red is a very bright and powerful color so it attracts attention, and it stands out even more when the rest of the website is blue or another colder color.
Warmer tones like red, yellow and orange are naturally bright and so tend to attract the eye. They also “expand” when set against colder colors like blue and green. This means that an orange button on a blue background looks like it’s flowing outwards and taking the front seat. Conversely, a blue button on an orange background contracts inward, wishing to stay in the background. Here’s a picture to illustrate:
Comparing warm and cold colors
Here’s a couple of examples of websites that use color effectively to direct users’ attention to the important elements:
Function website
Function features a “We’re Hiring” link on its jobs page. To ensure the link is not missed, the designers set it against a red background that pops out from the dark background header, effectively grabbing attention.
Causecast website
Causecast use color effectively. Four bright pink elements pop out at you: the logo, the feedback link, the donate link and the website description message.
Want the “About” blurb on your website to grab the visitor’s focus? Make the background yellow. Want to make the “Join” button stand out? Color it orange. Make sure not to highlight too many elements, though; if you do, they may get lost in each other’s company.

5. White space indicates relationships Link

One of the most crucial elements in an interface is the white space between elements. If you’re not familiar with the term white space, it means just that: space between one interface element and another, be it a button, a navigation bar, article text, a headline and so on. By manipulating white space, we can indicate relationships between certain elements or groups of elements.
So, for example, by putting the headline near the article text we indicate that it is related to that text. The text is then placed farther away from other elements to separate it and make it more readable. Here’s an example in which white space could be improved:
Whitespace usage here can be improved
The text looks all right and is certainly readable, but because the spaces above and below each heading are equal, they don’t separate each piece of text clearly. We can improve this by increasing the white space between each section and also by slightly tightening the line height of the paragraphs:
Improved whitespace
This results in more clearly defined blocks; we can easily tell which headings go with which pieces of text and can see the separate sections clearly. Good designers often squint or glance at their work from a distance, which lets them see the blocks of elements separated by white space as they merge together. If you cannot see these groups clearly then you may need to tweak your white space.

6. Letter spacing Link

Web design is pretty limiting for typographers. But while there are only a few safe Web fonts and not a great many things you can do to style them, it’s worth remembering that we do still have some level of control. “Tracking” is a term used in the field of typography to describe the adjustment of spacing between letters in words. We’ve got the ability to do this with CSS using the “letter-spacing” property.
If used with restraint and taste, this property can be effective in improving the look of your headlines. I wouldn’t recommend using letter spacing on the body text because the default spacing generally provides the best readability for smaller font sizes.
Here’s an example of letter spacing in use:
Letter spacin examples
And here’s the CSS code used for the above examples:
h1 {
 font-family: Helvetica;
 font-size: 27px;
}

h2 {
 font-family: Helvetica;
 font-size: 27px;
 letter-spacing: -1px;
}

h3 {
 font-family: Georgia;
 font-size: 24px;
 letter-spacing: 3px;
 font-variant: small-caps;
 font-weight: normal;
}
The effect can be useful when you want to craft a more aesthetically pleasing or more original heading. Here, I’ve used only a couple pixels for letter spacing, but already it makes a big difference to the style of the font.

7. Auto-focus on input Link

Many Web applications and websites feature forms. These may be search forms or input forms inviting you to submit something. If this form is the core feature of your application or website, you may want to consider automatically focusing the user’s cursor on the input field when the website loads. This will speed things up because users can start typing right away without having to click on it. A good example of this is Google and Wikipedia’s websites.
Wikipedia auto focus
Upon arriving at Wikipedia.org, the search box is already highlighted, ready to accept text.
To automatically focus on input fields, you’ll need a little bit of JavaScript. There are various solutions, and the one you should use depends on the functionality you want to achieve. The simplest way to do it would be to add the following to your body tag:

Your form code should look something like:
Now, every time the page loads, the text field called “form_field” will be automatically selected, ready for input.
The only problem with this is that if your users want to return to the previous page using the Backspace key, they will be out of luck because they’ll just be deleting characters in the input field. Thankfully, Harmen Janssen has another simple JavaScript solution you can find here. Harmen’s script allows the Backspace key to go to the previous page when there are no characters left in the input field to delete.

8. Custom input focus Link

While the default look of form elements suffices for most functions, sometimes we want something a little prettier or a little more standardized across various browsers and systems. We can style input fields by simply targeting it with an “id,” “class” or plain old “input,” like so:
input {
 border: 2px solid #888;
 padding: 4px;
 font-size: 1em;
 background-color: #F8F8F8;
}
Default and styled input fields
What’s more interesting is also being able to style the input field when it’s in focus; that is, the state it’s in when it has been clicked. To do this, we need to attach a “:focus” after the “input” property:
input:focus {
 border-color: #000;
 background-color: #FFFE9D;
}
Input field in focus
If you’re using custom backgrounds to style your input field, they may clash with some browsers and operating systems’ default focus styles. For example, here’s a screenshot of a custom-styled form clashing with the default blue OS X glow effect:
OS X input glow
In such cases, you could also use the “input:focus” property to remove the default styling. The default blue glow in the screenshot above can be removed by disabling the “outline” property:
input:focus {
 outline: none;
}
The blue glow effect will now be gone:
OS X input glow removed
Obviously you would only want to remove the outline if you’re replacing it with your own styling, so that you don’t negatively affect the accessibility and usability of your forms.

9. Hover controls Link

Some Web applications have extra utility controls, such as edit and delete buttons, that don’t necessarily have to be shown beside every item at all times. They can be hidden to simplify the interface and focus visitors’ attention on the main controls and content. For example, these hover controls are used in Twitter when you hover over messages:
Twitter's hover controls
These hover controls can be achieved with some simple CSS code, without any JavaScript. Simply style the
with the controls when its parent
is in a hover state. Here’s the code to hide and show the controls (using a
with the class “controls” inside a
with the class “message”):
.message .controls { display: none; }
.message:hover .controls { display: block; }
When you hover over the “message”
, the “controls”
inside it will appear, along with all of its content, giving you the same functionality as shown in the Twitter screenshot above.
There may be an issue with accessibility because screen readers may not be able to read the hidden
. There are plenty of other ways to hide the inner
, such as offsetting it with a negative margin that takes it off the page (e.g. “left-margin: -9999px”), coloring its text the same color as the background or simply placing another
on top of it.
This technique should of course be used with restraint because you don’t want to hide your important controls; but if used correctly, it can be useful for cleaning up your interface by removing those extra utility links that you don’t want to show up at all times.
Note that this doesn’t work in IE6, so you’ll need to override the hiding property in your IE6-specific style sheet or, if you don’t have one, simply use the following IE6-specific code inside the section of your code:
<!--[if lt IE 7]>