Hello All,
Below is my code which takes the data out from database and displays it on a page.
Currently my output is like: .
i want it to change to something like where instead of displaying title after image, it should come below it.
You need to show us the CSS you’re using to go with that.
Also, it’s not very helpful to give the PHP; we really need to see the HTML output. Please can you load your page, and use “View source” to copy and paste the relevant section of the HTML here.
You would really need to wrap each image and its caption (marked up with <p> tags) in a div, and then you can float the divs to place them side by side.
If you are putting your images inside a floated container then you need to put the 25% width on the container and set the image width to 100%. You’ve also set the image height to 150px which means you break the aspect ratio of the image. If you want the image to maintain its aspect ratio then set the image height to auto.
If your blocks are of uneven height then use display:inline-block (ie8+) instead of floats and then they won’t snag when they wrap.
You seem to have lost the <p> tags from your titles.
<img> is an inline element, and won’t create a line break before of after it. <p> is a block element and will automatically start on a new line. As you can see from your screenshot above, when you did include the <p> tags, the title was positioned below the image.
I have added<p> to titles. now things are 50% solved,but this is giving me images doen one another but not side by side. i need three in a line and three on next line
Again, you’ve not followed the original instructions carefully. You need to wrap each image and its title in a div. Then you can float the divs or use inline-block to align them side-by-side.
.img-wrap{
margin:0 1% 20px 1%;
width:22%;
display:inline-block;
*display:inline;/* ugly ie7 and ie6 hack - delete if not supporting*/
zoom:1.0;/* ugly ie7 and ie6 hack - delete if not supporting*/
vertical-align:top;
}
.imge img{
display:block;
width:100%;
height:auto;/* if you want a fixed height then change this*/
}
p.title{
padding:5px 0;
text-align:center;
margin:0;
}
Don’t write your css inline in the html as that makes it very awkward to change from the css file. Also you had 2 style tags in the element and only one is allowed.
In case my php is wrong then you need actual html that looks like this:
The above is a working example so just copy it and run it in your browser while online to see the effect.
Rather than using a div and a p tag it would be more semantic these days to use the figure and figcaption elements as that was what they were designed for in html5.
Paul, don’t put quotes around variables e.g. echo “$date”; because that date will then be interpreted as a string. Leave the quotes out. If you still need the stuff in varaibles to be wrapped in quotes for HTML purposes then do what you were doing earlier with “”.$picture.“”
Gotcha - I merely looked at what you posted and saw the PHP and your outputted HTML sample did not match what PHP would have done. Either way just trying to educate :-).