Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrap">
	<h1 class="pen-title">CSS Expanding Search Box</h1>
	<p class="pen-description">An expanding search box/form powered purely by CSS.</p>
	<!-- Begin Your Code -->
	
	<form method="get" class="search-form" action="#">
		<label for="search-field"><span class="screen-reader-text">To search this site, enter a search term</span></label>
		<input class="search-field" id="search-field" type="text" name="s" value="" aria-required="false" autocomplete="off" placeholder="Search&hellip;" />
		<button class="search-submit"><span class="screen-reader-text">Search</span><i class="fa fa-search"></i></button>
	</form>

	<!-- End Your Code -->
</div><!-- .wrap -->
              
            
!

CSS

              
                // Set some base styles on the search form
.search-form {
	display: inline-block;
	float: right;
	position: relative;
	width: 100%;
}

// Set height for the search form elements
.search-field,
.search-submit {
	height: rem(60);
}

// Style the search text input
.search-field {
	@include position(absolute, null 0 null null);
	@include transition (all 0.5s ease-in-out);
	
	background-color: transparent;
	border: none;
	border-bottom: 1px solid rgba($color-white,.5) !important; // Add an !important for CodePen because it's adding inline styles when focused
	box-sizing: border-box;
	color: rgba($color-white, .5);
	cursor: pointer;
	font-size: rem(36);
	font-weight: 300;
	opacity: 0;
	padding-right: rem(60);
	width: 0;
	z-index: 3;
	
	// When we focus on the text input, display it
	&:focus {
		cursor: text;
		opacity: 1;
		outline: none;
		width: 100%;
		z-index: 1;
		
		// When focused AND hovering the text input, do not alter the default styles of the search icon
		&:hover {

		~ .search-submit .fa-search {
				color: $color-white;
			}
		}
	}
	
	// When hovering the text input, adjust the color of the search icon
	&:hover {

		~ .search-submit .fa-search {
			color: lighten($color-white, 10%);
		}
	}
}

// Style the submit button
.search-submit {
	@include transition (all 0.2s ease-in-out);
	
	background-color: transparent;
	border: none;
	float: right;
	position: relative;
	width: rem(60);
	z-index: 2;
	
	// Adjust the color of the search icon on hover
	&:hover {
		
		.fa-search {
			color: lighten($color-white, 10%);
		}
	}
}

// Style our search icon
.fa-search {
	@include transition (all 0.2s ease-in-out);
	
	color: $color-white;
	font-size: rem(36);
}
              
            
!

JS

              
                
              
            
!
999px

Console