Floated images stacked - html

I am trying to create a list of actors in a film with a small profile image to the left of the actor's name and their accompanying character, however my images are strangely stacking on top of one another, and I'm not sure why. The cast names, their character and the image are all being pulled in dynamically from an external API.
Below is an image of the current layout:
The accompanying HTML and CSS is below:
HTML
<?php
foreach($tmdb_cast['cast'] as $castMember){
if ($tmp++ < 10)
echo '<img src="http://cf2.imgobject.com/t/p/w45' . $castMember['profile_path'] . '" class="actor_image" alt="' . $castMember['name'] . '" title="' . $castMember['name'] . '" />';
echo '<p>' . $castMember['character'] . ' - ' . $castMember['name'] . '</p>';
}
echo '<p id="morecast">[...view all cast]</p>'
?>
CSS
#cast {
margin-left: 50%;
border: solid 1px red;
}
.actor_image {
float: left;
}
#morecast {
text-align: right;
}
The layout I'm trying to achieve is something similar to the one on display at IMDb, with the actor's name and character vertically aligned with the image:

It looks like you're floating your images, but not applying a "clear" between your image+text units. Try applying a "clear: both;" between each actor instance?

Wrap the image and p elements in a div and have clear:both on the div. Set the inline style to a class. I did it inline as a quick-and-dirty example.
foreach($tmdb_cast['cast'] as $castMember){
if ($tmp++ < 10)
echo '<div style="clear: both;">'
echo '<img src="http://cf2.imgobject.com/t/p/w45' . $castMember['profile_path'] . '" class="actor_image" alt="' . $castMember['name'] . '" title="' . $castMember['name'] . '" />';
echo '<p>' . $castMember['character'] . ' - ' . $castMember['name'] . '</p>';
echo '</div>'
}

I'ts convenient to create a css class that wraps every image and text group:
echo '<div class="actor">
<img src="http://cf2.imgobject.com/t/p/w45' . $castMember['profile_path'] . '" class="actor_image" alt="' . $castMember['name'] . '" title="' . $castMember['name'] . '" />';
echo '<p>' . $castMember['character'] . ' - ' . $castMember['name'] . '</p>
</div>';
And float each container
.actor{
float:left;
clear: left;
}
Now you have a box arround the image+text group that you can float. If this doesn't fix the problem, next step is define the .actor "width" property

Related

CSS elements listing vertical automatically, column count : 4, rows : N

Question :
element1 elementN+1 element2N+1 element3N+1
element2 elementN+2 element2N+2 element3N+2
. . . .
. . . .
. . . .
elementN element2N element3N element4N
My css code.
HTML
<ul>
<li>element1</li>
<li>element2</li>
<li>element3</li>
<li>element.</li>
<li>element.</li>
<li>element.</li>
<li>element4N</li>
</ul>
CSS
ul {float:left;}
ul li {float:left; min-width: 250px;}
Result :
element1 element2 element3 element4
element5 element6 element7 element8
. . . .
. . . .
. . . .
element4N-3 element4N-2 element4N-1 element4N
I tried with display grid(ul tag) but it requires row count which I need automatic.
display: grid;
grid-auto-flow: column;
grid-template-rows: repeat(35, 1fr);
I'm wondering if it's possible to do this by only using CSS.

give margin bottom inside dd class

i want to give margin bottom to them
code is as shown below,
<div class="dd" id="menu_list_drag">
<?php echo $li; ?>
</div>
where $li is as shown below,
foreach ($p1 as $p) {
$inner_li = "";
$p2 = array_filter($menu, function($a)use($p) {
return $a['parent_id'] == $p['id'];
});
if ($p2) {
$inner_li = $this->generate_li($menu, $p['id']);
}
$li .= "<li class='dd-item' data-id='" . $p['id'] .
"' id='menu-list'><div menu-id='" . $p['id'] . "' id='drag' class='dd-handle'>" . $p['title'] .
"<div style='float:right; margin-bottom:10px' class='dd-nodrag'>"
. "<a class='btn-group btn-group-xs edit_menu' data-toggle='tooltip' id='" . $p['id'] .
"' data-original-title='Edit' onclick='edit_menu($(this))' title='Edit Menu'>"
. "<i class='btn btn-default edit_area fa fa-pencil'></i></a>"
. "<a class='btn-group btn-group-xs delete_menu' id='" . $p['id'] .
"' data-toggle='tooltip' data-original-title='Delete' delete_type='delete_single' onclick='delete_menu($(this))' title='Deactivate Menu'>"
. "<i class='btn btn-default fa fa-trash-o'></i></a></div></div>" . $inner_li . "</li>";
}
$ol = "<ol class='dd-list'>" . $li . "</ol>";
data comes fine but i am unable to give margin bottom to this dd class menu
please help me thank you...
i have used this
.dd-handle{height:35px;}
and it worked for me...!!

I want to put an imgae + h5 inside the "a" tag in WordPress

I want to put an image + h5 inside the "a" tage in WordPress..it seem's not working.. properly syntax error whith calling the image!..
echo '<li>' . "<img src='".get_post_meta($post->ID, "news_images", true) . "' />" .$recent["post_title"].' </li> ';
Try this
<li><img src='".get_post_meta($post->ID, "news_images", true) . "' /> .$recent["post_title"] </li>
Hope this works

Photo Resize when loading... PHP photo from server

I'm wondering if anyone could provide me with some advice on where I went wrong. I'm trying to get a photo to resize when loaded in a DIV but the photo keeps taking it's own dimensions. Does anyone have any idea why my code isn't working? Thank you in advance!
if($row['coverphoto'] === NULL){
echo"<li>";
echo"<img src='images/slider-4.jpg'>";
echo "<div class='banner'>Customize Your Banner!</div>";
echo "</li>";
}
else{
echo "<li>";
echo "<img style='height:auto; width:auto; max-width:1025px; max-height:503px;' src='/coverphotos/" . $row['coverphoto'] . "'/><br />";
echo "<div class='banner'>Customize Your Banner!</div>";
echo "</li>";
}
?>
Try this,
else{
echo "<li>";
echo "<div style="width:50px;height:50px;"><img style='height:50px; width:50px;' src='/coverphotos/" . $row['coverphoto'] . "'/></div><br />";
echo "<div class='banner'>Customize Your Banner!</div>";
echo "</li>";
}
If it is not worked means, please check your, css file
<li>
styles. May that style makes this mistake.

Back button on the image preview

I have a minor problem, i just want a simple image preview with a go back button or something similar, I made
<div id="image1">
<a href="../assets/image_large1.jpg"><img src="../assets/image_1.jpg" width="160" height="107" alt="Example 1" />
</div>
but I don't know how to put a button inside
how could I do it?
In the most simple solution to your problem, I would do special show_image.php page, for example:
<?php
$directory = 'assets/';
$filename = $_GET['image'];
if(empty($filename) || is_file( $directory . $filename ))
{
echo 'No such image!';
}
else
{
echo '<img src="' . $directory . $filename . '" />';
}
echo '<br />';
echo 'Go back';
exit;
And link for the image will be: http://mysite.com/show_image.php?image=image_1.jpg
Of course this code should be made more secure and this thing could be done other ways.