Converting a CSS styled search box to use in a Drupal theme? - drupal

I'm using Drupal 6, working on converting my static HTML and CSS files into a Drupal theme. So far most has gone well. How would I theme the search form though for a Drupal 6 theme?
What I'm confused on is, do I use the template.php file in conjunction with the
search-theme-form.tpl.php file? Can I import my style.css sheet in the search-theme-form.tpl.php file? or can I actually just paste in my CSS directly?
I've uploaded the search box here so you can see how it behaves and looks. http://nside-elite.techiedesign.net/testsearchform/testsearchform.html
Here is my original CSS:
#searchwrap {
width: 330px;
height: 51px;
margin-right: auto;
position: relative;
margin-left: auto;
top: 150px;
}
#searchboxwrapper {
height: 28px;
float: left;
width: 277px;
}
#searchbuttonwrapper {
width: 53px;
height: 28px;
float: right;
}
.preload {
position: absolute;
top: 0px;
left: 0px;
width: 1px;
height: 1px;
visibility: hidden;
overflow: hidden;
}
.searchbox {
background-position: top;
background-color: #515151;
background-image: url('Images/searchbox-shadow.png');
border: 2px #333333 solid;
outline: none;
background-repeat: repeat-x;
height: 20px;
margin-right: 3px;
float: right;
margin-top: 1px;
width: 250px;
text-indent: 5px;
font-size: 10pt;
color: #1D1D1D;
font-style: italic;
font-family: Arial;
}
.searchbutton {
background: url('Images/go-button.png');
background-repeat: no-repeat;
cursor: pointer;
width: 53px;
height: 28px;
border: 0px;
}
.searchbutton:hover {
background: url('Images/go-button-gifsmooth.gif');
background-repeat: no-repeat;
border: 0px;
}
.searchbutton:active {
background: url('Images/go-button-pressed.png');
background-repeat:no-repeat;
border: 0px;
}
.searchbox:focus {
border: 2px;
border-color: #6B6B6B;
border-style: solid;
}
And HTML:
<div id="searchboxwrapper">
<input name="Text1" type="text" class="searchbox" value="Search Nside Elite" onfocus="if(this.value == 'Search Nside Elite'){this.value = '';this.style.fontStyle='normal';this.style.color='#BFBFBF';}" onblur="if(this.value == '') {this.value='Search Nside Elite';this.style.fontStyle='italic';this.style.color='#222222'}" />
</div>
<div id="searchbuttonwrapper">
<input name="searchbutton" type="button" value="" title="Search" class="searchbutton" />
</div>
No one at the Drupal forums would give me the time of day. I'd appreciate any help you can offer. I'm not familiar with PHP.
Thanks!

You definitely do use template.php, thats where you prepare the variables for print in the .tpl.php file. In this case you want to add a preprocess function onto the search_theme_form hook. To attach your new preprocess function to the theme hook write a function in template.php like this:
function MYTHEME_preprocess_search_theme_form(&$variables) {
//do stuff
}
You will want to clear cache before any changes show up. This is where you can add things to be printed on the template.
function MYTHEME_preprocess_search_theme_form(&$variables) {
$variables['whatever'] = 'hi there';
}
Later at the template you can call this by writing print $whatever; and it will print the value. Usually though, I don't change the search_theme_form.tpl.php so I don't bother redeclaring it in my theme and use drupal's default.
Here is an example of me adding my own preprocess function to search_theme_form in order to remove the stupid label on the form element as well as have the textfields default value disappear on focus.
function MYTHEME_preprocess_search_theme_form(&$variables) {
unset($variables['form']['search_theme_form']['#title']);
unset($variables['form']['search_theme_form']['#printed']);
$variables['form']['search_theme_form']['#value'] = 'Search';
$variables['form']['search_theme_form']['#attributes'] = array('onfocus' => "if (this.value == 'Search') {this.value = '';}" );
$variables['search']['search_theme_form'] = drupal_render($variables['form']['search_theme_form']);
$variables['search_form'] = implode($variables['search']);
}
I hope this answers some of your questions and points you in the right direction.

Related

Button moves down whenever I place text in it

I am trying to make a TicTacToe game as my first project and for some reason no matter what I do when I click one of the cells they go down a line and are not in the same row as the others.
this is an example
here is the css:
button {
width: 30%;
height: 200px;
text-align: center;
line-height: 0.85px;
cursor: pointer;
display: inline;
margin: 0px;
font-size: 14rem;
}
this is the typescript where I insert X and O in and the html where I present a button:
public place ()
{
if (this.reserved())
{
if(this.player==1)
{
this.xory = 'X'
this.player++
}
else
{
this.xory = 'O'
this.player--
}
}
}
<button (click) = "place()">{{xory}}</button>
I suggested to use as content of your empty boxes to compensate the alignment when the player didn't fill it with a choice.
By the way it was hard to say how you should initialize that value since you are using Angular.
So you can just opt for using the vertical-align:bottom; in your css rule as showed in this example:
button {
width: 30%;
height: 200px;
cursor: pointer;
text-align: center;
font-size: 10rem;
display: inline;
vertical-align: bottom;
margin: 0 0 3px 0;
padding: 0;
}
<button></button>
<button>O</button>
<button></button>
<button>X</button>
<button></button>
<button></button>
<button></button>
<button>O</button>
<button>X</button>

How to DIsable Image Caption on Hover in Wordpress

Sometimes ago I found a Site, URL is http://www.fun71.com i saw that when i bring mouse to the image than image cation is hide. can someone tells he how can i do this with my site ?
is is done by CSS or by Javascript ? If it is CSS than please code for me. my Friend Gives e CSS which is
.wp-caption .wp-caption-text {
font-size: 0.8em;
line-height: 17px;
margin: 0px;
width: 100%;
padding: 0px 0px 5px;
background-color: #FFF;
position: absolute;
bottom: 0px;
left: 0px;
opacity: 0.7;
}
but it is not working for me. plz help me
What worked for me:
Removing the image title visible on hover by adding this to the theme functions.php
// Title Removal from WordPress image
add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text');
function remove_image_text( $attr ) {
unset($attr['title']);
return $attr;
}
Source
if all your image captions have the wp-caption-text class then simply hide the text on hover as below.
.wp-caption .wp-caption-text {
font-size: 0.8em;
line-height: 17px;
margin: 0px;
width: 100%;
padding: 0px 0px 5px;
background-color: #FFF;
position: absolute;
bottom: 0px;
left: 0px;
opacity: 0.7;
display:block;
}
.wp-caption .wp-caption-text:hover{
display:none !important;
}

iPhone's spotlight-like box in html

I'm using IE 7 . can anyone suggest a simpler code for what I'm trying to do .
here's my html:
<span id="mainSpan" class="deleteIcon">
<input type="text" id="txt1" />
<span id="btn" onclick="var x = document.getElementById('txt1'); x.value = ''; x.focus();"></span>
</span>
and my css:
input {
font-size: 20px;
width: 250px;
}
#mainSpan {
position: relative;
border: 1px #aaa inset;
}
span.deleteicon span {
border: none;
margin-left: 1px;
position: absolute;
display: block;
top: 5px;
width: 18px;
height: 18px;
background: url('file:///path-to-clear.png') no-repeat center;
cursor: pointer;
}
span.deleteicon input {
border: none;
margin: 0px;
padding-right: 0px;
}
but it looks like this in IE 7:
i want to make it like the spotlight in an iPhone:
and do I need css or javascript if i want the 'clear' button to show up when cursor is in the box ? like this ..
it's easy to do it in other newer browsers but need to use it on IE 7 .
thanks for anyone who can share their code . =D
Try ccs3pie
It helps with ancient IEs. You'll be able to use border radius and other cool stuff.

How do you style the dropdown on Google Places Autocomplete API?

We need to tweak the styling of the dropdown that shows the autocomplete place suggestions when using the Google Places/Maps Autocomplete API.
Does anyone know if this is even possible? If so, I guess we just need to know the CSS classnames/IDs.
There's a screen grab of the bit I am referring to here:
This is now documented by google: https://developers.google.com/maps/documentation/javascript/places-autocomplete#style_autocomplete
If you use firebug (as mentioned in a comment to your question...) you see that the container with the autocomplete results is a DIV with the class "pac-container" and the suggestions are inside it as a DIV with the class "pac-item". so just style with CSS.
This CSS will allow the drop-down to resize to fit the width of the results:
.pac-container, .pac-item {
width: inherit !important;
}
It is pretty difficult to inspect the elements since it closes as soon as it loses focus.
Though we know that the container has the .pac-container class and items have .pac-item, upon further investigating the API I found that it embeds the CSS styles in the document.
Here's what initially there, so use it to change the pre-defined styles to fit your needs.
.pac-container {
background-color: #fff;
position: absolute!important;
z-index: 1000;
border-radius: 2px;
border-top: 1px solid #d9d9d9;
font-family: Arial, sans-serif;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
overflow: hidden
}
.pac-logo:after {
content: "";
padding: 1px 1px 1px 0;
height: 16px;
text-align: right;
display: block;
background-image: url(https://maps.gstatic.com/mapfiles/api-3/images/powered-by-google-on-white3.png);
background-position: right;
background-repeat: no-repeat;
background-size: 120px 14px
}
.hdpi.pac-logo:after {
background-image: url(https://maps.gstatic.com/mapfiles/api-3/images/powered-by-google-on-white3_hdpi.png)
}
.pac-item {
cursor: default;
padding: 0 4px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
line-height: 30px;
text-align: left;
border-top: 1px solid #e6e6e6;
font-size: 11px;
color: #999
}
.pac-item:hover {
background-color: #fafafa
}
.pac-item-selected,
.pac-item-selected:hover {
background-color: #ebf2fe
}
.pac-matched {
font-weight: 700
}
.pac-item-query {
font-size: 13px;
padding-right: 3px;
color: #000
}
.pac-icon {
width: 15px;
height: 20px;
margin-right: 7px;
margin-top: 6px;
display: inline-block;
vertical-align: top;
background-image: url(https://maps.gstatic.com/mapfiles/api-3/images/autocomplete-icons.png);
background-size: 34px
}
.hdpi .pac-icon {
background-image: url(https://maps.gstatic.com/mapfiles/api-3/images/autocomplete-icons_hdpi.png)
}
.pac-icon-search {
background-position: -1px -1px
}
.pac-item-selected .pac-icon-search {
background-position: -18px -1px
}
.pac-icon-marker {
background-position: -1px -161px
}
.pac-item-selected .pac-icon-marker {
background-position: -18px -161px
}
.pac-placeholder {
color: gray
}
I case anyone is interested in the hierarchy I was able to scrape the following using Firebug:
<div class="pac-container pac-logo" style="width: 557px; position: absolute; left: 66px; top: 106px; display: none;">
<div class="pac-item">
<span class="pac-icon pac-icon-marker"></span>
<span class="pac-item-query">
<span>France</span>
</span>
</div>
<div>
This worked for me, and now I can run this on mobile!
.pac-container {
z-index: 10000 !important;
width: auto !important;
position: initial !important;
left: 0 !important;
right: 0 !important;
display: block !important;
}
.pac-container:empty{
display: none !important;
}
And this somewhere!
$('selector').append('.pac-container');
Now the results will show in the selected div as a normal block element :)
To force the box to stay open for much easier styling and inspection from dev tools you can set the input value from the JS console and the container will stay open when inspecting from the dev tools.
Simply run document.querySelector('.pac-target-input').value = 'CB' in the console on your page with the input, then go back to the Elements tab and you can now individually inspect each element.
This gets around the issue where it always closes when focus is lost.
if you want to create your custom html & css then AutocompleteService class is also available which will provide all data in json.
const service = new google.maps.places.AutocompleteService();
service.getQueryPredictions(
{ input: "provide location string here for search" },
(suggestions) => console.log(suggestions)
);
For easier debugging and styling. to keep the dropdown open.
use the following code in chrome console.
document.querySelector('.pac-container').style.display = 'block'
Also used following classes to style the suggested dropdown in google places auto complete
Update icons
.pac-icon {
background-image: url('./assets/locationMark.svg') !important;
background-repeat: no-repeat;
background-position: 0 0;
background-size: 14px 18px;
}
Update text
.pac-item-query {
font-size: 16px
}
Hide google logo
.pac-logo {
padding: 10px 0;
&::after {
display: none;
}
}

How to change an input button image using CSS

So, I can create an input button with an image using
<INPUT type="image" src="/images/Btn.PNG" value="">
But, I can't get the same behavior using CSS. For instance, I've tried
<INPUT type="image" class="myButton" value="">
where "myButton" is defined in the CSS file as
.myButton {
background:url(/images/Btn.PNG) no-repeat;
cursor:pointer;
width: 200px;
height: 100px;
border: none;
}
If that's all I wanted to do, I could use the original style, but I want to change the button's appearance on hover (using a myButton:hover class). I know the links are good, because I've been able to load them for a background image for other parts of the page (just as a check). I found examples on the web of how to do it using JavaScript, but I'm looking for a CSS solution.
I'm using Firefox 3.0.3 if that makes a difference.
If you're wanting to style the button using CSS, make it a type="submit" button instead of type="image". type="image" expects a SRC, which you can't set in CSS.
Note that Safari won't let you style any button in the manner you're looking for. If you need Safari support, you'll need to place an image and have an onclick function that submits the form.
You can use the <button> tag. For a submit, simply add type="submit". Then use a background image when you want the button to appear as a graphic.
Like so:
<button type="submit" style="border: 0; background: transparent">
<img src="https://i.imgur.com/tXLqhgC.png" width="90" height="90" alt="submit" />
</button>
More info
div.myButton input {
background: url(https://i.imgur.com/tXLqhgC.png) no-repeat;
background-size: 90px;
width: 90px;
height: 90px;
cursor: pointer;
border: none;
}
<div class="myButton">
<INPUT type="submit" name="" value="">
</div>
This will work anywhere, even in Safari.
This article about CSS image replacement for submit buttons could help.
"Using this method you'll get a clickable image when style sheets are active, and a standard button when style sheets are off. The trick is to apply the image replace methods to a button tag and use it as the submit button, instead of using input.
And since button borders are erased, it's also recommendable change the button cursor to
the hand shaped one used for links, since this provides a visual tip to the users."
The CSS code:
#replacement-1 {
width: 100px;
height: 55px;
margin: 0;
padding: 0;
border: 0;
background: transparent url(image.gif) no-repeat center top;
text-indent: -1000em;
cursor: pointer; /* hand-shaped cursor */
cursor: hand; /* for IE 5.x */
}
#replacement-2 {
width: 100px;
height: 55px;
padding: 55px 0 0;
margin: 0;
border: 0;
background: transparent url(image.gif) no-repeat center top;
overflow: hidden;
cursor: pointer; /* hand-shaped cursor */
cursor: hand; /* for IE 5.x */
}
form>#replacement-2 { /* For non-IE browsers*/
height: 0px;
}
Here's a simpler solution but with no extra surrounding div:
<input type="submit" value="Submit">
The CSS uses a basic image replacement technique. For bonus points, it shows using an image sprite:
<style>
input[type="submit"] {
border: 0;
background: url('sprite.png') no-repeat -40px left;
text-indent: -9999em;
line-height:3000;
width: 50px;
height: 20px;
}
</style>
Source:
http://work.arounds.org/issue/21/using-css-sprites-with-input-type-submit-buttons/
Here is what worked for me on Internet Explorer, a slight modification to the solution by Philoye.
>#divbutton
{
position:relative;
top:-64px;
left:210px;
background: transparent url("../../images/login_go.png") no-repeat;
line-height:3000;
width:33px;
height:32px;
border:none;
cursor:pointer;
}
You can use blank.gif (a one-pixel transparent image) as the target in your tag:
<input type="image" src="img/blank.gif" class="button">
And then style background in CSS:
.button {border:0;background:transparent url("../img/button.png") no-repeat 0 0;}
.button:hover {background:transparent url("../img/button-hover.png") no-repeat 0 0;}
A variation on the previous answers:
I found that opacity needs to be set, of course this will work in Internet Explorer 6 and on. There was a problem with the line-height solution in Internet Explorer 8 where the button would not respond. And with this you get a hand cursor as well!
<div id="myButton">
<input id="myInputButton" type="submit" name="" value="">
</div>
#myButton {
background: url("form_send_button.gif") no-repeat;
width: 62px;
height: 24px;
}
#myInputButton {
background: url("form_send_button.gif") no-repeat;
opacity: 0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
width: 67px;
height: 26px;
cursor: pointer;
cursor: hand;
}
I think the following is the best solution:
CSS:
.edit-button {
background-image: url(edit.png);
background-size: 100%;
background-repeat: no-repeat;
width: 24px;
height: 24px;
}
HTML:
<input class="edit-button" type="image" src="transparent.png" />
My solution without JavaScript and without images is this:
HTML:
<input type=Submit class=continue_shopping_2
name=Register title="Confirm Your Data!"
value="confirm your data">
CSS:
.continue_shopping_2: hover {
background-color: #FF9933;
text-decoration: none;
color: #FFFFFF;
}
.continue_shopping_2 {
padding: 0 0 3px 0;
cursor: pointer;
background-color: #EC5500;
display: block;
text-align: center;
margin-top: 8px;
width: 174px;
height: 21px;
border-radius: 5px;
border-width: 1px;
border-style: solid;
border-color: #919191;
font-family: Verdana;
font-size: 13px;
font-style: normal;
line-height: normal;
font-weight: bold;
color: #FFFFFF;
}
Perhaps you could just import a .js file as well and have the image replacement there, in JavaScript.
Let's assume you can't change the input type, or even the src. You only have CSS to play with.
If you know the height you want, and you have the URL of a background image you want to use instead, you're in luck.
Set the height to zero and padding-top to the height you want. That'll shove the original image out of sight, giving you a perfectly clean space to show your CSS background-image.
It works in Chrome. I don't have any idea if it works in Internet Explorer. Barely anything clever does, so probably not.
#daft {
height: 0;
padding-top: 100px;
width: 100px;
background-image: url(clever.jpg);
}
<input type="image" src="daft.jpg" id="daft">

Resources