- CSS Forms
- Styling Input Fields
- Example
- Padded Inputs
- Example
- Bordered Inputs
- Example
- Example
- Colored Inputs
- Example
- Focused Inputs
- Example
- Example
- Input with icon/image
- Example
- Animated Search Input
- Example
- Styling Textareas
- Example
- Styling Select Menus
- Example
- Styling Input Buttons
- Example
- Responsive Form
- Aligned Form
- How to Create a Coloured («Colored») Box in HTML/CSS
- How to put text into a box that has a background colour
- How to Create a Coloured («Colored») Box in HTML/CSS
- Prerequisites
- Creating a Coloured Box
- Demo
- Browser Compatibility
- thesitewizard™ News Feed (RSS Site Feed)
- Please Do Not Reprint This Article
- Related Articles
- New Articles
- Popular Articles
- How to Link to This Page
- Create Colored Boxes
- Invalid Short Codes & CSS
- 3 Ways to Make Colored Boxes
- Using Pure CSS Code
- Creating Shortcodes for Boxes
- Difference Between Shortcodes & CSS
- Changing Themes Without Breaking Code
- Reader Interactions
- Leave a Reply Cancel reply
- Primary Sidebar
CSS Forms
The look of an HTML form can be greatly improved with CSS:
Styling Input Fields
Use the width property to determine the width of the input field:
Example
The example above applies to all elements. If you only want to style a specific input type, you can use attribute selectors:
- input[type=text] — will only select text fields
- input[type=password] — will only select password fields
- input[type=number] — will only select number fields
- etc..
Padded Inputs
Use the padding property to add space inside the text field.
Tip: When you have many inputs after each other, you might also want to add some margin , to add more space outside of them:
Example
Note that we have set the box-sizing property to border-box . This makes sure that the padding and eventually borders are included in the total width and height of the elements.
Read more about the box-sizing property in our CSS Box Sizing chapter.
Bordered Inputs
Use the border property to change the border size and color, and use the border-radius property to add rounded corners:
Example
If you only want a bottom border, use the border-bottom property:
Example
Colored Inputs
Use the background-color property to add a background color to the input, and the color property to change the text color:
Example
Focused Inputs
By default, some browsers will add a blue outline around the input when it gets focus (clicked on). You can remove this behavior by adding outline: none; to the input.
Use the :focus selector to do something with the input field when it gets focus:
Example
Example
Input with icon/image
If you want an icon inside the input, use the background-image property and position it with the background-position property. Also notice that we add a large left padding to reserve the space of the icon:
Example
input[type=text] <
background-color: white;
background-image: url(‘searchicon.png’);
background-position: 10px 10px;
background-repeat: no-repeat;
padding-left: 40px;
>
Animated Search Input
In this example we use the CSS transition property to animate the width of the search input when it gets focus. You will learn more about the transition property later, in our CSS Transitions chapter.
Example
input[type=text] <
transition: width 0.4s ease-in-out;
>
input[type=text]:focus width: 100%;
>
Styling Textareas
Tip: Use the resize property to prevent textareas from being resized (disable the «grabber» in the bottom right corner):
Example
textarea <
width: 100%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
resize: none;
>
Styling Select Menus
Example
select <
width: 100%;
padding: 16px 20px;
border: none;
border-radius: 4px;
background-color: #f1f1f1;
>
Styling Input Buttons
Example
input[type=button], input[type=submit], input[type=reset] <
background-color: #04AA6D;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
>
/* Tip: use width: 100% for full-width buttons */
For more information about how to style buttons with CSS, read our CSS Buttons Tutorial.
Responsive Form
Resize the browser window to see the effect. When the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other.
Advanced: The following example uses media queries to create a responsive form. You will learn more about this in a later chapter.
Aligned Form
An example of how to style labels together with inputs to create a horizontal aligned form:
How to Create a Coloured («Colored») Box in HTML/CSS
How to put text into a box that has a background colour
How to Create a Coloured («Colored») Box in HTML/CSS
I was asked by a visitor how he could create a box, give it a background colour («color» if you use a different variant of English), and insert text in it, the way some printed magazines and books sometimes place additional information in a separate box or panel on a page.
Prerequisites
This article assumes that you know a bit of HTML and CSS. Otherwise you will be at a loss as to where to put the code I supply below or how to adapt it for your purpose.
Creating a Coloured Box
The box itself can be any block tag in HTML. Many, if not most, webmasters use a for this purpose.
Let’s say that you have the following HTML snippet that you want to make into a box.
The CSS to give the DIV block a background colour is, predictably:
The background-color rule above specifies the HTML colour value of #cfc . You can of course use any other colour you like. Most web editors and plain text editors (other than the rudimentary Notepad that comes with Windows) have a colour picker, allowing you to visually select a colour to get the appropriate numerical value. Alternatively, if you prefer to do things the hard way, you can also consult the list of colours and their values on Wikipedia.
Unfortunately, although the above code is correct, if you use it as it stands, you will find that the background colour will hug the text you place very closely, causing the entire thing to seem barely like a box. To make things more box-like, you will probably want to add some space to the area around your text, and perhaps even give it a border.
The padding rule adds 10 pixels to the space between your text and the margins of the box, and the border rule creates a 1-pixel thick solid green border. You can of course change the values given here (ie, the number of pixels and the colour) to suit your page’s design.
If you’re posting to a blog that allows you to insert HTML, but does not make it easy for you to change the style sheet, you can even put those rules into your DIV tag.
Demo
The above code produces the following box.
This is a demo box to illustrate the code given in thesitewizard.com’s tutorial on creating coloured boxes.
Browser Compatibility
The CSS given above should work in all current browsers. It will probably even work in most older browsers too, including Internet Explorer 6 (which is most likely extinct today).
Copyright © 2017-2018 Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from https://www.thesitewizard.com/.
thesitewizard™ News Feed (RSS Site Feed)
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
Please Do Not Reprint This Article
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
Related Articles
New Articles
Popular Articles
How to Link to This Page
It will appear on your page as:
Copyright © 2017-2018 Christopher Heng. All rights reserved.
thesitewizard™, thefreecountry™ and HowToHaven™ are trademarks of Christopher Heng.
This page was last updated on 20 December 2018.
Create Colored Boxes
Have you ever landed on a website for the very first time which is all the same color?
How hard is it to find the most important content on that page?
On your own site you know where everything is but put yourself in your readers shows for a minute.
Around 80% of visitors to your site are new.
They have never seen your site before and when they leave, most will never come back.
So make it easy for them and more will come back.
One way to attract your readers attention is to use colored boxes. You can create colored boxes by creating shortcodes or using pure CSS code.
Invalid Short Codes & CSS
Highlight your most important: content, links and calls to action using colored boxes.
But this can cause a massive problem down the track for you.
The reason for this is most themes include this feature built into the core files.
When you change themes, you end up with invalid shortcodes, css code or html that doesn’t work.
This can be a nightmare to remove manually.
Invalid code will also look ugly, unprofessional and worst of all, the content you highlighted to grab your readers attention, is no longer highlighted.
This is called theme lock and sometimes used to try and lock you into staying with the same theme developer.
3 Ways to Make Colored Boxes
The solution to this is to either:
- Install a plugin with shortcodes which moves with you from theme to theme.
- Using CSS only – Insert a small code block into your child themes css file which works on all themes.
- Using CSS and php to create shortcodes for colored boxes.
Using Pure CSS Code
Here’s some code which you can easily paste into your child themes style.css file.
You can easily edit this code to change:
- The background color – background: #eee ;
- The border color – border: 1px solid #ddd ;
- The border thickness – 1px solid
- The padding between your text and the border – padding: 10px ;
- Create different types of boxes ( .alert, .note, .info) – .alert
Once you’ve created different colored boxes and styled them, simply wrap your content using this code in your HTML editor.
If you want 3 types of boxes, simply use the code block above and name them:
- .note – Use this to make a note box
- .alert – Use this to make an alert box
- .info – Use this to create an info box
Different themes use different code for displaying boxes
- Woo themes uses shortcodes built into the framework
- Genesis doesn’t offer any code built into the core files so you’ll need to install a plugin or use the code above.
- Thesis uses this code which won’t work in Genesis or StudioPress themes
Creating Shortcodes for Boxes
You can also create great looking boxes using shortcodes which won’t break when you move themes.
Add some PHP code and css to your files like this. Learn more about how to create short codes in WordPress to make colored boxes in my next post.
Difference Between Shortcodes & CSS
Shortcodes will enable you to include content with paragraphs within your colored boxes.
Pure CSS will only allow you to wrap the content within one paragraph.
Changing Themes Without Breaking Code
One of the big advantages of adding the code above is that you may find your old boxes start working again.
This depends on which theme you where using previously but in my case it worked after moving from Thesis.
If you do use code like this which is flexible, you won’t suffer any problems when you change themes.
How about yourself, what do you use to draw attention to your most important content?
Reader Interactions
Leave a Reply Cancel reply
You must be logged in to post a comment.
Primary Sidebar
Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…