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.
Related
I have a question regarding how I might display a number of different background images on my site (not a slideshow but page specific backgrounds) along with an image title/credit line of text specific to each image?
I can position the text ok but not sure how to change the text with each new image.
This is what I have so far:
#header #headerbanner {
float: right;
width: 468px;
margin: 30px 0 10px 0;
text-align: left;
padding: 10px;
background: font-size: .8em;
line-height: 1.5em;
}
#header #headerbanner h3 {
font-size: 1.1em;
font-family: "Lucida Grande", "Lucida Sans
Unicode",Verdana,Arial,Helvetica,sans-serif;
}
#header #headerbanner p a {
border-bottom: 1px dashed #a8ef9d;
}
#header #headerbanner a:hover {
background: url(images/blacktrans.png);
}
<div id="headerbanner" class="widget widget_block widget_text">
<p>Image: Eildon Hills, Scottish Borders</p>
</div>
Thanks in advance.
S
I would use some JavaScript to always move to the next image/text:
setInterval(nextImage, 10000);
function nextImage() {
// Repeats every 5 seconds
}
Before this function just select the image and text element by using IDs and the JavaScript getElementById function.
<p id="text"></p>
<img id="img"></img>
text = document.getElementById('text');
img = document.getElementById('img');
And in this function set content of these elements
text.innerHTML = "Your Authors Name";
img.style.background = "url(newUrl/)";
In the function you should also use an Array with all names and images. And an counter and
if(counter>=imgArray.length) {
counter=0;
} else {
counter++;
}
And use the counter to display the text and image on the current position.
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.
I am working on a website in which I want to make a square box around times.
The php code which I have used in order to pull off the times is:
{
echo date('l', strtotime($key)).": ".$value['start']." ".$value['end']."<br/> <br/>";
}
The above php pulls off the following day and times:
Problem Statement:
I am wondering what changes I should make in the php code above so that I can put the square boxes around times, something like this:
PHP has nothing to do with design. And you should definitely not use characters
(like ) to create spaces / margins
Demo: https://www.tehplayground.com/WtTs8Yk0pRw8wHAu
use CSS instead:
* {margin:0; box-sizing:border-box;}
html,body {height:100%; font:14px/1.4 sans-serif;}
.times {
display: inline-flex; /* act as inline */
flex-flow: row wrap; /* wrap into flex rows */
}
.times>* {
flex: 1 0 25%; /* 25%, so subdivision by 4 elements */
text-align: center;
padding: 5px;
margin: 5px 0;
}
.times>*:nth-child(2n) { /* every second child element (time SPAN) */
border: 1px solid #ddd;
border-radius: 3px;
}
<div class="times">
<span>mon:</span>
<span>09:00</span>
<span>to</span>
<span>21:00</span>
<span>tue:</span>
<span>09:00</span>
<span>to</span>
<span>21:00</span>
<span>wed:</span>
<span>09:00</span>
<span>to</span>
<span>21:00</span>
</div>
so inside your PHP foreach simply echo like:
echo '
<span>'. date('l', strtotime($key)) .':</span>
<span>'. $value['start'] .'</span>
<span>to</span>
<span>'. $value['end'] .'</span>
';
I have added the round-cornered box around the time values. Round cornered boxes were created using CSS class called box. Put this code in the header section of your page
<style>
.box{
background-color: #4CAF50;
border-radius: 12px;
border: none;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
and change the php code as below
echo date('l', strtotime($key)).": <span class='box' >".$value['start']."</span> <span class='box' >".$value['end']."</span><br/> <br/>";
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
I'm working on a website for an American Football team. They have these newsitems on their front page which they can manage through a CMS system. I have a problem with alligning the text inside those news items. Two of the news items look like this:
As you can see, the right newsitem text are displayed nicely. But the left cuts it off really bad. You can only see the top half of the text at the last sentence. I use overflow: hidden; to make sure the text doesn't make the div or newsitem bigger. Does anyone have any idea how to solve this through HTML and CSS or should I cut it off serverside with PHP?
Here's my code (HTML):
<div class="newsitem">
<div class="titlemessagewrapper">
<h2 class="titel" align="center"><?php echo $row['homepagetitel']; ?></h2>
<div class="newsbericht">
<?php echo $row['homepagebericht']; ?>
</div>
</div>
<div class="newsfooter">
<span class="footer_author"><?php echo get_gebruikersnaam_by_id($row['poster_id']); ?></span> <span class="footer_comment">Comments <span>todo</span></span>
Lees meer
</div>
</div>
And here is the CSS:
.newsitem{
float: left;
height: 375px;
width: 296px;
margin: 20px 20px 0px 20px;
background-color: #F5F5F5;
}
.newsitem .titel{
color:#132055;
font-size:1.2em;
line-height:1.3em;
font-weight:bold;
margin:10px 5px 5px 5px;
padding:0 0 6px 0;
border-bottom:1px dashed #9c0001;
}
.titlemessagewrapper{
height: 335px;
overflow: hidden;
}
.newsitem .newsbericht{
padding:5px 5px 5px 5px;
font-size: 0.8em;
margin-bottom: 5px;
}
.newsitem .newsfooter{
width: 100%;
height: 25px;
background-color: #132055;
margin: 0px auto;
font-size: 0.8em;
padding-top: 5px;
margin-top: 10px;
border: 1px solid #9c0001;
}
You should not rely on the user to enter <cut> !
User Input = error
What if the user forgets to enter <cut>? Will your news item now look unprofessional?
What would be the point of a user creating a news item to find that some of it was cut off?
If the div can only fit a fixed string length you should validate the max length of the news item Input body instead of relying on <cut>. This can be simply achieved using maxlength attribute.
<textarea id="userinput" maxlength="150">Enter your news</textarea>
If you do use <cut> you should also add in overflow: hidden; to ensure that the content is not unprofessionally displayed if no cut tag is present.
If you want to display the all text and keep the div the same fixed height
Replace
overflow: hidden;
with
overflow:auto;
(Scroll bar won't appear when content is smaller than the div)
Otherwise validate the length of the string / content in your div or remove the CSS height attribute to allow all the content appear with no scroll bars.
Hope this helps
Remove the height attribute on the .titlemessagewrapper. Its this height attribute which is causing the cut off.
If you want the boxes to remain the same height: Take the whole string, perform substr and save in a new variable and echo that.
Eg.
<?php
$str = "abcdefghijkl";
$new_strsubstr($str, 0, 8); // abcdef
// will return abcdefhi
?>