Showing a DIV while hovering another DIV in a loop - php

i am trying to show a div when hovering another div. I researched this forum for solutions but i did not find anything that matched my problem, because mine is in a loop from 0 to 9. I know i just missed something really basic, i just cannot find it.
The whole code is PHP, the HTML lines are made with 'echo'.
I want .runestext$i to show up when .runes$i is hovered.
So, for example, when .runes1 is hovered i want to show up .runestext1 ^^
Here is my code:
<?php>
for ($i = 0; $i <= 9; $i++) {
//FROM HERE
if ($i >= 5) {
$top_position = 493;
}
else {
$top_position = 133;
}
if ($i >= 5) {
$r = 18 + 250 * $i - 250 * 5 - 612.5;
}
else {
$r = 18 + 250 * $i - 612.5;
}
$runes = getRunes($summoner_currentgame_specified);
echo "<style> " . ".runes" . $i . "{" .
"position: absolute;
left: " . $r . "px;" .
"top: " . $top_position . "px;
font-size: 16px;
color: #fff;
font-family: Verdana, Friz Quadrata Thin, sans-serif;
font-weight:bold;" .
"</style>";
echo "<div id='a' class=runes" . $i . ">Runes</div>";
echo "<style> " . ".runes" . $i . ":hover" . "{" .
"position: absolute;
background-color: rgba(0, 0, 0, 0.9);
width: 225px;
height: 300px;
margin-left: -21px;
margin-top: -273px;
text-align: center;
border: 1px solid #fff;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 25px;" . "}" .
"</style>";
//TO HERE ALL IS WORKING FINE, just for clarity of the code
echo "<style>" . ".runestext" . $i . "{
font-family: Verdana;
font-style: normal;
font-weight: bold;
font-size: 16px;
color: #fff;
text-decoration: none;
display: none; }" .
"</style>";
echo "<div id='b' class=runestext" . $i . ">RUNESTEXT</div>";
//Here my mistake should be, i just cannot find it:
echo "<style>" . ".runes" . $i . ":hover .runestext" . $i . "{" .
"display: block;" . "}" .
"</style>";
}
</php>
I really hope you guys can help me as i dont get this working after a lot of time of trying.

It appears your runestext is not a child of runes, which means you need the sibling selector ~ to target it.
// ------------------------------------- ↓
echo "<style>" . ".runes" . $i . ":hover ~ .runestext" . $i . "{" .
"display: block;" . "}" .
"</style>";
}
Side notes
You also miss a rule closure } in this style
echo "<style> " . ".runes" . $i . "{" .
"position: absolute;
left: " . $r . "px;" .
"top: " . $top_position . "px;
font-size: 16px;
color: #fff;
font-family: Verdana, Friz Quadrata Thin, sans-serif;
font-weight:bold;" .
"</style>";
Don't use the same id on your div's, it should be unique

Related

Remove empty space

With the php script below I read user-records of my sql database and show them in my webpage. However, there is an unwanted empty space between the records. How can I remove this empty space?
Sorry, the items are in Dutch language.
<style>
table {
border-collapse: collapse;
border: 1px solid lightblue;
text-align: left;
font-family: verdana;
font-size: 11px;
}
th,td {
border: 1px solid lightblue;
cell-padding: 0px;
}
table.a {
table-layout: fixed;
width: 350px;
background-color: lightblue;
font-weight: bold;
font-size: 13px;
}
table.b {
table-layout: fixed;
width: 350px;
}
table.c {
width: 80px;
margin-left: 355px;
top: -105px;
position: relative;
}
</style>
foreach ($pdo->query($sql) as $row) {
echo "<table class=a><tr>" .
"<td>" . $row['achternaam'] . "</td>" .
"<td>" . $row['tussenvgsl'] . "</td>" .
"<td>" . $row['voornaam'] . "</td>" .
"<td>" . $row['stem'] . "</td>" .
"</tr></table>";
echo "<table class=b><tr><td>" .
$row['straat'] . "</td><td>" . "</td></tr></table>";
echo "<table class=b><tr><td>" .
$row['woonplaats'] . "</td><td>" .
$row['postcode'] . "</td></tr></table>";
echo "<table class=b><tr><td>" .
"Tel: " . $row['telefoon'] . "</td></tr></table>";
echo "<table class=b><tr><td>" .
"Email: " . $row['email'] . "</td></tr></table>";
echo "<table class=b><tr><td>" .
"Geb. datum: " . date('d-m-Y',($row['geboortedatum'])) . "</td><td>" .
"Inschrijfdatum: " . date('d-m-Y',($row['inschrijfdatum'])) . "</td></table>" ;
echo "<table class=c><tr>" .
"<td >" . "<img src='".$row['foto']." ' width=80 >" . "</td>" .
"</tr></table>";```
The empty space is because of the position: relative; declared in table.c. You can try to declare like this:
`table.c {
width: 80px;
margin-left: 355px;
top: 10px;
position: absolute;
}`
This should remove the empty space.

mPDF div ends line (probably)

I'm working on exporting my page to pdf using mpdf. The problem is, that I need my chords above the text. But every chord starts a new page and verse numbers aren't shown at all...
I'm getting song text from markdown via parses to html and than to pdf
css:
.wrapper{
display: inline-block;
position: relative;
margin-top: 4ex;
}
.chord{
font-weight: bold;
position: absolute;
bottom: 1.6ex;
}
.verse{
font-weight: bold;
position: relative;
margin-top: 3em;
}
.verse::after{
content: attr(number);
font-weight: bold;
transform: translateX(-120%);
position: absolute;
bottom: 0;
width: max-content;
}
php:
$object = \Spatie\YamlFrontMatter\YamlFrontMatter::parse(file_get_contents(__DIR__ . '/songs/' . $f));
$song = str_replace('<verse', '<p class="verse"', $object->body());
$song = str_replace('</verse>', '</p>', $song);
$song = str_replace('<wrapper><chord>', '<p class="wrapper"><p class="chord">', $song);
$song = str_replace('</chord></wrapper>', '</p></p>', $song);
$pdf->AddPage();
$pdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);
if ($object->matter('capo') != null) {
$pdf->WriteHTML('<div class="capo">Capo ' . $object->matter('capo') . '</div>', \Mpdf\HTMLParserMode::HTML_BODY);
}
$pdf->WriteHTML(
'<div style="position: absolute; width: 190.08mm; left: 53.46mm;top: 0; max-height: 265px">
<h1>' . $object->matter('title') . '</h1>
<h2>' . $object->matter('author') . '</h2>
<div class="song_body"><p id="song_text">' . $song . '</p></div></div>',
\Mpdf\HTMLParserMode::HTML_BODY
);
md file:
<verse number="1:"></verse><wrapper><chord>Am</chord></wrapper>I walk a <wrapper><chord>C</chord></wrapper>lonely road<Br>

Why isn't my CSS changing here as it should be?

I have the following HTML in conjunction with some PHP:
echo "<a href='" . $_SERVER["PHP_SELF"] . "?guess=" . $value . "' class='already-guessed'>" . $value . "</a>\n";
It applies a special class if it's been already guessed, as the class implies. I have this if it hasn't been guessed:
echo "<a href='" . $_SERVER["PHP_SELF"] . "?guess=" . $value . "'>" . $value . "</a>\n";
And this is the relevant CSS:
.letters a {
display: inline-block;
width: 40px;
height: 40px;
margin: 0 3px 6px 0;
background: #5ac9ff;
color: #fff;
line-height: 2.5em;
text-align: center;
text-decoration: none;
}
.letters a:nth-child(10n) {
margin: 0 0 8px 0;
}
.letters a:hover {
background: #54bff3;
}
.letters a:active {
background: #4fb4e4;
}
.already-guessed {
background: green;
}
So I just have it detect all anchor.
The selector for the anchor gives precedence. Change your code for the .already-guessed class as follows:
.already-guessed {
background: green !important;
}
Or, if you'd prefer, update the selector:
.letters a.already-guessed {
background: green;
}

Super weird HTML mess up

I have a comment system, it works by adding a row to a SQL database. Anyway That works, but then when I echo out the comment div gets all messed up.. Anyway here is the page it is on: http://learntc.net/index.php.
PHP:
while($row = mysql_fetch_array($result))
{
if ($count==1)
{
$bg == "33383C" ;
$count = 0;
}
echo "<div style='background-color: $bg; border: 1px soild silver;' class='comment'>";
echo "<div class='imageAndName'>";
echo "<img src='". $row["image"] ."' class='cPic'/>";
echo "<div class='UserLink'><a href='" . $row["page"] . "'>" . $row["username"] . "</a></div>";
echo "</div>";
echo "<div class='textStuff'>";
echo "<div class='post'>" . $row["comment"] . "</div>";
echo "<div style='color: gray; font-size: 8px'>" . $row["date"] . "</div>";
echo "</div>";
echo "</div>";
$bg = "#282C2F";
$count = $count + 1;
}
CSS:
.comments{
float: right;
padding: 10px;
width: 50%;
border: 1px solid #454D53;
}
.cPic{
width: 60px;
height: 60px;
}
.imageAndName{
width: 30%;
overflow: hidden;
float: left
}
.imageAndName a{
display: block;
}
.textStuff{
width: 70%;
float: right;
}
.post{
overflow: hidden;
width: 100%;
}
.comment{
padding-bottom: 5px;
}
Add clear: both to your .comment style.
Problem one:
$bg == "33383C" ;
should be
$bg = "#33383C";
I don't see anything else. The div is probably screwed up for this reason.

pagination in css/php

two questions:
--1-- it displays all the number of pages. but i'd like it to display as:
<< Prev . . 3 4 [5] 6 7 . . Next >>
--2-- when i hover on the current page no, it should change color or increase the font-size, but when i modify the css of a:hover, all the page nos change color or size instead of the one which i'm pointing to. also, when modifying a:active, nothing happens.
this is my paging code in php:
$self = $_SERVER['PHP_SELF'];
$limit = 2; //Number of results per page
$numpages=ceil($totalrows/$limit);
$query = $query." ORDER BY idQuotes LIMIT " . ($page-1)*$limit . ",$limit";
$result = mysql_query($query, $conn)
or die('Error:' .mysql_error());
?>
<div class="caption">Search Results</div>
<div class="center_div">
<table>
<?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) {
$cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result);
?>
<tr>
<td style="text-align:right; font-size:15px;"><?php h($row['cArabic']); ?></td>
<td style="font-size:16px;"><?php echo $cQuote; ?></td>
<td style="font-size:12px;"><?php h($row['vAuthor']); ?></td>
<td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']); ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="searchmain">
<?php
//Create and print the Navigation bar
$nav="";
$next = $page+1;
$prev = $page-1;
if($page > 1) {
$nav .= "<span class=\"searchpage\"><a onclick=\"showPage('','$prev'); return false;\" href=\"$self?page=" . $prev . "&q=" .urlencode($search_result) . "\">< Prev</a></span>";
$first = "<span class=\"searchpage\"><a onclick=\"showPage('','1'); return false;\" href=\"$self?page=1&q=" .urlencode($search_result) . "\"> << </a></span>" ;
}
else {
$nav .= " ";
$first = " ";
}
for($i = 1 ; $i <= $numpages ; $i++) {
if($i == $page) {
$nav .= "<span class=\"searchpage\">$i</span>";
}else{
$nav .= "<span class=\"searchpage\"><a onclick=\"showPage('',$i); return false;\" href=\"$self?page=" . $i . "&q=" .urlencode($search_result) . "\">$i</a></span>";
}
}
if($page < $numpages) {
$nav .= "<span class=\"searchpage\"><a onclick=\"showPage('','$next'); return false;\" href=\"$self?page=" . $next . "&q=" .urlencode($search_result) . "\">Next ></a></span>";
$last = "<span class=\"searchpage\"><a onclick=\"showPage('','$numpages'); return false;\" href=\"$self?page=$numpages&q=" .urlencode($search_result) . "\"> >> </a></span>";
}
else {
$nav .= " ";
$last = " ";
}
echo $first . $nav . $last;
?>
</div>
and this is how it displays currently:
alt text http://img714.imageshack.us/img714/7184/pag1l.jpg
css:
.searchmain {
margin:30px;
text-align: center;
}
.searchpage {
border: solid 1px #ddd;
background: #fff;
text-align:left;
font-size: 16px;
padding:9px 12px;
color: #FEBE33;
margin-left:2px;
}
.searchpage a{
text-decoration: none;
color: #808080;
}
.searchpage a:hover {
color: #FEBE33;
border-color: #036;
text-decoration: none;
}
.searchpage a:visited {
color: #808080;
}
The solution to your first program seems pretty straightforward; you know the number of surrounding links you want to display so you can simply loop from current_page - surrounding_links to current_page + surrounding_links. Add some conditions for the beginning, the end and for when to show the dots and you're done.
For the css; I´m not entirely sure what you want to achieve but I think you can solve it by using just a tags, the surrounding spans seem redundant, you only need them for the items that are not links (.no_link in the example below):
a, .no_link {
float: left;
display: block;
padding:9px 12px;
border: solid 1px #ddd;
background: #fff;
text-align:left;
font-size: 16px;
}
a {
color: #808080;
}
a:hover {
color: #FEBE33;
border-color: #036;
}
.no_link {
color: #FEBE33;
}
1. Change the padding and border properties of this CSS:
.searchpage {
border: none;
background: #fff;
text-align:left;
font-size: 16px;
padding:3px;
color: #FEBE33;
margin-left:2px;
}
And add the codes for square brackets around $i.
for($i = 1 ; $i <= $numpages ; $i++) {
if($i == $page) {
$nav .= "<span class=\"searchpage\">[$i]</span>";
That should change the visuals of your numbers, I haven't tested it seeing as you don't have a live site but it should work.
2. Instead of .searchpage a:hover try searchmain a:hover.
None of this is tested, but best I could come up with after viewing your code. Hope it helps to at least point you in the right direction :)

Categories