float right property wrong display when overflow in previous container - php

I am displaying a list of files in a container.
This list is generated by a php script.
For each file I associate a trash button in order to delete the file if user needs to. To do so I set float to right on the trash button.
But in some cases where the file name is too long, because of the overflow, the button is not displayed on the same line.... any idea how to fix that ?
Here is the generation script :
$list_docs = '<ul class="listDocs">';
foreach ($iterator as $file) {
// ignore filenames starting with . dot.
if (substr($file->getBasename(), 0, 1) === '.') {
continue;
}
$entryId++; // unique list entry id...
// use this and $prevDepth to check for nesting into and out of directories...
$curDepth = $iterator->getDepth();
$dirStart = $curDepth > $prevDepth; // nest down a directory?
$dirEnd = $curDepth < $prevDepth; // end of the directory
if ($dirEnd) { // UL end...
$list_docs .= '<!-- dir-end --></ul>';
}
if ($file->isDir()) { // display path details...
if ($dirStart) { // UL start... with Directory so will nest...
$list_docs .= '<ul class="listDocs indent">';
}
// display directory details
$list_docs .= '<li class="docResult"><i class="fa fa-folder"></i> <span id="file_'. $entryId. ' data-folder="'.$file->getPathname().'" class="folderClic">'.$file->getFilename().'</span><span class="file-remove fa fa-trash-o"></span></li>';
} else {
if ($dirStart) { // UL start... first time for this directory...
$list_docs .= '<ul class="listDocs indent">';
}
// display file details
$list_docs .= '<li class="docResult"><i class="fa fa-file-o"></i> <span id="file_'. $entryId .'" data-file="'.$file->getPathname().'" class="fileClic">'.$file->getFilename().'</span><span class="file-remove fa fa-trash-o"></span></li>';
}
$prevDepth = $curDepth; // record depth so we can check next time...
}
$list_docs .= '</ul>';
This code is pasted into a div :
<div class="documentList" id="documentList">Explorer</div>
And here is css :
.file-remove {
float: right;
color: #700;
cursor: pointer;
}
.documentList{
display: inline-block;
background-color: rgba(255,255,255,1);
border-style: solid;
border-width: 2px;
border-color: rgba(0,0,0,0.3);
color: rgba(116,119,123,1);
padding: 0.5em 0.5em;
width: 20%;
min-height: 500px;
vertical-align: top;
}
.listDocs{
list-style: none;
text-align: left;
padding: 0em 0em;
margin: 0em 0em;
overflow: auto;
}
I have also tried to display it as a table, but I don't manage to get the proper width for the filename column.
EDIT: here is a picture of the issue :
I also tried with word-wrap: break-word; on the docResult class, then I got the following :

I would probably change the inline elements:
<li class="docResult">
<i class="fa fa-file-o"></i>
<span id="file_'. $entryId .'" data-file="'.$file->getPathname().'" class="fileClic">'.$file->getFilename().'</span>
<span class="file-remove fa fa-trash-o"></span>
</li>
Into:
<li class="docResult">
<div class="file"><i class="fa fa-file-o"></i></div>
<div class="title" id="file_'. $entryId .'" data-file="'.$file->getPathname().'" class="fileClic">'.$file->getFilename().'</div>
<div class="file-remove"><i class="fa fa-trash-o"></i></div>
</li>
This way we can display them as "inline-block", and have long file titles grow vertically without interrupting either side icons.
Then, we can:
.docResult{
font-size: 0; /* Remove children spacing */
}
.docResult div{
display: inline-block; /* Allows for horizontal positioning of siblings */
vertical-align: top; /* They will stick to the top, even if a long title expands the row */
font-size: inital; /* Resets font-size from parent's 0px */
}
.docResult .file{
width: 50px; /* Example icon width */
}
.docResult .file-removed{
width: 50px;
}
.docResult .title{
width: calc(100% - 50px - 50px); /* We want the title to be as long as it can be without overlapping icons */
}
So, basically we're using block elements instead of inline elements, this way elements don't wrap around each other like text. Afterwards, we're defining we want each element to position horizontally, keeping both icons aligned with the first line of the title, and giving the title's element the maximum possible without getting in the way of either icon.

Related

Why doesn't display:inline-block work for my HTML?

The display: inline-block technique to make div elements appear next to each other does not work with my dynamically-generated content cards.
My content cards are a modified version of a tutorial found on the w3schools website, which can be found here:
https://www.w3schools.com/howto/howto_css_cards.asp
Goal
I'm in the process of creating a relatively simple search engine for my website based on a query that checks a MySQL database for any potential matches. The results are returned in the form of a content card. If the system finds 3 matches, 3 content cards will be generated in the results. The code is being controlled by a for-loop (PHP) that generates a content card for each match found.
Problem
The corresponding content cards are generated for each match, however, they appear on separate lines below each other (vertically). I attempted to use the display: inline-block technique to force them next to each other with no results. I suspect the reason why is because the code for each content card must already be there for the effect to take place. If not, CSS & HTML assume that there was only ever one content card and doesn't align them properly.
HTML/CSS/PHP Code for Content Cards
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 300px;
margin: auto;
text-align: center;
font-family: arial;
width: 30%;
}
.card button {
border: none;
outline: 0;
padding: 12px;
color: white;
background-color: #000;
text-align: center;
cursor: pointer;
width: 20%;
font-size: 18px;
}
.card button:hover {
opacity: 0.7;
}
.shrink {
-webkit-transform: scale(0.8);
-moz-transform: scale(0.8);
-ms-transform: scale(0.8);
transform: scale(0.8);
}
<!-- Container -->
<div class="container" style="background-color: white; width:89%; padding-top: 400px;">
<!-- Generates 1 Content Card for each Match -->
<?php
for($x = 0; $x < count($title); $x++) {
?>
<!-- Content Card Design & Data -->
<div class="shrink">
<div class="card" style="background-color: white; border-radius: 2%; display: inline-block;">
<a href="#" data-toggle="modal" data-target="#ModalCarousel<?php echo " $x ";?>" style="text-decoration: none; color: black;">
<img src="listingimages/<?php echo "$firstListingImage[$x]";?>" style="width:100%; border-top-left-radius: 2%; border-top-right-radius: 2%;">
<h4><?php echo "$title[$x]";?></h4>
<hr>
<p><span class = "glyphicon glyphicon-cutlery"></span> <?php echo "$foodType[$x]";?></p>
<hr>
<p><span class = "glyphicon glyphicon-map-marker"></span> <?php echo "$city[$x]";?>, <?php echo "$state[$x]";?></p>
<hr>
<p style="font-size: 30px;"><b>$<?php echo "$price[$x]";?></b><span style="font-size: 15px;"> USD</span></p>
</a>
</div>
</div>
<?php } ?>
</div>
It is very easy just you need to add in the class .card {float:left} then it will work as you want
With inline-block for it to work you must also set a fixed width on .shrink, which is the repeated holder, and maybe vertical-align
The preferred way nowadays is by setting display:flex; flex-wrap:wrap on the container which is made just for this kind of box display. Also set width on .shrink with this solution.
Your .cards are nicely displayed as inline-blocks, but they're each wrapped inside a .shrink which are full blocks. That's why they're not lining up as you'd expect.

Border is not being applied to the whole div?

I am trying to create a div (trending-panel) that is only 30% of the total page, in that div contains 10 generated divs (trending-div). The multiple generated divs contain an image, text ($title), and the number of views that article has ($Counter). For some odd reason, when I apply a border to the entire trending-panel, the border does not get applied to the last image and text. Even though the last image and text are printed out, the trending-panel is not counting it for some reason and only prints the border towards the first 9. Here's my code:
HTML CODE:
<div class="trending-panel">
<?php
$resultSet = $db->query("SELECT * FROM Articles ORDER BY Counter DESC, dateStamp DESC LIMIT 10");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$image = $rows["image"];
$title = $rows["title"];
$link = $rows["link"];
$count = $rows["Counter"];
echo "<div class='trending-div'><img src='{$image}'/><p>{$title}</p><p id='count'>{$count}</p></div>";
}
}
?>
</div> <!--End of trending panel div-->
CSS:
.trending-panel{
width: 30%;
border: 1px solid lightgray;
}
.trending-div{
position: relative;
clear: both;
border: 1px solid lightgray;
}
.trending-div img{
width: 45%;
height: 120px;
float: left;
}
.trending-panel p{
width: 54%;
float: right;
font-family: "Oswald";
font-size: 16px;
color: black;
}
#count{
position: absolute;
bottom: 0px;
right: 0px;
font-family: "Oswald";
font-size: 14px;
color: black;
}
Generated HTML:
<div class="trending-panel">
<div class='trending-div'><img src='/media/thumbnails/bus-falls-in-alligator-pond.jpg'/><p>School Bus Falls Into Alligator Pond</p><p id='count'>202254</p></div><div class='trending-div'><img src='/media/thumbnails/foods-that-can-kill-you.jpg'/><p>Top Ten Foods That Can Kill You</p><p id='count'>150136</p></div><div class='trending-div'><img src='/media/thumbnails/most-shocking-facts-about-disney.jpg'/><p>The Top Ten Most Shocking Facts About Disney</p><p id='count'>102508</p></div><div class='trending-div'><img src='/media/thumbnails/extremely-weird-religions.jpg'/><p>10 Extremely Weird Religions</p><p id='count'>98069</p></div><div class='trending-div'><img src='/media/entertainment/trump.jpg'/><p>This Is What Would Happen If You Stopped Sleeping</p><p id='count'>45646</p></div><div class='trending-div'><img src='/media/thumbnails/signs-you-grew-up-in-the-90s.jpg'/><p>10 Signs You Grew Up In The 90s</p><p id='count'>26183</p></div><div class='trending-div'><img src='/media/thumbnails/no-spin-earth.jpg'/><p>This Is What Would Happen If The Earth Stopped Spinning</p><p id='count'>7144</p></div><div class='trending-div'><img src='/media/thumbnails/bubble-gum-under-shoe.jpg'/><p>10 Unwritten Rules Everyone Should Follow</p><p id='count'>3593</p></div> </div> <!--End of trending panel div-->
It could be because you image tag doesn't have quotes around the src attribute value. Also add a closer for the image change:
echo "<div class='trending-div'><img src=$image><p>$title</p><p id='count'><$count</p></div>";
to:
echo "<div class='trending-div'><img src='{$image}'/><p>{$title}</p><p id='count'>{$count}</p></div>";
Try this, you have an '<' before $count, which isn't valid, if you want to use < or > then you have to use escape codes because these mark the start and end of tags.

How To Wrap Content That Is Generated Programatically In PHP Through Divs Depending On Screen Res

I have been racking my brains trying to figure out how to change what I have into something that will organise my content into as many rows as necessary and as many columns (divs) as necessary when the screen resolution changes.
Basically, my current website set up has a content div with a height of 430px which can accommodate any number of columns because I have a horizontal scroll. Within each column there can be up to 10 rows of data before another column is created for the next lot of data.
What I want to do is change the height of the content div to % not px so it will scale with the browser res. My current script will still only output the same number of rows and columns if the content div is too small of too big, so what I want is to have the number of rows less for smaller screen res's and more for higher res screens.
I kind of want the content to wrap into the next column (div) if the browser is made smaller.
Hope this makes sense.
Can someone point me in the right direction? I know this code is currently written differently but I cant think how to do it:
functions.php:
<?php
function printTranscriptions()
{
global $link;
$query = "SELECT * FROM transcriptions ORDER BY artist, title";
if ($result = mysqli_query($link, $query)) {
$count = 0;
while ($row = mysqli_fetch_row($result)) {
if (($count % 10) == 0) {
if ($count > 0) {
echo "</div>\n";
}
echo '<div class="content_columns">'."\n";
}
$artistTitle = $row[1] . ' - ' . $row[2];
echo '<p>' . $artistTitle . '</p>'."\n";
$count++;
}
if ($count > 0) {
echo "</div>\n";
}
/* free result set */
mysqli_free_result($result);
}
}
My index file calls the content in the following structure:
<!-- Transcriptions page start -->
<div class="transcriptions_page">
<h1>
Transcriptions
</h1>
<div class="content">
<div class="list-wrapper">
<div class="transcription-list">
<?php printTranscriptions();?>
</div>
<!-- transcription-list end -->
</div>
<!-- list-wrapper end -->
</div>
<!-- content end -->
</div>
<!-- Transcriptions page end -->
My css:
.content {
display: block;
overflow: hidden;
background-color: #2D949E;
color: #fff;
text-shadow: #FAFAFA;
margin-top: 75px;
margin-left: 10%;
margin-right: 10%;
padding: 20px 20px 20px 20px;
height: 430px;
border: 1px solid #99E9F1;
}
.list-wrapper {
overflow: hidden;
}
.transcription-list {
display: block;
white-space: nowrap;
}
.content_columns {
display: inline-block;
background-color: #429EA8;
letter-spacing: 1px;
margin-right: 20px;
padding: 0 10px;
}
.content_columns:last-child {
margin-right: 0 !important;
}
Thanks

HTML5 (php) with CSS Tooltip shows up far away from hyperlink

If I hover over the hyperlink, the tooltip shows up but not as it should. It shows up a few inches below the hyperlink. I got the code from a demo of the internet.
How do I get the tooltip right below the hyperlink?
Here is the PHP code I used:
if ($teller == 3) {
echo '<p><a href="#" class="tooltip">...<span>';
foreach ($bericht->datums as $date) {
echo date('d/m/Y', strtotime($date->datum)) . ' om ' . date('H:i', strtotime($date->beginUur)) . '<br />';
}
echo '</span></a></p>';
}
The code above generated this code in HTML:
<p>
<a href="#" class="tooltip">...
<span>
13/04/2013 om 13:49<br />
15/04/2013 om 12:50<br />
29/04/2013 om 16:00<br />
</span>
</a>
</p>
Here is the CSS that belongs to it:
a.tooltip span {
position:absolute;
z-index: 999;
white-space:nowrap;
bottom:9999px;
background:#81b0b0;
color:#e0e0e0;
padding:5px 12px;
line-height: 24px;
height: auto;
opacity: 0;
transition:opacity 0.5s ease-out;
}
a.tooltip span::before {
content: "";
display: block;
border-left: 6px solid #81b0b0;
border-top: 6px solid transparent;
position: absolute;
top: -6px;
left: 0px;
}
a.tooltip:link {
color:#FFF;
}
a.tooltip:visited {
color:#FFF;
}
a.tooltip:hover span {
opacity: 1;
bottom:-35px;
}
Can someone help me out please? Thanks! ;)
when you use
position:absolute;
it positions against the nearest container in the chain that has a position set; so if you don't have a position set on any of the elements that contain it, or its parents, it will position against the body.
try putting position absolute or relative on the containing p tag

Tree Menu Won't Scroll

I have a nested list that lists child nodes when the parent node is expanded. The parent node is expanded by clicking an image to the left of the text.
Unfortunately, it expands right off the page. I would like a scrollbar to appear when the content is off the page.
When I set "overflow: auto", a scrollbar never pops up, it just expands off the page and removes the expansion image on left of the list items.
Here's sample .html:
<body>
<div id="theDiv" style="clear: left;">
<ul id="theList">
<li id="1" class="parent">
<img class="expanded" align="absmiddle" src="./tree_expanded.gif"/>
Parent1
<ul style="display: block;">
<li id="10">
.....
</ul>
</li>
....
</ul>
</div>
</body>
Here's sample .js:
function expand() {
if(this.className == "expand") {
jQuery(this.parentNode).children("ul").show();
this.className = "expanded";
this.src = "/_images/tree_expanded.gif";
}
else {
jQuery("ul", this.parentNode).hide();
this.className = "expand";
this.src = "/_images/tree_unexpanded.gif";
}
}
Here's sample .css:
#theList {
margin-top: 0;
}
#theList, #theList ul {
list-style: none;
margin: 5px 20px;
padding: 0;
}
#theList .expand, #theList .expanded {
margin-left: -20px;
cursor: pointer;
}
#theList img {
margin-right: 5px;
}
#theList ul {
display: none;
}
#theList li {
white-space: nowrap;
margin-bottom: 4px;
}
First of all, set a definite width of the container div, so it knows when to start scrolling. Next, set it to overflow-x:scroll; or something to that effect. It should work :)
Ok, I was on the right track but not persistent enough. CSS really drives me nuts. I need to set both the div and the list height to get it to scroll. I was trying one or the other, not both.
I'm such a n00b.

Categories