Css colored text boxes

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.

This is a demo box to illustrate the code given in thesitewizard.com’s tutorial on creating coloured boxes.

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.

New Articles

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.

Источник

How to Create a Colored Text Box in WordPress

Beginner Income

How to Create a Colored Text Box in WordPress

We all know writing good content is hard.

But you also need to make it as visually appealing as possible if you want the most people to read that content.

Enter colored text boxes:

Sprucing up your wordpress content with content color boxes adds a nice touch to your content…

…and since most bloggers and website owners aren’t doing it, you can really set yourself and your content apart from the crowd.

Step 1: Creating a Colored Text Box with HTML

Head over to the piece of content that you want to add your colored text box to.

You need to go to the “Text” tab of the wordpress text editor since you’ll be entering some code.

text editor text tab in wordpress

Now find the sentence/text or whatever else you want your colored text box to contain.

From here, add this to the beginning of your text/sentence:

Now add this to the end of that text/sentence:

For example, I’m going to create a text box around the sentence:

And here’s what it will look like:

Note: you can name the part between the quotes to whatever you want; so it could be “redbox” or “bluebox” or “colorthing”.

Again, just make sure you’re doing this in the text editor and not the visual editor of the wordpress post editor.

text editor text tab in wordpress

So at this point if you were to preview your post you’d notice that nothing happens to the sentence that you’ve just wrapped in your colorbox code.

This is because we need to tell our website what that color box is supposed to look like.

Step 2: Styling our Colored Text Box with CSS

You’ll now need to head over to your preferred means of adding CSS to your website.

That will likely either be through your child themes style.css sheet located in Appearance>Editor…

…or through the use of a custom css plugin like Simple Custom CSS…

…or by going to Appearance>Customize>Additional CSS in your wordpress dashboard.

If you don’t have a preferred way, we’re going to go to Customize>Additional CSS (available for all wordpress versions 4.4 or later).

However, before you do that it’s better if we can open the Customize option panel directly on the post we’re adding the colorbox to.

So press the “preview” button on the post you’re adding the colored box to in order to preview your post, which should open it up in a new window.

From here, press the customize option located at the top in the admin bar:

customize in wordpress admin bar

And then click on Additional CSS within the customize options:

additional css in customize

Otherwise, save the post as private and navigate to it after going to Appearance>Customize.

The point is that you just want to be in Customize>Additional CSS page while having the post containing the color box up on your screen.

The reason is because it will allow you to preview CSS changes in real-time.

Next, we need to add this code into our Additional CSS:

Remember to change the “#colorbox” part to whatever you named your color box before; so if you named it “redbox” you’d put “#redbox” instead.

Now, between these brackets you need to add the specifics of how you want to style your box.

Here’s what you probably want to do:

Adding “background-color: #dff8ec;” will make the box have color:

Note: You can find the hex numbers for different colors by going to a place like Color Hex or Adobe.

Okay, so this doesn’t look so great. And we’re going to add some padding to fix that.

Here’s what it looks like now:

If you want to center the text inside the box, you can do it as you normally would with any text: by highlighting the text in the visual editor tab of the post editor and pressing the align center button.

If your color box is appearing to close the the text that follows it in your articles you can add “margin-bottom: 25px;” to fix that:

Of course, change the “25px” to whatever you want.

One other styling option worth mentioning is adding a border:

This is achieved by adding “border: 3px solid #888;”.

#colorbox <
background-color: #dff8ec;
padding: 20px 30px 20px 30px;
margin-bottom: 25px;
border: 3px solid #888;
>

Where 3px is the thickness of the border; solid means it’s a solid line; and #888 is the color.

If you saw my post on how you can make passive income, you’ll see that I made a really thick border so my color box looked like it was inside another color box.

If we apply that idea to our green box, by setting the “border: 3px solid #888;” to “15px” instead of “3px” we get a similar effect:

The last thing I want to mention is making the box look rounder.

We can achieve this by adding “border-radius: 5px;”.

#colorbox <
background-color: #dff8ec;
padding: 20px 30px 20px 30px;
margin-bottom: 25px;
border: 3px solid #888;
>

That’s It

And now you can decorate all of your posts in as many colored boxes as you want.

Add these into your content to keep it interesting and your visitors will love it.

Jack and Chelsea are the creators of Beginner Income; a blog about online income and earning money passively, so you can quit your day job and gain financial freedom. For the past 5 years, we’ve created blogs, websites, online stores, and other side hustles, which have allowed us to quit our day jobs and work for ourselves from home.

Источник

Оцените статью