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.
Related
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 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.
I am trying to get a jQuery function to slide li items left and right by clicking an arrow. I am using a jQuery script called TinyCarousel.js. While I have it functioning properly, it continues to scroll right until the last li item is in the first position. What I have currently can be seen here in the "Games Currently Testing or Releasing section" under the main slider. If you scroll all the way to the right you will notice the issue.
Is it possible to either...
1) Change the jQuery to make the last li item stop once it is showing all the way on the right side of the window? I know this would have to be relative to the browser window size as well as make one single partial movement incase the window size has a partial item showing. I also know I would have to know the amount of li items which I can do within the php.
2) Or two, append the li continually so that the slider never seems to end. Just continues through repeating over and over? I would guess that I need to continually append li items as well as remove them if they are off screen.
I attempted to create a jFiddle to show the issue. But it is doing something all together different on jFiddle which is closer to what I need. It seems to stop moving right at some point. But it does not need the entire last li to display completely. What is it doing differently than what I have on the live site where it does stop?
Any help is greatly appreciated. I did search and found this but it did not seem to work in this situation. Thank you in adavnce.
I have am using jQuery 1.10.2, php 5.4, TinyCarousel.js version 1.9
Here is what I have currently.
The CSS
.PrevArrow {
width: 5%;
float: left;
margin-top: 20px;
}
.NextArrow {
width: 5%;
float: right;
margin-top: 20px;
}
.ListImage img {
margin-top: 5px;
margin-bottom: 10px;
}
#slider-code .viewport {
float: left;
width:90%;
height: 95px;
overflow: hidden;
position: relative;
margin-top: 5px;
margin-left: auto;
margin-right: auto;
}
#slider-code .buttons {
display: block;
margin: 0px 10px 0 10px;
float: left;
}
#TickHead {
margin-top: 3px;
}
#slider-code .prev {
margin: 0 10px 0 10px;
}
#slider-code .next {
margin: 0 10px 0 10px;
}
#slider-code .disable {
visibility: hidden;
}
#slider-code .overview {
list-style: none;
padding: 0;
margin: 0;
position: absolute;
left: 0;
top: 0;
}
.TestingTickerText {
vertical-align: top;
color: #666666;
font-family:'Open Sans', "lucida grande", tahoma, verdana, arial, sans-serif;
font-size: 10px;
}
#slider-code .overview li {
float: left;
margin: 0 20px 0 0;
padding: 1px;
height: 65px;
width: 105px;
left: 0;
}
#slider-code .pager {
overflow:hidden;
list-style: none;
clear: both;
margin: 0 0 0 45px;
}
#slider-code .pager li {
float: left;
}
#slider-code .pagenum {
text-decoration: none;
text-align: center;
padding: 5px;
color: #555555;
font-size: 14px;
font-weight: bold;
display: block;
}
#slider-code .active {
color: #fff;
}
The php
<div id="slider-code">
<div class="PrevArrow">
<img src="Link to Left Arrow"/>
</div>
<div class="viewport">
<ul class="overview">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
etc...
</ul>
</div>
<div class="NextArrow">
<img src="Link to Right Arrow"/>
</div>';
<center>
<span id="TickHead" class="cat_bg2">Games Currently Testing or Releasing</span>
</center>
</div>
The jQuery
(function ($) {
$(document).ready(function(){
$('#slider-code').tinycarousel({ display: 1});
});
}(jQuery));
I think the problem you're having is due to css positioning of the images. Try adjusting the margins so that they will be placed slightly further away from each other; so that when no image is appended the slider will stop and there will be no space. If thats not the issue, try this:
1:
Create a div and place all of the slider images in it.
2:
Give each arrow button a separate div and class.
3:
Use the jquery append function to dynamically add images to the slider class when a user clicks either button.
$(document).ready(function(){
$('.arrowbutton').click(function(){
$('.imageslider').append('.image');
});
});
Also, remember to give your image slider a set width in css, and set overflow to hidden. That should make sure no appended images go outside of the slider, and no scrollbars appear.
for some reason the text in my div doesn't go to the next line, i've tried several different css elements which don't seem to work.... word-wrap:break word, just jumbles the letters...
what i want is for one there is an extra word it goes down to the next line like it's supposed to
this is the div it's in
#top7 {
width: 150px;
height:auto;
margin: 5px;
display: block;
float: left;
word-wrap:break-word;
}
text that it's in
#p6 {
font-family: Myriad Pro;
margin: 1px;
font-size: 22px;
background-color:#540f45;
padding: 5px 5px 3px 4px;
margin:4px;
}
a {
text-decoration: none;
color: white;
text-align: right;
font-family: Myriad Pro;
}
here is the php function that retrieves the data from the database
<p id='p6'><?php echo "<a href='' "</a>"; ?></p>
this is all wrapped in these two id's
body {
background:#603e4f;
display: block;
}
#foursquare {
background-color:#603e4f; width: 290px;
display: block;
position: absolute;
}
There's no white space in the generated code, add some between elements (and not )
<p6 id="a2"><a href=http://classm8.net/retrieveclasslist.php?className=MATH100>MATH100</p6><p6 id="a2"><a href=http://classm8.net/retrieveclasslist.php?className=HINF200>HINF200</p6>
You have to use "display:flex" with word-wrap.
#top7 {
word-wrap: break-word;
display:flex;
}
Create a proper class and get rid of the p6 element. Obviously you'd use your database generated HTML. I just used your values as an example for the fiddle. Also since you're wrapping the elements in a p tag anyway the word break is pointless unless you expect data to be too long for a single tag. Paragraphs break to a new line automatically.
<div id="top7">
<p class="six">CSC110</p>
<p class="six">MATH100</p>
<p class="six">HINF130</p>
<p class="six">CSC110</p>
<p class="six">HINF200</p>
</div>
.six {
font-family: Myriad Pro;
margin: 1px;
font-size: 22px;
background-color:#540f45;
padding: 5px 5px 3px 4px;
margin:4px;
}
http://jsfiddle.net/calder12/5crqT/
I have a link after an image in my xhtml. The browser automatically puts a return character after the image so that the link is below the image. I want the link to be beside the image. How do I modify the CSS/XHTML for this?
PHP generates it like this(example code)
echo "<img class = \"c\" src=\"http:\/\/www.facebook.com\/favicon.ico\" alt=\"\"\/>";
echo "<a name = \"a1\" class = \"b\" href = \"$ass_array[url]\">$ass_array[name]</a>";
CSS
img.c
{
display:??;
}
a.b
{
color:#000088;
padding-top:2px;
padding-bottom:2px;
display:block;
width:100%;
border-bottom:1px solid #cccccc;
}
See: http://jsfiddle.net/thirtydot/vgnAa/
CSS:
.c {
display: block;
float: left;
margin-top: 4px;
margin-right: 4px;
}
.b {
color:#000088;
padding-top:2px;
padding-bottom:2px;
display:block;
border-bottom:1px solid #cccccc;
overflow: hidden;
}
Either float: left, float: right depending which side you want the link to be. Apply that to both, and make sure to have a clear div after.
This way you can still have that display:block on .b.
"float:left;" for both elements will work