Select option in sequence - php

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>

Related

problem showing repeated whole page when trying to display data from database

I'm trying to display the data from the database, but whenever I connect it the whole page gets repeated - from the head title to a row and then it shows the head title again as if I had split the page, and another row from the database.
I want to show the data like the products page next to each other but it only shows one and then repeats the whole page.
This is my code that I tried - the page gets repeated from the main-container and shows one row, then repeats the main container again.
<?php
require_once 'opp_data.php';
$sql ="SELECT * FROM college_opp";
$allopp =$conn->query($sql);
?>
//i dont know if i have to show the whole code but this is only the code part where everything gets repeated
<?php
while ($row = mysqli_fetch_assoc($allopp)) {
?>
<div class="main-container">
<h2>تصفح الفرص التطوعية </h2>
<div class="post-collect">
<div class="post-main-container">
<div class="all sports">
<div class="post-img">
<img src="imgs/<?php echo $row["images"]; ?>">
<span class="category-name" data-name="sporty">كلية علوم الرياضة </span>
</div>
<div class="post-content">
<div class="post-content-top">
<span>
<i class="fa-solid fa-users-line"></i><?php echo $row["volunteer_num"]; ?>
</span>
<span><i class="fa-regular fa-calendar-days"></i><?php echo $row["Date"]; ?></span>
</div>
<h2>"<?php echo $row["Title"]; ?>"</h2>
<p>"<?php echo $row["Description"]; ?>"</p>
</div>
<div class="button-btn">
التفاصيل والتسجيل
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</body>
for the style.css\\
.main-container{
width: 90vw;
margin: 0 auto;
padding: 40px 0;
}
.main-container h2{
text-align: center;
padding: 90px 0;
font-size: 32px;
color: #fff;
}
.main-container p{
font-weight: 300;
padding: 10px 0;
opacity: 0.7;
text-align: center;
}
.post-main-container{
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 60px;
}
.post-main-container div{
box-shadow: 0px 8px 27px -12px rgba(0, 0, 0, 0.64);
}
.post-img{
position: relative;
width: 2vw;
height: 19vw;
}
.post-img img{
position: absolute;
left: 20px;
width: 17vw;
height: 19vw;
}
.post-content{
padding: 25px;
}
.post-content-top{
background: #2b1055;
color: #fff;
opacity: 0,9;
padding: 5px 0 5px 15px;
}
.post-content-top span{
padding-right: 20px;
}
.post-content h2{
font-size: 22px;
padding: 12px 0;
font-weight: 400;
}
.post-content p{
opacity: 0.7;
font-size: 15px;
line-height: 1.8;
color: ghostwhite;
}
.button-btn a {
padding: 8px 15px;
display: block;
font-family:'Almarai', sans-serif ;
font-size: 15px;
cursor: pointer;
background: transparent;
border-radius: 20px;
width: 50%;
border: 2px solid #fff;
color: #fff;
margin: 5px auto;
padding: 0.4rem;
text-decoration: none;
font-weight: 600;
transition: all 0.2s ease-in-out;
}
.button-btn a:hover{
background:#2b1055;
}
Because your entire page is in the while loop it will duplicate the whole page multiple times. I don't know if this is exactly what you want but I suggest you doing it something like this:
<?php
require_once 'opp_data.php';
$sql ="SELECT * FROM college_opp";
$allopp =$conn->query($sql);
?>
<div class="main-container">
<h2>تصفح الفرص التطوعية </h2>
<div class="post-collect">
<?php while ($row = mysqli_fetch_assoc($allopp)) { ?>
<div class="post-main-container">
<div class="all sports">
<div class="post-img">
<img src="imgs/<?php echo $row[" images "]; ?>">
<span class="category-name" data-name="sporty">كلية علوم الرياضة </span>
</div>
<div class="post-content">
<div class="post-content-top">
<span>
<i class="fa-solid fa-users-line"></i><?php echo $row["volunteer_num"]; ?>
</span>
<span><i class="fa-regular fa-calendar-days"></i><?php echo $row["Date"]; ?></span>
</div>
<h2>"
<?php echo $row["Title"]; ?>"</h2>
<p>"
<?php echo $row["Description"]; ?>"</p>
</div>
<div class="button-btn">
التفاصيل والتسجيل
</div>
</div>
</div>
<?php } ?>
</div>
</div>
This will only loop the post-main-container.
This is the code you are looking for
<div class="main-container">
<h2>تصفح الفرص التطوعية </h2>
<div class="post-collect">
<div class="post-main-container">
<?php
while ($row = mysqli_fetch_assoc($allopp)) {
?>
<div class="all sports">
<div class="post-img">
<img src="imgs/<?php echo $row["images"]; ?>">
<span class="category-name" data-name="sporty">كلية علوم الرياضة </span>
</div>
<div class="post-content">
<div class="post-content-top">
<span>
<i class="fa-solid fa-users-line"></i><?php echo $row["volunteer_num"]; ?>
</span>
<span>
<i class="fa-regular fa-calendar-days"></i><?php echo $row["Date"]; ?>
</span>
</div>
<h2>"<?php echo $row["Title"]; ?>"</h2>
<p>"<?php echo $row["Description"]; ?>"</p>
</div>
<div class="button-btn">
التفاصيل والتسجيل
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

Hi guys, my columns do not centre, any ideas?

my columns are not behaving and are all squashed to the left, i've tried overriding the col-2 to set no margins or flex and nothing works, any ideas? thanks.
<li>
<div class="link"><i class="fa fa-database"></i>More<i class="fa fa-chevron-down"></i></div>
<ul>
<?php foreach ($Ranking as $post): ?>
<div class="row" style="margin: 0px 30px;">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="col-2">
<h4 style="font-weight: 500;"><a
href="/single_page_main.php?id=<?php echo $post['id']; ?>"><?php echo $post['title']; ?>
</a></h4>
</div>
<div class="col-2">
<h4><?php echo html_entity_decode($post['body']); ?></h4>
</div>
<div class="col-4">
<img src="<?php echo '/assets/images/' ,
$post['image']; ?>">
</div>
<div class="col-4">
<a href="/player_profile.php?id=<?php echo $post['id']; ?>"><div class="">Profile</div>
</a>
</div>
</div>
</div>
<?php endforeach; ?>
</ul>
</li>
</ul>
$(function() {
var Accordion = function(el, multiple) {
this.el = el || {};
this.multiple = multiple || false;
var links = this.el.find('.link');
links.on('click', {el: this.el, multiple: this.multiple},
this.dropdown)
}
Accordion.prototype.dropdown = function(e) {
var $el = e.data.el;
$this = $(this),
$next = $this.next();
$next.slideToggle();
$this.parent().toggleClass('open');
if (!e.data.multiple) {
$el.find('.submenu').not($next).slideUp().parent().removeClass('open');
};
}
var accordion = new Accordion($('#accordion'), false);
});
The above is the jquery accordion code used to show the ul content on click, however all the conent within this has been moved to the left and none of it centres even with overriding css styles or html code, any ideas? thanks.
.accordion {
width: 100%;
margin: 30px auto 20px;
background: #FFF;
max-width: 800px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.accordion .link {
cursor: pointer;
display: block;
padding: 15px 15px 15px 42px;
color: #4D4D4D;
font-size: 14px;
font-weight: 700;
border-bottom: 1px solid #CCC;
position: relative;
-webkit-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
Above is the CSS, thanks.
I get this
I'm trying to achieve this

show description when clicked

i will need some help with some coding if possible. I would like to have when clicked Learn More to show description above the button and when clicked back to hide it. Any help would be higly appreciated! Code listed below. Thank you for your time!
One more thing, as you can see the top border is not shown, how can i make it to show? Thank you very much for the time spent!
<style>
/* RELATE PRODUCTS BEGIN */
.cardd {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 600px;
margin: auto;
text-align: center;
font-family: arial;
}
.cardd p {
font-family: "Arial Black", Gadget, sans-serif;
font-size: 24px;
font-weight: bold;
margin-top: 6px;
margin-bottom: 5px;
margin-left: 0px;
text-align: left;
padding-top: 6px;
}
.price {
color: grey;
font-size: 22px;
}
.cardd button {
border: none;
outline: 0;
padding: 12px;
color: white;
background-color: #c41735;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
.cardd button:hover {
opacity: 0.7;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
padding: 0;
margin-top: 0px;
margin-bottom: 10px;
}
</style>
<div class="container">
<!-- <div class="row no-margin">
<div class="col-lg-12 text-center">
<h1 class="section-heading">Harnesses</h1>
</div>
</div> -->
<div class="row">
<div class="col-lg-12 scrollReveal sr-bottom sr-ease-in-out-quad sr-delay-1">
<br><br><br>
<h1 class="section-heading page-heading">Engines</h1>
<p></p>
</div>
</div>
<div class="height-60"> </div>
<div class="row">
<div class="col-lg-3 col-md-6 mb-5 col-sm-12">
<div class="scrollReveal sr-bottom sr-ease-in-out-quad sr-delay-1 ">
<div class="cardd">
<img src="g" alt="" style="width:100%">
<h2 class="page-heading">Vittorazi<br> Moster185 Plus MY20</h1>
<span class="price">£1729.99</span>
<p></p>
<p><button>Learn more</button></p>
<p></p>
</div>
</div>
</div> <br>
<div class="col-lg-3 col-md-6 mb-5 col-sm-12">
<div class="scrollReveal sr-bottom sr-ease-in-out-quad sr-delay-1">
<div class="cardd">
<img src="g" alt="" style="width:100%">
<h2 class="page-heading"><br> </h1>
<span class="price">£1729.99</span>
<p></p>
<p><button>Learn more</button></p>
</div>
</div>
</div> <br>
<div class="col-lg-3 col-md-6 mb-5 col-sm-12">
<div class="scrollReveal sr-bottom sr-ease-in-out-quad sr-delay-1">
<div class="cardd">
<img src="" alt="" style="width:100%">
<h2 class="page-heading"><br> </h1>
<span class="price">£1729.99</span>
<p></p>
<p><button>Learn more</button></p>
</div>
</div>
</div> <br>
<div class="col-lg-3 col-md-6 mb-5 col-sm-12">
<div class="scrollReveal sr-bottom sr-ease-in-out-quad sr-delay-1">
<div class="cardd">
<img src="" alt="Atom 80 Vitorazzi" style="width:100%">
<h2 class="page-heading"><br></h1>
<span class="price">£1729.99</span>
<p></p>
<p><button>Learn more</button></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
What you're looking for is a collapsible! All you need is a little JavaScript, and you can expand/collapse text using a button.
Expand Above
If you want to make the hidden text appear above the button, try this:
var collapse = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < collapse.length; i++) {
collapse[i].addEventListener("click", function() {
this.classList.toggle("active");
var expand = this.previousElementSibling;
if (expand.style.display === "block") {
expand.style.display = "none";
} else {
expand.style.display = "block";
}
});
}
.collapsible {
border: none;
outline: 0;
padding: 12px;
color: white;
background-color: #c41735;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
.expand {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #eee;
}
<div class="expand">
<p>
Hidden text.
</p>
</div>
<button type="button" class="collapsible">Learn more</button>
Expand Below
If you want to make it appear below the button, however, just flip the order in which the <div> and <button> element appear, and switch out previousElementSibling with nextElementSibling:
var collapse = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < collapse.length; i++) {
collapse[i].addEventListener("click", function() {
this.classList.toggle("active");
var expand = this.nextElementSibling;
if (expand.style.display === "block") {
expand.style.display = "none";
} else {
expand.style.display = "block";
}
});
}
.collapsible {
border: none;
outline: 0;
padding: 12px;
color: white;
background-color: #c41735;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
.expand {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #eee;
}
<button type="button" class="collapsible">Learn more</button>
<div class="expand">
<p>
Hidden text.
</p>
</div>
To make the text hide and appear above the Button you must make use of toggle() event as
$("document").ready(function(){
$(".collapsible").toggle(
function(){
$(".expand").css({"display" : "block"});},
function(){
$(".expand").css({"display" : "none"});});
});
.collapsible {
border: none;
outline: 0;
padding: 12px;
color: white;
background-color: #c41735;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
.expand {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #eee;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<div class="expand">
<p>
Hidden text.
</p>
</div>
<button type="button" class="collapsible">Learn more</button>
Note: Add the Jquery CDN to use the jquery code.
(<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js">
</script>)

Set a div under another

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.

How to position radiobutton under div?

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

Categories