I use the following code:
.contain {
max-width: 960px;
text-align: center;
}
.category {
position: relative;
display: inline-block;
float: left;
padding: 10px;
}
<div align="center" class="category">
<img src="img/Tariffs-Booking-Icon.png" style="width:100; height:60px;margin-right: 124px;" />
</div>
<div align="center" class="category">
<img src="img/driver_icon.jpg" style="width:100; height:100px;margin-right:124px;" />
</div>
<div align="center" class="category">
<img src="img/user.png" style="width:100; height:100px" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" style="width:100; height:100px;margin-left:58px;" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" style="width:100; height:100px;" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" style="width:100; height:100px;" />
</div>
I am unable to display three images in one rows and in second row next three images.
but i got the images in one rows. so there is any possibility to show images like as in one
row 1 2 3 and second row 4 5 6 images.
Thanks and regards
Add clear: left; to .category:nth-child(4)
JSFiddle - DEMO
.category:nth-child(4) {
clear: left;
}
The clear CSS property specifies whether an element can be next to
floating elements that precede it or must be moved down (cleared)
below them. - by Mozilla MDN
The easiest way would be to have one div for each row and each div having just those 3 images inside them.
<div align="center" class="category">
<img src="img/Tariffs-Booking-Icon.png" />
<img src="img/driver_icon.jpg" />
<img src="img/user.png" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" />
<img src="img/abuse.jpg" />
<img src="img/abuse.jpg" />
</div>
See it here: http://jsfiddle.net/vj4kLdjh/1/
A slightly better approach would be to wrap each row into another div what would have display set to block (default) and the inside divs should either lose the float, or you need to add a clear:both element to the end of each row.
<div class="row>
<div align="center" class="category">
<img src="img/Tariffs-Booking-Icon.png" />
</div>
<div align="center" class="category">
<img src="img/driver_icon.jpg" />
</div>
<div align="center" class="category">
<img src="img/user.png" />
</div>
</div>
<div class="row>
<div align="center" class="category">
<img src="img/abuse.jpg" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" />
</div>
</div>
See it here: http://jsfiddle.net/vj4kLdjh/2/
I've marked the rows with a red border in both cases. I've also removed the inline styling in my answer, and I suggest you do the same in your code. Define classes for those elements and avoid inline styling whenever possible.
This will do exactly what you need - 2 rows containing 3 pictures each to 960px (Which you can of course modify). Don't forget that the child element (category) is width + padding(x2) for actual width - in this case, 320px each.
CSS:
div.contain {
width:960px;
}
# Each div takes 320px (times 3 is 960px)
div.category {
display: inline-block;
padding:5px;
width: 310px;
}
Then
<div class="contain">
<div class="category"># image 1</div>
<div class="category"># image 2</div>
<div class="category"># image 3</div>
</div>
<div class="contain">
<div class="category"># image 4</div>
<div class="category"># image 5</div>
<div class="category"># image 6</div>
</div>
You have to add a wrapper div to each row as:
.row_wrap {
width: 100%;
display: inline-block;
}
.contain {
max-width: 960px;
text-align: center;
}
.category {
position: relative;
display: inline-block;
float: left;
padding: 10px;
}
<div class="row_wrap">
<div align="center" class="category">
<img src="img/Tariffs-Booking-Icon.png" style="width:100; height:60px;margin-right: 124px;" />
</div>
<div align="center" class="category">
<img src="img/driver_icon.jpg" style="width:100; height:100px;margin-right:124px;" />
</div>
<div align="center" class="category">
<img src="img/user.png" style="width:100; height:100px" />
</div>
</div>
<div class="row_wrap">
<div align="center" class="category">
<img src="img/abuse.jpg" style="width:100; height:100px;margin-left:58px;" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" style="width:100; height:100px;" />
</div>
<div align="center" class="category">
<img src="img/abuse.jpg" style="width:100; height:100px;" />
</div>
</div>
Hope this helps
div{
width: 400px;
}
div>img{
width: 100px;
float: left;
}
div>img:nth-child(3n+1){
clear: left;
}
<div>
<img src="1.jpg"/>
<img src="1.jpg"/>
<img src="1.jpg"/>
<img src="1.jpg"/>
<img src="1.jpg"/>
<img src="1.jpg"/>
</div>
Related
I'm trying to write a page with different size images but can't figure out how to align them properly.
This is how the web-page looks:
https://i.imgur.com/Li17CMl.jpg
I have added bootstrap img-fluid for responsiveness. If i set fixed height images wont scale down properly on smaller screens.
I cleaned some non related data with '...' just to make code look cleaner.
My current code:
foreach(row...) : ?>
<div class="col-md-6" style="padding...">
<div class="card">
<div class="card-body" style="padding...">
<a href="">
<div>
<img class="img-fluid" style="width: 100%;" src="row->image..." alt="">
</div>
<div>
<h5> title </h1>
<h6> date </h6>
</div>
</a>
</div> <!-- /card body -->
</div> <!-- /card -->
</div> <!-- /col-6 -->
<?php endforeach; ?>
I'm hoping that images will scale down on smaller screens.
TL:DR object-fit: cover; will do the trick.
Solution 1 - FIXED HEIGHT
with this solution you have to set value for the height of the images: the photos won't stretch but the ratio will be different for each screen
.img-fluid {
height: 200px; /* insert here your desired height*/
object-fit:cover;
}
Solution 2 - REAL FLUID
this solution is a little trickier but the photos will have always the ratio you will choose.
.card-body a div:first-child {
position: relative;
width: 100%;
height: 0;
padding-top: 60%; /*insert value for the desired ratio. ie: 60% -> 10/6 image*/
}
.img-fluid {
position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
object-fit: cover;
}
Please use below code:
.img-card img{width:100%;height:300px;object-fit:cover;}
.img-card{margin-bottom:15px;margin-top:15px;}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-6">
<div class="img-card">
<img src="https://i.ytimg.com/vi/VDNd4KjELkU/maxresdefault.jpg" />
</div>
</div>
<div class="col-6">
<div class="img-card">
<img src="https://media-cdn.tripadvisor.com/media/photo-s/0f/5e/fc/f5/inkaya-cinari.jpg" />
</div>
</div>
<div class="col-6">
<div class="img-card">
<img src="https://thumbs.dreamstime.com/z/scenery-5680647.jpg" />
</div>
</div>
<div class="col-6">
<div class="img-card">
<img src="https://cdn.pixabay.com/photo/2015/11/11/03/47/evening-1038148__340.jpg" />
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-lg-3 col-md-3">
<div style="border:1px solid #ccc; border-radius:5px; padding:16px; margin-bottom:16px; height:250px;">
<img src="'.$row['college_image'].'" alt="" class="img-responsive" >
<p align="center"><strong>'. $row['product_name'] .'</strong></p>
<h4 style="text-align:center;" class="text-danger" >'.$row['search_link'].'</h4>
</div>
</div>
I want to make above img tag as clickable link
Thanks
<div class="col-sm-6 col-lg-3 col-md-3">
<div style="border:1px solid #ccc; border-radius:5px; padding:16px; margin-bottom:16px; height:250px;">
<!--- MAGIC --->
<a href="<YOUR_URL_FROM_DATABASE">
<img src="'.$row['college_image'].'" alt="" class="img-responsive" >
</a>
<!--- /MAGIC --->
<p align="center"><strong>'. $row['product_name'] .'</strong></p>
<h4 style="text-align:center;" class="text-danger" >'.$row['search_link'].'</h4>
</div>
</div>
How do I hide the image tag if there is no image present? Basically, I have an image gallery that has 4 images that can be set. However, if a product has 2 images how do I hide the other 2 image tags? What would be the best method to use?
<img src="/images/large/<?=$prod_id?>.jpg" onclick="openModal();currentSlide(1)" style="border: 1px solid #cccccc;" class="hover-single"/>
<div class="row">
<p style="text-align:center;">Click on image to enlarge</p>
<div class="column">
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:80px; height:80px; border-right: 1px solid #cccccc; padding-right: 5px;" onclick="openModal();currentSlide(2)" class="hover-shadow cursor">
</div>
<div class="column">
<img src="/images/large3/<?=$prod_id?>.jpg" style="width:80px; height:80px; border-right: 1px solid #cccccc; padding-right: 5px;" onclick="openModal();currentSlide(3)" class="hover-shadow cursor">
</div>
<div class="column">
<img src="/images/large4/<?=$prod_id?>.jpg" style="width:80px; height:80px;" onclick="openModal();currentSlide(4)" class="hover-shadow cursor">
</div>
</div>
<div id="myModal" class="modal" style="display: block;">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<div class="mySlides" style="display: block;">
<div class="numbertext">1 / 4</div>
<img src="/images/large1/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">2 / 4</div>
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">3 / 4</div>
<img src="/images/large3/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">4 / 4</div>
<img src="/images/large4/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<a class="prev" onclick="plusSlides(-1)"><</a>
<a class="next" onclick="plusSlides(1)">></a>
<div class="caption-container">
<p id="caption"></p>
</div>
<div class="column">
<img class="gallery cursor active" src="/images/large1/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(1)">
</div>
<div class="column">
<img class="gallery cursor" src="/images/large2/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(2)">
</div>
<div class="column">
<img class="gallery cursor" src="/images/large3/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(3)">
</div>
<div class="column">
<img class="gallery cursor" src="/images/large4/<?=$prod_id?>.jpg" style="width:95%; height:95%;" onclick="currentSlide(4)">
</div>
</div>
</div>
Your modal-content code can be rewritten as below:
check if the image file exists or not
display the slide if the image file exists, do nothing if not.
for($i = 1; $i<=4; $i++) {
$img_file = '/images/large'.$i.'/'.$prod_id.'.jpg';
if(file_exists($img_file)) {
$display = ($i == 1) ? ' block' : ' none';
echo '<div class="mySlides" style="display:'.$display.';">';
echo ' <div class="numbertext">'.$i.' / 4</div>';
echo ' <img src="'.$img_file.'" style="width:95%; height:95%; margin-left: 2.5%;">';
echo '</div>';
}
}
The above code can be used to replace the following code section:
<div class="mySlides" style="display: block;">
<div class="numbertext">1 / 4</div>
<img src="/images/large1/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">2 / 4</div>
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">3 / 4</div>
<img src="/images/large3/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<div class="mySlides" style="display: none;">
<div class="numbertext">4 / 4</div>
<img src="/images/large4/<?=$prod_id?>.jpg" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
Sure it is not the best way to check file_exists each time. This can be improved by means of storing the number of images for each product in your data set / database. Then just set a new variable such as $img_num to replace the 4 in the loop.
Try this code:
<div class="row">
<p style="text-align:center;">Click on image to enlarge</p>
<div class="column">
<?php if(file_exists('/images/large2/'.$prod_id.'.jpg')){<?php>
<img src="/images/large2/<?=$prod_id?>.jpg" style="width:80px; height:80px; border-right: 1px solid #cccccc; padding-right: 5px;" onclick="openModal();currentSlide(2)" class="hover-shadow cursor"><?php }
</php>
Here is possible idea for your requirement :
$query = "here is your query";
$res = "your query executed";
$imagearray = array();
$i = 0;
while($row = mysql_fetch_array($res))
{
if(file_exists(imagepath.$row["image"]))
{
$imagearray[$i] = $row["image"];
$i++
}
}
Hi their Brother ild flue did a good work, but we can enhance the code a bit more but making the fetching a bit more dynamic, I propose the code below,
scan the dir for existing folders(in that way u don't need to depend
on the arbitrary number to indicate the folder
see that those paths with ur image exist or not
display the specified images and let the rest of the be discarded.
<div id="myModal" class="modal" style="display: block;">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<?php
$k=1;
$dirs = array_filter(glob('images/*'), 'is_dir');
foreach ( $dirs as $allLargeDir ){
$imgPath=$allLargeDir."/".$prod_id.".jpg";
if(file_exists($imgPath)){
?>
<div class="mySlides" style="display: block;">
<div class="numbertext"><?php echo $k++." / ".$n; ?></div>
<img src="<?php echo $imgPath;?>" style="width:95%; height:95%; margin-left: 2.5%;">
</div>
<?php
}
}
?>
Hi I want to align two rows of div under each other no matter the height of the divs in the row above. I'm using display:inline-block; so that the divs will inline next to each other.
Here is what I'm getting
Photo 1
Notice that div #2 is slightly shorter than div one
and here is what i want to accomplish
enter image description here
Notice that in the second picture no matter the height of the div above it the second row still aligns as it should.
here is my css
.post-set{
max-width:445px;
margin:0px 1px 15px 0px;
padding:0;
display:inline-block;
border-bottom:1px solid #e1e1e1;
vertical-align:top;
}
i'm using this in my wordpress theme. Here is the html along with the php.
<div class="medium-8 column post-set" style="padding:0;">
<a href="<?php the_permalink(); ?>" title="<?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">
<?php the_post_thumbnail('fifth-post'); ?>
</a>
<div class="row column" style="padding:0">
<h1 class="fifth-post-title"><?php the_title(); ?><h1>
<div class="fifth-ex">
<?php echo excerpt(18); ?>
</div>
<span class="fifth-by-line"> BY: <?php the_author_posts_link(); ?></span>
</div>
</div>
You can visit GetVersed.us to see a live example. It's the section under the "Get Your Voice Heard Banner"
is there a way to accomplish this without suggesting masonry?
I don't see HTML you are using. But here is solution with my html code and yours CSS class. Notice that in CSS I set width instead of max-width.
Different height of div blocks I set using inline style. It can be set in class or auto.
.post-set{
width:60px;
margin:0px 1px 15px 0px;
padding:0;
display:inline-block;
border-bottom:1px solid #e1e1e1;
vertical-align:top;
background-color:black;
}
<div>
<div class="post-set" style="height:20px;">
</div>
<div class="post-set" style="height:35px;">
</div>
</div>
<div>
<div class="post-set" style="height:15px;">
</div>
<div class="post-set" style="height:30px;">
</div>
</div>
You can create a simple table and place your divs as follows:
<table>
<tbody>
<tr>
<td>
<div 1...>
</td>
<td>
<div 2...>
</td>
</tr>
<tr>
<td>
<div 3...>
</td>
<td>
<div 4...>
</td>
</tr>
</tbody>
</table>
This will make sure that the alignment is as you wish. You can then add some styles if you wish.
You should look into flexbox.
HTML:
<div class="item_container">
<div class="item">
</div>
<div class="item">
</div>
</div>
<div class="item_container">
<div class="item">
</div>
<div class="item">
</div>
</div>
CSS:
.item_container {
display:flex; align-items:stretch;
}
.item { float:left; }
So I am working to make a change on this site. http://www.kbduct.com . One the site there is a png file of a transparent united states logo on the front. I had to add a small awfs logo banner to it and have the viewer be able to click on it so that it can lead to a different site. I added the anchor tags to these items but nothing happens wen you click on it. Heres the index file and the external file for the image.
BTW, I didn't build this site. Im helping to maintain it for the time being.
INDEX:
<?php include('inc/default.php');
$pageTitle = "The Nations Source For Industrial Ducting, Ducts and Ductwork Components - KB Duct";
$pageDisc = "KB Duct is the Nation's source for industrial duct, ducting components and ductwork fittings and supplies. We offer custom built solutions for your industrial needs.";
$pageKeys = "duct, ductwork, ducting, duct work, commercial ducting, industrial ducting, custom ductwork, ductwork supplies, ducting accessories, duct fittings";
?>
<!doctype html>
<html>
<?php include('inc/head.php'); ?>
<body>
<div id="sb-site">
<?php include('inc/maximage.php'); ?>
<?php include('inc/header.php'); ?>
<div class="mainarea">
<a href="http://awfsfair.org/">
<div id="eBanner" style=" position: absolute; right: 380px; top: 310px;">
<?php /*?> <script type='text/javascript' src='http://libs.a2zinc.net/Common/JS/10.6.0.0/a2zWidget.js'></script><script type='text/javascript' id='exWidget'>new a2z.Widget('dGbJ%2fQfPqUA4s%2fDNrIc%2fzt5xiq%2fL4ZoFjVXmdUEcJutOcD9ggxZSCZyU8MZ6cQu6',40297,'http://libs.a2zinc.net/Common/Widgets/ExhibitorBadge.aspx',31,201133,330,200).render();</script>
<?php */?>
</a>
</div>
<div class="wrapper">
<?php include('inc/industry.php'); ?>
<?php include('inc/catatypes.php'); ?>
<div id="mob-only">
<?php include('inc/mobslideup.php'); ?>
</div>
</div>
</div>
<?php include('inc/footer.php'); ?>
</div>
<?php include('inc/mob-menu.php'); ?>
</body>
</html>
MAXIMAGE.PHP:
<div id="maximage">
<div>
<img src="img/Custom-Ductwork-Clamp-Together-Ducting-Shiny-Ducts-BG.jpg" alt="KB Duct is the nation's source for clamp together and flanged industrial ducting and duct parts." />
<div class="in-slide-content" style="display:none;">
<img src="img/nations-source-for-industrial-ducting.png" alt="KB Duct offers custom fabricated industrial ducting solutions.">
</div>
</div>
<div>
<img src="img/shinyduct.jpg" alt="" />
<div class="in-slide-content" style="display:none;">
<img src="img/awfs-nations-source.png">
</div>
</div>
<!-- <div>
<img src="img/kbduct-production.jpg" alt="" />
<div class="in-slide-content" style="display:none;">
<img src="img/nations-source-for-industrial-ducting.png">
</div>
</div>-->
<div>
<img src="img/plasma.jpg" alt="" />
<div class="in-slide-content" style="display:none;">
<img src="img/awfs-nations-source.png">
</div>
</div>
<div>
<img src="img/welding.jpg" alt="" />
<div class="in-slide-content" style="display:none;">
<img src="img/awfs-nations-source.png">
</div>
</div>
<!-- <div>
<img src="img/clamp.jpg" alt="" />
<div class="in-slide-content" style="display:none;">
<img src="img/nations-source-for-industrial-ducting.png">
</div>
</div>-->
<div>
<img src="img/tunnel.jpg" alt="" />
<div class="in-slide-content" style="display:none;">
<img src="img/awfs-nations-source.png">
</div>
</div>
MAXIMAGE CSS ID:
#maximage {
display:block;/* Only use this if you fade it in again after the images load */
position:fixed !important;
z-index:-1;
CSS IN SLIDE CONTENT:
.in-slide-content {
color:#333;
float:right;
font-family:'Helvetica Neue', helvetica;
font-size:60px;
font-weight:bold;
right:20px;
margin:40px;
padding:20px;
position:absolute;
top:20px;
width:700px;
z-index:9999; /* Show above .gradient */
text-shadow: 0 1px 0 #fff;
-webkit-font-smoothing:antialiased;
}
I did some R&D got some thing. May be this help you
There is a id eBanner change inline styling to
position: absolute;
right: 269px;
top: 141px;
z-index: 9999;
height: 100px;
width: 185px;
border: 2px solid red;
Inside this div there is and anchor tag add folloing style
display: block;
width: 181px;
height: 100px;
Once you check it works then you can remove red border