how to keep all floated images in one line? - css

<div id="divT">
<img class="divTimg" src="divT/00.jpg" alt="img">
<img class="divTimg" src="divT/01.jpg" alt="img">
<img class="divTimg" src="divT/02.jpg" alt="img">
<img class="divTimg" src="divT/03.jpg" alt="img">
<img class="divTimg" src="divT/04.jpg" alt="img">
<img class="divTimg" src="divT/05.jpg" alt="img">
<div class="clear"></div>
</div>
css
#divT{
overflow-x:hidden;
}
.divTimg{
float:left;
width:17%;
cursor:pointer;
border-right:2px ridge gold;
}
05.jpg is placed in a new line, bellow the rest of images, but I need to keep them all in one line, and if there is no space enough - the last image should be visible partly.
I tried with various values of overflow-x for the parrent div, but without success.

To achieve the 'scrolling off to the side effect' you need to create a wrapper element, that contains a much wider element that then contains your images. This then allows you to shrink or grow the visible section, while having the hidden content appear scrollable.
<div class="scroll">
<div class="scroll_wrapper">
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
<img class="scroll_image" src="" />
// images
</div>
</div>
And then the CSS
.scroll {
width: 200px; // how much you want to see at once
overflow: auto;
}
.scroll_wrapper {
width: 600px; // this can be any number higher than the total width of the elements inside it
}
.scroll_image {
background: red;
height: 10px;
width: 50px; // just to test the scrolling
}
The jsfiddle for this can be found here

Just wrap your image list with another wrapper:
<div id="wrapper">
<div id="divT">
<img class="divTimg" src="divT/00.jpg" alt="img">
<img class="divTimg" src="divT/01.jpg" alt="img">
<img class="divTimg" src="divT/02.jpg" alt="img">
<img class="divTimg" src="divT/03.jpg" alt="img">
<img class="divTimg" src="divT/04.jpg" alt="img">
<img class="divTimg" src="divT/05.jpg" alt="omg">
<div class="clear"></div>
</div>
</div>
Add some styles:
#wrapper {
overflow:hidden;
}
#divT {
width:105%;
}

Related

How to place text inside the background image?

I am working on Bootstrap website. I wanted to place text in the right side of the car. I am getting the output as:
I wanted to place text "hello" in the right side of the Car.
Code:
<div class="row text-center">
<div class="col-sm-6">
<figure>
<img src="images/category/auto.gif" alt=""/>
<figcaption class="main_service">Hello</figcaption>
</figure>
</div>
<div class="col-sm-6">
<figure>
<img src="images/category/auto.gif" alt=""/>
<figcaption>Hello</figcaption>
</figure>
</div></div>
CSS:
.main_auto {background:url(images/category/auto.gif) no-repeat;
background-size: 35% 75%;
}
.main_service {
width:254px;
height:136px;
float:left;
padding:20px 20px 0 90px;
}
I am new to Bootstrap.
You can use css position property. Declare image css position property as relative and text css position property as absolute.
Code:
<div class="row text-center">
<div class="col-sm-6">
<figure>
<img src="images/category/auto.gif" alt="" class="img-disp" />
<figcaption class="main_service">Hello</figcaption>
</figure>
</div>
<div class="col-sm-6">
<figure>
<img src="images/category/auto.gif" alt="" class="img-disp" />
<figcaption class="main_service">Hello</figcaption>
</figure>
</div>
</div>
CSS:
.img-disp{
position: relative;
}
.main_service {
position: absolute;
....
}
Than you can adjust your text position by adding top and left margin to .main_service class.
You can see result here : https://jsfiddle.net/8kcsryqy/

Image gallery in html. How to make images appear the same size?

How to make images from image gallery appear same size? (if originally they have different dimensions).
jsfiddle.net
Add a description of the image here
<div class="img">
<a target="_blank" href="https://unsplash.it/g/300/400">
<img src="https://unsplash.it/g/200/300" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" width="600"height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
Update Css Add img Class In Css. And Remove height :auto in div.img img Class
Note: You Can Change Hight & width in Css
img
{
width:300px;
height:200px;
}
div.img img
{
width: 100%;
}
See Live Demo Here
Snippet Example Below
div.img {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.img:hover {
border: 1px solid #777;
}
div.img img {
width: 100%;
}
div.desc {
padding: 15px;
text-align: center;
}
img
{
width:300px;
height:200px;
}
<!DOCTYPE html>
<body>
<div class="img">
<a target="_blank" href="https://unsplash.it/200/300/?random">
<img src="https://unsplash.it/200/300/?random" alt="Trolltunga Norway" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/300/400">
<img src="https://unsplash.it/g/200/300" alt="Forest" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="https://unsplash.it/g/400/400">
<img src="https://unsplash.it/g/400/400" alt="Northern Lights" >
</a>
<div class="desc">Add a description of the image here</div>
</div>
That depends on how you want to adjust the ones that aren't the same size. In other words, if you have a 300x200 image and a 300x300 image, you could:
stretch the 300x200 one out to 300x300, which would make it look distorted
scale the 300x200 one up so it's large enough to fill a 300x300 box, then crop out or hide the excess
keep the 300x200 one at its normal size but put it in a 300x300 box with some whitespace above and below it
crop the top and bottom of the 300x300 one so it's also 300x200
These are all options you have and they'd all be implemented a little differently, so first figure out which way you want to go.

Can't figure out why :nth-of-type won't work

I'm trying to select every 4th image in my div gallery. I can't seem to figure out why I can't select it.
#gallery img:nth-of-type(4n){
border: 5px solid #000;
}
I've tried a few other ideas but to no success. Can anyone help me and explain to me why this isn't selecting every 4th image in my div gallery? Thanks in advance.
<div id="gallery">
<a href="/system/images/series_uploads/5/original/ankara_5602p_alabaster.jpg?1330114093" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/5/gallery/ankara_5602p_alabaster.jpg?1330114093" title="Ankara" />
<div class="gallery-text">
<h3>Ankara</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/6/original/ankara_5624p_noce.jpg?1330114095" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/6/gallery/ankara_5624p_noce.jpg?1330114095" title="Ankara" />
<div class="gallery-text">
<h3>Ankara</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/7/original/ashton_23931_smokey_beige_.jpg?1330114250" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/7/gallery/ashton_23931_smokey_beige_.jpg?1330114250" title="Ashton" />
<div class="gallery-text">
<h3>Ashton</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/8/original/ashton_23942_camel_haze_entry.jpg?1330114251" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/8/gallery/ashton_23942_camel_haze_entry.jpg?1330114251" title="Ashton" />
<div class="gallery-text">
<h3>Ashton</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/9/original/ashton_23942_camel_haze_lr.jpg?1330114252" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/9/gallery/ashton_23942_camel_haze_lr.jpg?1330114252" title="Ashton" />
<div class="gallery-text">
<h3>Ashton</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/10/original/berkshire_25525_oak.jpg?1330115116" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/10/gallery/berkshire_25525_oak.jpg?1330115116" title="Berkshire" />
<div class="gallery-text">
<h3>Berkshire</h3>
<p>HDP – High Definition Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/11/original/berkshire_25585_walnut_famousdaves01.jpg?1330115118" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/11/gallery/berkshire_25585_walnut_famousdaves01.jpg?1330115118" title="Berkshire" />
<div class="gallery-text">
<h3>Berkshire</h3>
<p>HDP – High Definition Porcelain</p>
</div>
</a>
</div>
they aren't siblings that's why you should use
#gallery a:nth-of-type(4n) img{
border: 5px solid #000;
}

How to make this banner ad same as in another site

How to make red banner ad shown in the top of : http://forum.creditcardpaymentgateways.in/index.php same as shown in this site: http://www.creditcardpaymentgateways.in ?
I've tried to use this code but not working out:
<div id="anu-utility2" WIDTH="525" style="margin:auto auto">
<img style="display:block;width:529px;margin:auto auto" WIDTH="529" HEIGHT="75" src="http://www.creditcardpaymentgateways.in/images/banners/celebrationoffer4.jpg" title="Click here" /></div>
I want to remove the light colored background rectangle behind the red banner(used in the forum):
The forum is in PHPBB and Site is in Joomla.
you should move anu-utility2 to into rt-utility3
Your Example Source Code:
<div id="rt-utility" class="feature-shadows-light">
<div id="rt-utility2">
<div id="rt-utility3">
**<div id="anu-utility2" width="525" style="margin: auto auto">
<a href="http://www.creditcardpaymentgateways.in/pc-tech-support-payment-gateway-new-offer-from-mumbai-based-comapny.html">
<img style="display: block; width: 529px; margin: auto auto" width="529" height="75"
src="http://www.creditcardpaymentgateways.in/images/banners/celebrationoffer4.jpg"
title="Click here"></a></div>**
<div class="rt-grid-6 rt-alpha">
</div>
<div class="rt-grid-2 rt-omega">
</div>
<div class="clear">
</div>
</div>
</div>
</div>
Do you want same as the below image.
You need the gradient image and the below code to achieve this
css:
img
{
border:none;
}
#bannerbg
{
background:url(gradient-div.png) repeat-x;
background-color:#FFFFFF;
height:75px;
}
HTML:
<div id="bannerbg">
<div id="anu-utility2" WIDTH="525" style="margin:auto auto">
<img style="display:block;width:529px;margin:auto auto" WIDTH="529" HEIGHT="75" src="http://www.creditcardpaymentgateways.in/images/banners/celebrationoffer4.jpg" title="Click here" /></div>
</div>

text-align: justify and images

I have a list of images (not in a list, but could be if that might solve the problem) that I want to fill the whole width of a div. I've tried the code at the bottom, and while it does justify any text in the p tag it doesn't do the same for images. How can I get it to evenly space the images across the full width of the div?
<div>
<p>
<img src="image1.png" alt="foo" />
<img src="image2.png" alt="foo" />
<img src="image3.png" alt="foo" />
<img src="image4.png" alt="foo" />
<img src="image5.png" alt="foo" />
</p>
</div>
My CSS:
div { width: 30em; }
p { text-align: justify; }
The simplest way to make it is :
.justify-image{ text-align: justify;}
.justify-image img{display:inline-block;}
.justify-image:after{content:""; display: inline-block; width: 100%; height: 0;}
<p class="justify-image">
<img src="https://via.placeholder.com/150x40" alt="my img">
<img src="https://via.placeholder.com/150x40" alt="my img">
<img src="https://via.placeholder.com/150x40" alt="my img">
<img src="https://via.placeholder.com/150x40" alt="my img">
<img src="https://via.placeholder.com/150x40" alt="my img">
<img src="https://via.placeholder.com/150x40" alt="my img">
</p>
1. You need a container with text-align:justify; (a <p> paragraph in this case.)
2. Your images need to be display:inline-block; else they will not interact as "text" (in justify text last line is not affected you need to add one to make it works.)
3. You need a line of "text" under your images for justifying to apply, with pseudo-element you can achieve it easily by creating a *:after.
*:after :
Don't forget content:"";. Without it, it will not appear. In my example I've used an inline-block with width:100%. It will always break the line after the content in my paragraph.
Happy coding ! :)
Because no one mention in the previous answers. Nowadays (2017) and for awhile ago you can use CSS3 flexbox, by applying the property justify-content:space-between
div {
display: flex;
justify-content: space-between
}
<div>
<img src="https://picsum.photos/50" alt="foo" />
<img src="https://picsum.photos/50" alt="foo" />
<img src="https://picsum.photos/50" alt="foo" />
<img src="https://picsum.photos/50" alt="foo" />
<img src="https://picsum.photos/50" alt="foo" />
</div>
Images are displayed inline so you might as well use the text-align:justify css property to align your images with css. As others suggest, if you want to justify the final row you will have to insert some sort or blank image that takes up the full width at the end of your image list.
See http://fiddle.jshell.net/ewv6K/show/
<!DOCTYPE html>
<title>
Justified Images example
</title>
<style>
body {
text-align:center;
}
#container {
width:800px;
text-align:justify;
margin-left:auto;
margin-right:auto;
}
#force {
width:100%;
height:0px;
}
</style>
<div id="container">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/AfricanWildCat.jpg/220px-AfricanWildCat.jpg" alt="cat 1">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/WhiteCat.jpg/220px-WhiteCat.jpg" alt="cat 2">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Ojo_de_gata_trim.jpg/220px-Ojo_de_gata_trim.jpg" alt="cat 3">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Scheme_cat_anatomy-en.svg/220px-Scheme_cat_anatomy-en.svg.png" alt="cat 4">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Olhos_de_um_gato-3.jpg/220px-Olhos_de_um_gato-3.jpg" alt="cat 5">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Listen%2C_do_you_want_to_know_a_secret.jpg/220px-Listen%2C_do_you_want_to_know_a_secret.jpg" alt="cat 6">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/AfricanWildCat.jpg/220px-AfricanWildCat.jpg" alt="cat 1">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/WhiteCat.jpg/220px-WhiteCat.jpg" alt="cat 2">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Ojo_de_gata_trim.jpg/220px-Ojo_de_gata_trim.jpg" alt="cat 3">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Scheme_cat_anatomy-en.svg/220px-Scheme_cat_anatomy-en.svg.png" alt="cat 4">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Olhos_de_um_gato-3.jpg/220px-Olhos_de_um_gato-3.jpg" alt="cat 5">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Listen%2C_do_you_want_to_know_a_secret.jpg/220px-Listen%2C_do_you_want_to_know_a_secret.jpg" alt="cat 6">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/AfricanWildCat.jpg/220px-AfricanWildCat.jpg" alt="cat 1">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/WhiteCat.jpg/220px-WhiteCat.jpg" alt="cat 2">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Ojo_de_gata_trim.jpg/220px-Ojo_de_gata_trim.jpg" alt="cat 3">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Scheme_cat_anatomy-en.svg/220px-Scheme_cat_anatomy-en.svg.png" alt="cat 4">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Olhos_de_um_gato-3.jpg/220px-Olhos_de_um_gato-3.jpg" alt="cat 5">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Listen%2C_do_you_want_to_know_a_secret.jpg/220px-Listen%2C_do_you_want_to_know_a_secret.jpg" alt="cat 6">
<!-- Force the last row to be justifed - use a blank image here, not a real one like I have -->
<img id="force" src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Olhos_de_um_gato-3.jpg/220px-Olhos_de_um_gato-3.jpg" alt="end">
</div>​
In justified text, the last line of text in a paragraph is not expanded to fill the whole width. So to make the inline images spread out you need enough content to pull the paragraph out to two or more lines, eg.:
<div>
<p>
<img src="image1.png" alt="foo" />
<img src="image2.png" alt="foo" />
<img src="image3.png" alt="foo" />
<img src="image4.png" alt="foo" />
<img src="image5.png" alt="foo" />
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</div>
(or some other equally-ugly but less-visible version involving .) This is a bit of a nasty hack.
I realise this is way out of date but just thought I'd add a simple solution.
text-align: justify will only work if there is more than one line (if you use this on a paragraph of text, you will see that the last line does not justify). This little jQuery extention will add an invisible element to the element you are trying to justify and thus, your images will be evenly spread:
$.fn.justify = function() {
$(this).css("text-align", "justify");
$(this).append("<span style='display: inline-block;visibility: hidden;width:100%'></span>");
}
Then all you need to do is call:
$("#your-element").justify();
This javascript will spread the images over the div from the middleand to the sides:
var container = document.getElementById("imageContainer");
var imageList = container.getElementsByTagName("img");
var totalWidth = container.offsetWidth;
var sliceWidth = totalWidth/imageList.length;
for( i = 0; i < imageList.length; i++)
{
var totalMargin = sliceWidth - imageList[i].offsetWidth;
var margin = totalMargin / 2;
imageList[i].style.margin = "0px " + margin + "px 0px " + margin + "px"
}
The script asume a couple of things;
There must be an ID of the div (imageContainer)
All the images must have the same width
For my convinience I only tested in IE7, there are things that I'm not sure about such as "offsetWidth" that may be different in Firefox etc. but this is mostly for you to get the concept of the script.
You could of course add support for variable image widths and so forth, but that wasn't really in the scope here.
This script will distribute the images evenly if you add or remove images, ofcourse to a limit. If the total width of the images is greater than the width of the div, there will be wrapping.
Hope it helps!
<!-- not elegant -->
<div style="color:backgroundcolor">
<p>
<img src="image1.png" alt="foo"
/><em>.</em>
<img src="image2.png" alt="foo"
/><em>.</em>
<img src="image3.png" alt="foo"
/><em>.</em>
<img src="image4.png" alt="foo"
/><em>.</em>
<img src="image5.png" alt="foo" />
</p>
</div>
My CSS:
div { width: 30em; }
p { text-align: justify; }

Resources