Create search button like twentyfourteen theme

Asked

Viewed 791 times

0

I need to create a search button like the one in the theme twentyfourteen. How can I do?

  • What button exactly @Rafaelabublitz?

  • The search button.

  • @Rafaelabublitz, is this what you’re looking for? http://jsfiddle.net/9qnayd5u/

  • No, Tobymosque. It’s just like the example below @Samueldiogo. But I can’t implement it in my project.

  • Good night. Please do not edit the title to mark as solved, select the desired answer and click the "check" button below the points to choose the correct one, If you have managed to solve it yourself then you can answer your question yourself and after two days you can click the check button. Thank you for understanding

1 answer

1


See how simple jquery commands and use of css can help:

When the user clicks on the search button, it displays the search form..

See an example in practice:

$( "#btn-search" ).click(function() {
  $("#search-wrapper").toggle();
  $("#search-wrapper").addClass("active");
});
.principal{
  width: 200px;
  }

#search-wrapper{
  display: none;
  text-align: right;
  width: 100%;
  }

#txt-search{
  border: none;
  margin:5px 3px;
  width: 30%;

}
.active{
  background-color: green;
  color: white;
 }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="principal">
<nav class="text-right">
	<a>home </a> | 
	<a id="btn-search"><i class="glyphicon glyphicon-search"></i> search</a>
</nav>
<div id="search-wrapper">
	<form>
		search here: <input type="search" id="txt-search" name="txt-search">

	</form>
</div>
</div>

You saw that by default, the search form container was declared in css with display: None, soon it will only appear, if, the user clicks on the button, so the function toggle() alternate from show or Hide as the user clicks..

I hope I’ve helped :)

  • Samuel, I tested the code that you gave me, but for some reason, Search is not being a link and clicking nothing happens. I put: #btn-search { cursor: Pointer;} but still, when clicking, the action is not working. You know what can be?

  • This is the link to the page where I am trying to enter the code: http://oye-magazine.com/teste/back-to-the-past/

  • @Rafaelabublitz, put the script that calls jquery in the first place! main.js sjquery that has not yet been defined..

  • I put the code in http://codepen.io/anon/pen/MYGXer and it works normally. But when I put exactly the same code in wordpress, it does not work.

  • Hi @Rafaelabublitz, by what I’m seeing via develper Tools of Chrome (F12 key) on your site, there are 5 javascript errors, and it seems to me that this is related to setting or the way masonry is stacked, since it has an error, it does not run the subshot commands... Debug your site identify what may be happening.. bjs

  • 1

    I managed to. Thank you so much for your help.

  • 1

    @Rafaelabublitz If this answer solved your problem, you can mark her as accepted? Or even post your own solution.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.