I am having a big issue currently with my website : http://www.onetechsearch.com/recipes/?search=&images=1&from=&to=&cat=all.
What I am trying to do is to have my search bar, and under that to have my "extra search", and no matter how I try the extra search won't go under the normal search.
And I would like to make the extra fade-in and out when a button next to search is pressed, any clue how I can do that?
<style type="text/css">
#picture-side {
display: inline-block;
float:left;
z-index: 8;
text-align:center;
}
#picture-side1 {
display: inline-block;
float:left;
z-index: 9;
text-align:center;
}
.width-container {
max-width:1180px;
margin:0 auto;
position:relative;
}
#topbar {
background:#f2f2f2;
padding:15px 0 0 0;
min-height:70px;
position:fixed;
top:0;
z-index:998;
box-sizing: border-box;
width:100%;
box-shadow: 0 2px 10px #000;
}
#search input#sfield{
margin:0;
width:54%;
padding:0 10px;
font:normal 16px Arial, sans-serif;
border:none;
float:left;
border-radius:5px 0 0 5px;
box-shadow: 0 0 4px #444;
#picture-side2 {
display: inline-block;
float:left;
z-index: 10;
}
input[type="radio"]:checked+label{ border-bottom: 5px solid lime; }
.site-wrap {
display: none;
}
#picture {
visibility: hidden;
}
#picture2 {
visibility: hidden;
}
#video {
visibility: hidden;
}
</style>
<?php if(is_front_page() & 0){ ////////////////////ONLY ON FRONTPAGE///////////////////////?>
<ul id="side_cat" class="navigation">
<?php
global $client;
$categs = $client->getResult('*:*', "", 0, 1);
//$count = count($categs[0]['category_f']) > 20 ? 20 : count($categs[0]['category_f']);
$nCategs = $client->getResponse()->facet_counts->facet_queries;
$count = count((array)$nCategs);
foreach ($cat2 as $k => $v) {
$cat2[$k] = strtolower($v);
}
$categs_n = array();
$categs_v = array();
foreach ($nCategs as $k => $v)
{
$categs_v[] = $v;
$categs_n[] = $k;
}
$j = 0;
$newC = array();
for ($i= 0; $i < $count; $i++) {
/* foreach ($cat as $cat){ */
if (in_array($categs_n[$i], $cat2) && $j < 30 ) {
$j++;
$newC[] = ucfirst($categs_n[$i]); ?>
<?php }
}
foreach ($newC as $categ)
{ ?>
<li class="nav-item"><?php echo ucwords($categ); ?></li>
<?php
}
?>
</ul>
<input type="checkbox" id="nav-trigger" class="nav-trigger">
<label for="nav-trigger"></label>
<?php } else { ////////////////////OTHER PAGES///////////////////////?>
<?php }?>
<script src="jquery-1.8.0.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var cat= ["C"];
$("#cat").select2({
data: cat
});
});
</script>
<div id="topbar">
<div class="width-container">
<h1><?php bloginfo('name'); ?></h1>
<div id="search">
<form action="<?php bloginfo('url');?>/recipes" method="GET" id="searchF">
<?php
$searched_term = get_query_var('recipe_search');
if (empty($searched_term)) {
$searched_term = isset($_GET["search"]) ? $_GET["search"] : "";
}
?>
<input id="sfield" type="text" name="search" placeholder="keywords" <?php if (!empty($searched_term)) {echo 'value="'.$searched_term.'"';} ?>>
<input type="submit" value="Search">
</div>
</div>
<div id="extra-search" div style="display:flex;justify-content:center;align-items:center;z-index:-9000" >
<div id="picture-side">
<input type="radio" name="images" value="1" id="picture"
<?php if(isset($_GET["images"]) && $_GET["images"]=='1'){ echo 'Checked';} ?>><label for="picture">With Pictures</label>
</div>
<div id="picture-side1">
<input type="radio" name="images" value="0" id="picture2"
<?php if(isset($_GET["images"]) && $_GET["images"]=='0'){ echo 'checked';} ?>><label for="picture2">Without Pictures</label>
</div>
<div id="picture-side2">
<input type="radio" name="images" value="0" id="video"
<?php if(isset($_GET["video"]) && $_GET["video"]=='1'){ echo 'checked';} ?>><label for="video">With video</label>
</div>
<div id="time-side">
<!--<small>Published time</small>-->
<input type="text" id="from-side" name="from" placeholder="Start date"
</div>
<select id="cat" name="cat">
<option value="all" selected>All categories</option>
<option value="HI">Hawaii</option>
<option value="C">Hawaji</option>
</select>
</div>
</form>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
console.log(1);
jQuery("#searchF").submit( function(event) {
console.log($("#cat :selected").val());
var bAction = "<?php bloginfo('url');?>";
bAction = bAction + "/recipes/category/" + $("#cat :selected").val();
jQuery("#searchF").find('#cat').attr('disabled', true);
jQuery(this).attr('action', bAction);
});
});
</script>
Just remove the float: left; on #search in the CSS.
Changes to make it work:
#topbar h1 - set width:
width: 100%;
#extra-search - set only those styles:
position: relative;
float: left;
max-width: 1180px;
margin: 0 auto;
if you want to take advantage of display:flex - just put another div inside of extra-search.
Related
I was wondering if you could help me with a problem that I’m having in realizing my business’ website.
As you can see in my code I already created 6 select options, but I want to make sure that the second select option (and then the third etc.) appears only when I put a value on the first select option and I don’t know how to do it right now.
Here is my code:
<div class="case-item">
<div class="container">
<h2 class="title title--h3">I tuoi canotti</h2>
<br>
<div class="row">
<div class="col-md-4">
<div class="row">
<div class="col-md">
<select name="users" id="canotto1" onchange="Canotto(this.value,'Canotto1');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a
style="
background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1;"
onclick="EliminaCanotto('Canotto1');">Elimina</a>
</div>
</div>
<br>
<div id="mostra2">
<div class="row">
<div class="col-md">
<select name="users" id="canotto2" onchange="Canotto(this.value,'Canotto2');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a
style="
background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1;"
onclick="EliminaCanotto('Canotto2');">Elimina</a>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<select name="users" id="canotto3" onchange="Canotto(this.value,'Canotto3');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a
style="
background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1;"
onclick="EliminaCanotto('Canotto3');">Elimina</a>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<select name="canotto1" id="canotto4" onchange="Canotto(this.value,'Canotto4');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a
style="
background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1;"
onclick="EliminaCanotto('Canotto4');">Elimina</a>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<select name="canotto5" id="canotto5" onchange="Canotto(this.value,'Canotto5');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a
style="
background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1;"
onclick="EliminaCanotto('Canotto5');">Elimina</a>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<select name="canotto6" id="canotto6" onchange="Canotto(this.value,'Canotto6');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a
style="
background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1;"
onclick="EliminaCanotto('Canotto6');">Elimina</a>
</div>
</div>
</div>
<div class="col-sm-1">
</div>
<div class="col-md-7">
<div id="txtHint"></div>
</div>
</div>
</div>
</div>
This is the code of the ajax:
<script> function Canotto(str , can) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { var id = <?php echo $_GET['id'] ?>; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txtHint").innerHTML = this.responseText; } }; xmlhttp.open("GET","Plenum_inserimentoCanotti.php?q=" + str + "&id=" + id + "&can=" + can ,true); xmlhttp.send(); } } </script>
As you have not added any Javascript we do not know what the function Canotto actually does - does it send an ajax request, do a lookup in an array/json, create content dynamically or other! So - with a minor tweak to the HTMl so that each select menu has a unique dataset attribute - data-id you can look ahead/behind using a couple of simple sibling selector type functions ( findnextselect and findpreviousselect ) to identify the next/previous select menus and set a display property on these found nodes.
Perhaps it'll give an idea how to proceed
document.addEventListener('DOMContentLoaded',()=>{
let col=document.querySelectorAll('select.canotto');
const findnextselect=(n,expr)=>{
let s=n.nextElementSibling;
while(s){
if(s.matches(expr))return s;
if(s.tagName.toLowerCase()=='body')return false;
s=s.nextElementSibling;
}
}
const findpreviousselect=(n,expr)=>{
let s=n.previousElementSibling;
while(s){
if(s.matches(expr))return s;
if(s.tagName.toLowerCase()=='body')return false;
s=s.previousElementSibling;
}
}
const changehandler=function(e){
let i=Number(this.dataset.id);
let n=findnextselect(this,'select.canotto');
let p=findpreviousselect(this,'select.canotto');
if( n && Number( n.dataset.id ) >= i )n.classList.add('active');
};
col.forEach(sel=>{
sel.addEventListener('change',changehandler)
})
})
select.canotto{display:none;padding:0.5rem;margin:0.5rem}
select.canotto:first-child{display:block}
.active{display:block!important}
<select class='canotto' data-id=1 name='users'>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select>
<select class='canotto' data-id=2 name='users'>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select>
<select class='canotto' data-id=3 name='users'>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select>
<select class='canotto' data-id=4 name='users'>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select>
Here is what I believe you are looking for. After each canotto1 is clicked, conotto2 is opened and so on.
The code lacked IDS and there were many unecessary element such as onchange. The styling was bad, I used an ID to pass the styling to each that had that ID.
If you had a clean code, the javascript could have been much shorter and not repeated and you could even use jQuery.
But the code below get the job done.
Tested and works.
<!DOCTYPE html>
<html>
<head>
<title>Hide Show</title>
</head>
<body>
<style>
#style-select { background-color: #cc0000;
border-radius: 10px;
border: 0;
color: #fff;
cursor: pointer;
font-size: 0.8rem;
font-weight: 400;
line-height: inherit;
text-transform:uppercase;
overflow: hidden;
padding: 0.4rem 0.6rem;
position: relative;
transition: .4s ease-in-out;
white-space: nowrap;
z-index: 1; }
</style>
<div class="case-item">
<div class="container">
<h2 class="title title--h3">I tuoi canotti</h2>
<br>
<div class="row">
<div class="col-md-4">
<div class="row">
<div class="col-md">
<select name="users" id="canotto1">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a id="style-select"
onclick="hideShowFeature()">Elimina</a>
</div>
</div>
<br>
<div id="mostra2">
<div class="row">
<div class="col-md">
<select name="users" id="canotto2">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a id="style-select"
onclick="hideShowFeature2()">Elimina</a>
</div>
</div>
</div>
<br>
<div class="row" id="mostra3">
<div class="col-md">
<select name="users" id="canotto3">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a id="style-select"
onclick="hideShowFeature3()">Elimina</a>
</div>
</div>
<br>
<div class="row" id="mostra4">
<div class="col-md">
<select name="canotto1" id="canotto4" onchange="Canotto(this.value,'Canotto4');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1" >
<a id="style-select"
onclick="hideShowFeature4()">Elimina</a>
</div>
</div>
<br>
<div class="row" id="mostra5">
<div class="col-md">
<select name="canotto5" id="canotto5" onchange="Canotto(this.value,'Canotto5');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a id="style-select"
onclick="hideShowFeature5()">Elimina</a>
</div>
</div>
<br>
<div class="row " id="mostra6">
<div class="col-md">
<select name="canotto6" id="canotto6" onchange="Canotto(this.value,'Canotto6');">
<?php echo $opt->Canotti(); ?>
</select>
</div>
<div class="col-md-1">
<a id="style-select"
>Elimina</a>
</div>
</div>
</div>
<div class="col-sm-1">
</div>
<div class="col-md-7">
<div id="txtHint"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function hideShowFeature() {
if (document.getElementById("canotto1").checked = true) {
document.getElementById("mostra2").style.display = "block";
document.getElementById("mostra3").style.display = "none";
document.getElementById("mostra4").style.display = "none";
document.getElementById("mostra5").style.display = "none";
document.getElementById("mostra6").style.display = "none";
}
}
function hideShowFeature2() {
if (document.getElementById("canotto2").checked = true) {
document.getElementById("mostra2").style.display = "block";
document.getElementById("mostra3").style.display = "block";
document.getElementById("mostra4").style.display = "none";
document.getElementById("mostra5").style.display = "none";
document.getElementById("mostra6").style.display = "none";
}
}
function hideShowFeature3() {
if (document.getElementById("canotto3").checked = true) {
document.getElementById("mostra2").style.display = "block";
document.getElementById("mostra3").style.display = "block";
document.getElementById("mostra4").style.display = "block";
document.getElementById("mostra5").style.display = "none";
document.getElementById("mostra6").style.display = "none";
}
}
function hideShowFeature4() {
if (document.getElementById("canotto4").checked = true) {
document.getElementById("mostra2").style.display = "block";
document.getElementById("mostra3").style.display = "block";
document.getElementById("mostra4").style.display = "block";
document.getElementById("mostra5").style.display = "block";
document.getElementById("mostra6").style.display = "none";
}
}
function hideShowFeature5() {
if (document.getElementById("canotto5").checked = true) {
document.getElementById("mostra2").style.display = "block";
document.getElementById("mostra3").style.display = "block";
document.getElementById("mostra4").style.display = "block";
document.getElementById("mostra5").style.display = "block";
document.getElementById("mostra6").style.display = "block";
}
}
</script>
<style>
#mostra2 {
display:none;
}
#mostra3 {
display:none;
}
#mostra4 {
display:none;
}
#mostra5 {
display:none;
}
#mostra6 {
display:none;
}
</style>
</body>
</html>
I want to add a slider in the form tag. Right now all the pictures are together. i want to make it more user friendly. As you can see in my code i'm fetching all images from database. And i've override the input radio button on each image so that the user can select its image.
I've already tried to use the Slick library but its not good.
<style type="text/css">
/*
html, body {
margin: 0;
padding: 0;
}
*/
* {
box-sizing: border-box;
}
.slider {
width: 50%;
margin: 100px auto;
}
.slick-slide {
margin: 0px 20px;
}
.slick-slide img {
width: 100%;
}
.slick-prev:before,
.slick-next:before {
color: black;
}
.slick-slide {
transition: all ease-in-out .3s;
opacity: .2;
}
.slick-active {
opacity: .5;
}
.slick-current {
opacity: 1;
}
.img{
width: 10%;
}
</style>
<style media="screen">
.input-hidden {
position: absolute;
left: -9999px;
}
input[type=radio]:checked + label>img {
border: 1px solid #fff;
box-shadow: 0 0 3px 3px #090;
}
input[type=radio]:checked + label>img {
transform:
rotateZ(-10deg)
rotateX(10deg);
}
/* Stuff after this is only to make things more pretty */
input[type=radio] + label>img {
width: 115px;
height: 115px;
transition: 500ms all;
}
* {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<form action="preview.php" method="post" >
<?php
$result_model = mysqli_query($conn, "SELECT * FROM model ORDER BY id DESC ");
$result_metal = mysqli_query($conn, "SELECT * FROM metal ORDER BY id DESC ");
$result_stone = mysqli_query($conn, "SELECT * FROM stone ORDER BY id DESC "); ?>
<div >
<div class="input-group">
<p>Choose your Model:</p>
</div>
<div class="regular slider">
<?php
while($model = mysqli_fetch_assoc($result_model)){
?>
<!-- <input type="radio" name="model" id="model<?= $model['id'] ?>" class="input-hidden" value="<?= $model['id'] ?>" />-->
<!--
<label for="model<?= $model['id'] ?>">
-->
<img
src="images/<?= $model['image'] ?>"
alt="<?= $model['name'] ?>" style="width:50%;" />
<!-- </label>-->
<?php
}
?>
<!-- </div>-->
<!-- <br>-->
<div>
<!--
<div class="input-group">
<p>Choose your Metal:</p>
</div>
-->
<!--
-->
</div>
<br>
</div>
<div class="input-group">
<p>Choose your Metal:</p>
</div>
<div class="regular slider">
<?php
while($metal = mysqli_fetch_assoc($result_metal)){
?>
<!--
<input type="radio" name="metal" id="metal<?= $metal['id'] ?>" class="input-hidden" value="<?= $metal['id'] ?>" />
-->
<!-- <label for="metal<?= $metal['id'] ?>">-->
<img
src="images/<?= $metal['image'] ?>"
alt="<?= $metal['name'] ?>" />
<!-- </label>-->
<?php
}
?>
?>
<!-- </div>-->
<!-- <br>-->
<div>
<!--
<div class="input-group">
<p>Choose your Metal:</p>
</div>
-->
<!--
-->
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="./slick/slick.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).on('ready', function() {
$(".regular").slick({
infinite: true,
slidesToShow: 3,
slidesToScroll: 1
});
});
</script>
</div>
</form>
I found an example of star rating with input of type="radio".
It's fantastic, but I'd like something simpler. Instead of input of type="radio", use star rating with <span> example in demonstration (demo).
Of the following code
.holder {
height: 1%;
overflow: hidden;
position: relative;
left: 0;
}
.left {
float: left;
}
.rating {
border: none;
float: none;
display: block;
left: 0;
}
.rating>input {
display: none;
}
.rating>label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating>.half:before {
content: "\f089";
position: absolute;
}
.rating>label {
color: #ddd;
float: right;
}
/* Styles hover mouse stars. */
.rating>input:checked~label,
/* Show gold star when clicked */
.rating:not(:checked)>label:hover,
/* Hover current star */
.rating:not(:checked)>label:hover~label {
color: #FFD700;
}
/* Hover previous stars in list */
.rating>input:checked+label:hover,
/* Hover current star when changing rating */
.rating>input:checked~label:hover,
.rating>label:hover~input:checked~label,
/* Lighten current selection */
.rating>input:checked~label:hover~label {
color: #FFED85;
}
<!DOCTYPE html>
<html lang="" es>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- FontAwsome Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<script>
$(document).ready(function() {
$(document).on('submit', '#frm-rating', function() {
//Get form data.
var data = $(this).serialize();
//Ajax
$.ajax({
type: 'POST',
url: 'rating.php',
data: data,
success: function(data) {
$("#result-rating").html(data);
}
});
return false;
});
});
</script>
</head>
<body>
<form id="frm-rating" method="POST">
<div class="holder">
<div class="left">
<fieldset class="rating">
<input type="radio" id="star5" name="rating" value="5" /><label class="full" for="star5" title="Excellent - 5 stars"></label>
<input type="radio" id="star4half" name="rating" value="4.5" /><label class="half" for="star4half" title="very good - 4.5 stars"></label>
<input type="radio" id="star4" name="rating" value="4" /><label class="full" for="star4" title="All right - 4 stars"></label>
<input type="radio" id="star3half" name="rating" value="3.5" /><label class="half" for="star3half" title="All right - 3.5 stars"></label>
<input type="radio" id="star3" name="rating" value="3" /><label class="full" for="star3" title="Regular - 3 stars"></label>
<input type="radio" id="star2half" name="rating" value="2.5" /><label class="half" for="star2half" title="Regulate the evil - 2.5 stars"></label>
<input type="radio" id="star2" name="rating" value="2" /><label class="full" for="star2" title="wrong - 2 stars"></label>
<input type="radio" id="star1half" name="rating" value="1.5" /><label class="half" for="star1half" title="Very bad - 1.5 stars"></label>
<input type="radio" id="star1" name="rating" value="1" /><label class="full" for="star1" title="Painful - 1 star"></label>
<input type="radio" id="starhalf" name="rating" value="0.5" /><label class="half" for="starhalf" title="Waste of time - 0.5 stars"></label>
</fieldset>
</div>
</div>
<textarea name="opinion" placeholder="Write a comment..."></textarea>
<!-- We use the user's session to get their ID in value -->
<input type="hidden" name="user" value="1" />
<button type="submit">Submit Review</button>
</form>
<div id="result-rating">
<!-- Respuesta Ajax. -->
</div>
</body>
</html>
How can I create stars of the same characteristics in this code using only CSS and jQuery without using frameworks as Bootstrap or others?
<div id="rating" class="rating">
<span class="stars"></span>
<span class="stars"></span>
<span class="stars"></span>
<span class="stars"></span>
<span class="stars"></span>
</div>
Or this code:
<ul class="star-rating">
<li class="star-icon">☆</li>
<li class="star-icon">☆</li>
<li class="star-icon">☆</li>
<li class="star-icon half">☆</li>
<li class="star-icon full">☆</li>
</ul>
And by means of jQuery, get the selected values and send them to the database.
$(document).ready(function() {
$(document).on('submit', '#frm-rating', function() {
//Obtenemos datos form.
var data = $(this).serialize();
//Ajax
$.ajax({
type: 'POST',
url: 'rating.php',
data: data,
success: function(data) {
$("#result-rating").html(data);
}
});
return false;
});
});
The goal is to have simpler code optimized.
Example:
.star-icon {
color: #ddd;
font-size: 2em;
position: relative;
display: inline;
direction: rtl;
unicode-bidi: bidi-override;
}
.star-icon:before{
content: '\2605';
position: absolute;
left: 0;
}
.star-icon.full:before {
color: #fde16d;
content: '\2605';
position: absolute;
left: 0;
}
.star-icon.half:before {
color: #fde16d;
content: '\2605';
position: absolute;
left: 0;
width: 50%;
overflow: hidden;
direction: ltr;
}
.star-icon.half:after {
content: '\2605';
position: absolute;
right: 0;
width: 50%;
overflow: hidden;
}
.star-rating > li:hover,
.star-rating > li:hover ~li:before,
.star-rating > li:hover ~li:after
{
width: 100%;
color: #fde16d;
cursor: pointer;
}
<ul class="star-rating">
<li class="star-icon">☆</li>
<li class="star-icon">☆</li>
<li class="star-icon">☆</li>
<li class="star-icon half">☆</li>
<li class="star-icon full">☆</li>
</ul>
Now to know what rating the user has chosen through PHP and jQuery.
Something more dynamic.
<?php
function calculate_stars($max, $rating){
$full_stars=floor($rating);
$half_stars = ceil($rating-$full_stars);
$gray_stars = $max-($full_stars + $half_stars);
return array ($full_stars, $half_stars, $gray_stars);
}
function display_star($rating){
$output="";
$number_stars = calculate_stars(5,$rating);
$full = $number_stars[0];
$half = $number_stars[1];
$gray = $number_stars[2];
$output ='<ul class="star-rating">';
if($gray)
for ($i=0;$i<$gray;$i++)
{
$output .= '<li class="star-icon">☆</li>';
}
if($half){
$output .= '<li class="star-icon half">☆</li>';
}
if($full){
for($i=0; $i<$full;$i++)
{
$output .= '<li class="star-icon full">☆</li>';
}
}
$output .='</ul>';
return $output;
}
echo display_star(4.3);
exit;
?>
Source observe the first 3 videos explaining the theme.
I do not want to use JavaScript; I want it in jQuery.
HTML markup:
<ul class="c-rating">
<li class="c-rating__item rating is-active left" data-index="0"></li>
<li class="c-rating__item" data-index="1"></li>
<li class="c-rating__item left" data-index="2"></li>
<li class="c-rating__item" data-index="3"></li>
<li class="c-rating__item left" data-index="4"></li>
<li class="c-rating__item" data-index="5"></li>
<li class="c-rating__item left" data-index="6"></li>
<li class="c-rating__item" data-index="7"></li>
<li class="c-rating__item left" data-index="8"></li>
<li class="c-rating__item" data-index="9"></li>
</ul>
<input type="hidden" class="rank" />
I have created a custom jQuery plugin for this functionality where you need to pass childClass for child selector and inputClass for input tag selector.
var activeClassCount = 1;
$.fn.customStarRatings = function(obj) {
var wrapper = this;
var stars = obj.childClass;
var input = obj.inputClass;
$(wrapper).hover(function() {
activeClassCount = $(this).find('.rating').index() + 1;
}, function() {
var $this = $(this);
$this.find(stars).slice(1, activeClassCount).addClass('is-active');
$this.find(stars).slice(activeClassCount, 10).not('.rating').removeClass('is-active');
// console.log($this.find(stars).slice(activeClassCount, 4).not('.rating'))
});
$(stars).hover(function() {
$(this).prevAll(stars).add($(this)).addClass('is-active');
$(this).nextAll(stars).removeClass('is-active');
});
$(stars).click(function(event) {
$(".rating").removeClass("rating");
$(this).addClass('rating');
activeClassCount = $(this).index() + 1;
$(this).prevAll(stars).addClass('is-active');
if (input) {
$(input).val(($(this).index() + 1)/2);
console.log($(input).val(), activeClassCount)
}
});
}
Then you have to simply call this jQuery function when the DOM gets ready.
$(".c-rating").customStarRatings({
childClass: ".c-rating__item",
inputClass: ".rank"
});
PS The HTML markup is not confined to usage of <ul> and <li> tags only. All you need to do is call this custom function on the wrapper tag of ratings and input element.
CSS edits:
.c-rating {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
.c-rating__item {
-webkit-box-flex: 0;
-webkit-flex: 0 0 12px;
-ms-flex: 0 0 12px;
flex: 0 0 12px;
height: 24px;
background-position: -12px 0px;
background-image: url(stars.svg);
cursor: pointer;
}
.c-rating__item.left {
background-position: 0px 0px;
}
.c-rating__item.is-active,
.c-rating__item: hover {
background-position: -36px 0;
}
.c-rating__item.left.is-active,
.c-rating__item.left: hover {
background-position: -24px 0;
}
The jQuery call to this function remains the same. Check the working fiddle here.
everything worked out great until this morning but I can't find out what is causing this problem.
The problem:
I need a search bar on the right of my nav items but it doesn't want to go to the right side.
The HTML(PHP):
<!-- HEADER
================================================== -->
<header class="header-type-5">
<div class="background-header"></div>
<div class="slider-header">
<!-- Top of pages -->
<div id="top" class="<?php if($theme_options->get( 'header_layout' ) == 1) { echo 'full-width'; } elseif($theme_options->get( 'header_layout' ) == 4) { echo 'fixed3 fixed2'; } elseif($theme_options->get( 'header_layout' ) == 3) { echo 'fixed2'; } else { echo 'fixed'; } ?>">
<div class="background-top"></div>
<div class="background">
<div class="shadow"></div>
<div class="pattern">
<div class="container">
<div class="row">
<!-- Header Left -->
<div class="col-sm-4" id="header-left">
<?php if ($logo) { ?>
<!-- Logo -->
<div class="logo"><img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" /></div>
<?php } ?>
</div>
<!-- Header Right -->
<div class="col-sm-8" id="header-right">
<?php
$top_block = $modules->getModules('top_block');
if( count($top_block) ) {
foreach ($top_block as $module) {
echo $module;
}
} ?>
<?php echo $currency.$language; ?>
<!-- <i class="fa fa-user"></i> -->
<div class="links">
<a class="l-a" href="index.php?route=account/account">Mijn Account</a>
<a class="l-s" href="index.php?route=checkout/cart">Winkelwagen</a>
<a class="l-c" href="index.php?route=checkout/checkout">Afrekenen</a>
</div>
<?php echo $cart; ?>
</div>
</div>
</div>
<style>
.sexy_line {
height: 1px;
background: white;
background: -webkit-gradient(linear, 0 0, 100% 0, from(#222222), to(#222222), color-stop(50%, white));
}
</style>
<div class="sexy_line"></div>
<?php if($theme_options->get( 'megamenu_type' ) == 4 || $theme_options->get( 'megamenu_type' ) == 5 || $theme_options->get( 'megamenu_type' ) == 6 || $theme_options->get( 'megamenu_type' ) == 9 || $theme_options->get( 'megamenu_type' ) == 14 || $theme_options->get( 'megamenu_type' ) == 19 || $theme_options->get( 'megamenu_type' ) == 29) { ?>
<div class="container container-megamenu2">
<?php } ?>
<?php
$menu = $modules->getModules('menu');
if( count($menu) ) { ?>
<div class="megamenu-background">
<div class="">
<div class="overflow-megamenu container">
<?php
if(count($menu) > 1) echo '<div class="row mega-menu-modules">';
$i = 0;
foreach ($menu as $module) {
if($i == 0 && count($menu) > 1) echo '<div class="col-md-3">';
if($i == 1 && count($menu) > 1) echo '<div class="col-md-9">';
echo $module;
if(count($menu) > 1 && ($i == 0 || $i == 1)) echo '</div>';
if(count($menu) > 1 && $i == 1) echo '</div>';
$i++;
} ?>
</div>
</div>
</div>
<?php } elseif($categories) { ?>
<div class="megamenu-background">
<div class="">
<div class="overflow-megamenu container">
<div class="container-megamenu horizontal">
<div class="megaMenuToggle">
<div class="megamenuToogle-wrapper">
<div class="megamenuToogle-pattern">
<div class="container">
<div><span></span><span></span><span></span></div>
Navigation
</div>
</div>
</div>
</div>
<div class="megamenu-wrapper">
<div class="megamenu-pattern">
<div class="container">
<ul class="megamenu shift-up">
<?php foreach ($categories as $category) { ?>
<?php if ($category['children']) { ?>
<li class="with-sub-menu hover"><p class="close-menu"></p><p class="open-menu"></p>
<span><strong><?php echo $category['name']; ?></strong></span>
<?php } else { ?>
<li>
<span><strong><?php echo $category['name']; ?></strong></span>
<?php } ?>
<?php if ($category['children']) { ?>
<?php
$width = '100%';
$row_fluid = 3;
if($category['column'] == 1) { $width = '220px'; $row_fluid = 12; }
if($category['column'] == 2) { $width = '500px'; $row_fluid = 6; }
if($category['column'] == 3) { $width = '700px'; $row_fluid = 4; }
?>
<div class="sub-menu" style="width: <?php echo $width; ?>">
<div class="content">
<p class="arrow"></p>
<div class="row hover-menu">
<?php for ($i = 0; $i < count($category['children']);) { ?>
<div class="col-sm-<?php echo $row_fluid; ?> mobile-enabled">
<div class="menu">
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li><?php echo $category['children'][$i]['name']; ?></li>
<?php } ?>
<?php } ?>
</ul>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
<!-- Search -->
<div class="search_form">
<div class="button-search"></div>
<input type="text" class="input-block-level search-query" name="search" placeholder="<?php echo str_replace('...', '', $search); ?>" id="search_query" value="" />
<?php if($theme_options->get( 'quick_search_autosuggest' ) != '0') { ?>
<div id="autocomplete-results" class="autocomplete-results"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#search_query').autocomplete({
delay: 0,
appendTo: "#autocomplete-results",
source: function(request, response) {
$.ajax({
url: 'index.php?route=search/autocomplete&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item.name,
value: item.product_id,
href: item.href,
thumb: item.thumb,
desc: item.desc,
price: item.price
}
}));
}
});
},
select: function(event, ui) {
document.location.href = ui.item.href;
return false;
},
focus: function(event, ui) {
return false;
},
minLength: 2
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
});
</script>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
<?php if($theme_options->get( 'megamenu_type' ) == 4 || $theme_options->get( 'megamenu_type' ) == 5 || $theme_options->get( 'megamenu_type' ) == 6 || $theme_options->get( 'megamenu_type' ) == 9 || $theme_options->get( 'megamenu_type' ) == 14 || $theme_options->get( 'megamenu_type' ) == 19 || $theme_options->get( 'megamenu_type' ) == 29) { ?>
</div>
<?php } ?>
<?php
$menu2 = $modules->getModules('menu2');
if( count($menu2) ) {
echo '<div class="overflow-menu2">';
foreach ($menu2 as $module) {
echo $module;
}
echo '</div>';
} ?>
</div>
</div>
</div>
</div>
<?php $slideshow = $modules->getModules('slideshow'); ?>
<?php if(count($slideshow)) { ?>
<!-- Slider -->
<div id="slider" class="<?php if($theme_options->get( 'slideshow_layout' ) == 1) { echo 'full-width'; } elseif($theme_options->get( 'slideshow_layout' ) == 4) { echo 'fixed3 fixed2'; } elseif($theme_options->get( 'slideshow_layout' ) == 3) { echo 'fixed2'; } else { echo 'fixed'; } ?>">
<div class="background-slider"></div>
<div class="background">
<div class="shadow"></div>
<div class="pattern">
<?php foreach($slideshow as $module) { ?>
<?php echo $module; ?>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</header>
(The "search_form" div doesn't work)
The CSS part:
/* #group Search */
#media(max-width: 991px){
#top .search_form {
padding: 0px;
padding-top:0px;
vertical-align: top;
width: 100%;
position: absolute;
display: none;
}
#top .search_form input {
padding: 11px 35px 10px 20px;
margin: 0px;
height: 40px;
width: 230px;
font-size: 12px;
display: none;
}
.search_form .button-search,
.search_form .button-search2 {
font-family: FontAwesome;
position: absolute;
right: 45px;
top: 10px;
cursor: pointer;
font-size: 16px;
line-height: 16px;
font-weight: 400;
color: #333;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
display: none;
}
}
#top .search_form {
margin: 6px 26px 0px 0px;
padding: 0px;
display: inline-block;
vertical-align: top;
width: 170px;
position: absolute !important;
right:0px;
}
.header-type-2 #top .search_form {
width: auto !important;
max-width: 270px;
display: block;
}
#top .search_form input {
padding: 11px 35px 10px 20px;
margin: 0px;
height: 40px;
width: 230px;
font-size: 12px;
}
.search-type-2 #top .search_form input {
-webkit-box-shadow: inset 0px 2px 2px 1px rgba(0,0,0,0.06);
-moz-box-shadow: inset 0px 2px 2px 1px rgba(0,0,0,0.06);
box-shadow: inset 0px 2px 2px 1px rgba(0,0,0,0.06);
}
.search-type-3 #top .search_form input {
border-radius: 0px;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
}
.search-type-4 #top .search_form input {
border-radius: 8px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
}
.search-type-5 #top .search_form input {
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
}
.search-type-7 #top .search_form input {
border-radius: 2px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
}
.search-type-6 #top .search_form input {
-webkit-box-shadow: 1px 1px 2px 0px rgba(255, 255, 255, 0.04), inset 0px 3px 8px 3px rgba(0,0,0,0.3);
-moz-box-shadow: 1px 1px 2px 0px rgba(255, 255, 255, 0.04), inset 0px 3px 8px 3px rgba(0,0,0,0.3);
box-shadow: 1px 1px 2px 0px rgba(255, 255, 255, 0.04), inset 0px 3px 8px 3px rgba(0,0,0,0.3);
}
.search_form .button-search,
.search_form .button-search2 {
font-family: FontAwesome;
position: absolute;
right: 45px;
top: 10px;
cursor: pointer;
font-size: 16px;
line-height: 16px;
font-weight: 400;
color: #333;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.search_form .button-search:before,
.search_form .button-search2:before {
content: "\f002";
}
/* #end */
I hope someone knows what is causing this problem.
Thanks in advance
I am newbie in HTML and CSS. I need radiobutton which locates under div. Now there's a div and radiobutton to right of.
<div class="rates">
<? foreach ($rates as $rate) { ?>
<div class="rates-block" <? if ($rate->id % 4 != 1) { ?> style="margin-left: 48px;" <? } ?>>
<img src="/images/aukc_image/<?= $rate->img ?>" class="products-img rate-img" alt="product-1">
</div>
<input class="rate-radio" type="radio" name="radio1" value="<?= $rate->count ?>;<?= $rate->price ?>">
<? } ?>
</div>
There's my CSS for thats classes:
.rates {
margin-top: 19px;
}
.rates-block {
display: inline-block;
background-color: #FFFFFF;
width: 152px;
height: 154px;
border: 1px solid rgb(220, 220, 220);
margin-left: 101px;
}
.rate-radio {
display: inline-block;
}
Now I have this
But I need something like this
Try this:
.rates {
margin-top: 19px;
}
.product-wrapper{
display: inline-block;
background-color: #FFFFFF;
width: 152px;
margin-left: 50px;
}
.rates-block {
width: 100%;
height: 154px;
border: 1px solid rgb(220, 220, 220);
}
.rate-radio {
display: inline-block;
}
<div class="rates">
<div class="product-wrapper">
<div class="rates-block">
<img src="http://www.creativeprintpack.com/images/shoppingbag4.jpg" class="products-img rate-img" alt="product-1" style="width:100%">
</div>
<input class="rate-radio" type="radio" name="radio1" value="wewe">Rate 0</input>
</div>
<div class="product-wrapper">
<div class="rates-block">
<img src="http://www.creativeprintpack.com/images/shoppingbag4.jpg" class="products-img rate-img" alt="product-1" style="width:100%">
</div>
<input class="rate-radio" type="radio" name="radio1" value="wewe">Rate 1</input>
</div>
</div>
I have added a wrapper for each product/rate, which has the width set, the div containing the image is 100% width as the input aswell