CSS Centering An Image - html

Yes, I know this has been asked countless times and I've read just about every posting I can find but still no solution to my specific issue. On a classified ad site with thumbnail hovers to view the larger image, I need the hovered images to be centered horizontally on the page and vertically within the browser window. So far, when I get it centered horizontally in the browser, the vertical is centered on the page which is often far longer than the window so the images appear either off the screen or at the top edge. If I center it vertically, then it follows the hover horizontally and goes off the screen that way too.
The images, though similar in the HTML example below, are being loaded dynamically and can have varying heights which is part of the problem as I can't simply specify a height. It boils down to the last two CSS blocks with absolute, which causes the vertical centering to work but not the horizontal. Using fixed aligns horizontally but then it's often off the screen vertically. Any ideas?
<p><div class="image-container">
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2079.jpg" alt="hpim2079.jpg" width="69" height="52" /><img class="large-image-style" src="/images/classifieds/68/hpim2079.jpg" alt="hpim2079.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2080.jpg" alt="hpim2080.jpg" width="69" height="52" /><img class="large-image-style" src="/images/classifieds/68/hpim2080.jpg" alt="hpim2080.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2081.jpg" alt="hpim2081.jpg" width="69" height="52" /><img class="large-image-style" src="/images/classifieds/68/hpim2081.jpg" alt="hpim2081.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2082.jpg" alt="hpim2082.jpg" width="69" height="52" /><img class="large-image-style" src="/images/classifieds/68/hpim2082.jpg" alt="hpim2082.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2083.jpg" alt="hpim2083.jpg" width="69" height="52" /><img class="large-image-style" src="/images/classifieds/68/hpim2083.jpg" alt="hpim2083.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2084.jpg" alt="hpim2084.jpg" width="69" height="52" /><img class="large-image-style" src="/images/classifieds/68/hpim2084.jpg" alt="hpim2084.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2115.jpg" alt="hpim2115.jpg" width="70" height="53" /><img class="large-image-style" src="/images/classifieds/68/hpim2115.jpg" alt="hpim2115.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2116.jpg" alt="hpim2116.jpg" width="70" height="53" /><img class="large-image-style" src="/images/classifieds/68/hpim2116.jpg" alt="hpim2116.jpg" width="323" height="244" /></a>
<a class="mouseover-thumbnail-holder" ontouchstart=""><img src="/images/classifieds/68/thumbnails/hpim2117.jpg" alt="hpim2117.jpg" width="70" height="53" /><img class="large-image-style" src="/images/classifieds/68/hpim2117.jpg" alt="hpim2117.jpg" width="323" height="244" /></a>
</div>
The CSS is fairly straightforward with
#media screen and (orientation: portrait) {
img.ri { max-width: 90%; }
}
#media screen and (orientation: landscape) {
img.ri { max-height: 90%; }
}
.image-container {
display: block;
margin: 0 auto 25px auto;
text-align: center;
width: 85%;
}
a.mouseover-thumbnail-holder {
position: relative;
}
.large-image-style {
position: relative;
top: auto; bottom: auto; left: 0; right: 0;
margin: auto;
background-color: #000000;
border-radius: 25px;
border: 10px double #FF0000;
}
a.mouseover-thumbnail-holder .large-image-style {
position: absolute;
display: inline-block;
z-index: 50;
opacity: 0;
pointer-events: none;
top: 50%;
left: 50%;
width: auto;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transition: all 2s ease;
-webkit-transition: all 2s ease;
-ms-transition: all 2s ease;
-moz-transition: all 2s ease;
-o-transition: all 2s ease;
}
a.mouseover-thumbnail-holder:hover .large-image-style , a.mouseover-thumbnail-holder:active .large-image-style {
position: absolute;
z-index: 100;
opacity: 1;
}

All you have to do is use margin: 0 auto; but make sure it has a width on the image

I think this might work for you. Instead of setting position: relative on the a.mouseover-thumbnail-holder element that encloses the image, let the positioning use the root element as the reference point by setting position: fixed on .large-image-style.
If you set all the offsets to zero and then use margin: auto on the image, it will center itself vertically and horizontally in the view port.
.image-container {
display: block;
margin: 0 auto 25px auto;
text-align: center;
width: 85%;
border: 1px dotted blue;
}
a.mouseover-thumbnail-holder .large-image-style {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
opacity: 0;
background-color: #000000;
border-radius: 25px;
border: 10px double #FF0000;
pointer-events: none;
transition: all 2s ease;
}
a.mouseover-thumbnail-holder:hover .large-image-style,
a.mouseover-thumbnail-holder:active .large-image-style {
opacity: 1;
}
.filler {
height: 500px;
border: 1px dotted blue;
}
<div class="filler">Top Filler...</div>
<div class="image-container">
<a class="mouseover-thumbnail-holder">
<img src="http://placehold.it/69x52" />
<img class="large-image-style" src="http://placehold.it/323x244" />
</a>
<a class="mouseover-thumbnail-holder">
<img src="http://placehold.it/69x52" />
<img class="large-image-style" src="http://placehold.it/523x244" />
</a>
<a class="mouseover-thumbnail-holder">
<img src="http://placehold.it/69x52" />
<img class="large-image-style" src="http://placehold.it/323x444" />
</a>
</div>
<div class="filler">Bottom Filler...</div>

Related

How to create a profile photos row with css? [duplicate]

This question already has answers here:
Overlapping/overlaying multiple inline images
(2 answers)
Closed 4 months ago.
i'm trying to create a row with many photos, example;
but i'm having trouble to create the border radius negative.
like this.
i've been trying in this codepen
CodePen
HTML
<div class="d-flex">
<a class="d-inline">
<img alt="project member" class="rounded-circle thumb48" src="https://i.imgur.com/C7sGXc6.png">
</a>
<div class="d-inline person">
<img alt="project member" class="rounded-circle thumb48" src="https://i.imgur.com/C7sGXc6.png">
</div>
<a class="d-inline">
<img alt="project member" class="rounded-circle thumb48" src="https://i.imgur.com/C7sGXc6.png">
</a>
</div>
CSS
.thumb48{
width: 48px !important;
height: 48px !important;
}
.rounded-circle{
border-radius: 50% !impor
}
.d-flex{
display:flex !important;
}
.d-inline{
display: inline !importante;
}
.person{
background-color:red;
position:relative;
}
.person:before
{
width: 10px;;
height: 68px;
border-radius:0 50% 50% 0;
background-color:#FFF;
display:inline-block;
vertical-align: middle;
content: '';
}
You can achieve this cutout effect by putting a solid border on each image that is the same colour as the background:
<div class="circle-overlap">
<img alt="project member" src="https://i.imgur.com/C7sGXc6.png">
<img alt="project member" src="https://i.imgur.com/C7sGXc6.png">
<img alt="project member" src="https://i.imgur.com/C7sGXc6.png">
</div>
.circle-overlap img {
width: 50px;
border-radius: 50%;
border: solid white 5px; // Change to a different colour to visualise more clearly what’s happening
margin-right: 2px;
position: relative;
background: teal;
}
.circle-overlap img:nth-of-type(2) {
left: -25px;
z-index: -1;
}
.circle-overlap img:nth-of-type(3) {
z-index: -2;
left: -50px;
}

how to place an image on top of another image while not having the images moving to other position when screen size is changed

I'm trying to put the lightbulbs in a fixed position above the floor plan, but once I set the position property of the floor plan image to be 'relative', the lightbulb images just couldn't go above the floor plan.
HTML:
<div>
<img src="floorplanff.jpeg" class="background" width="1200px" height="600px">
<img id="lightbulbbr" src="pic_bulboff.gif" width="45px" height="70px" class="br" >
<img id="lightbulbfy" src="pic_bulboff.gif" width="45" height="70" class="fy" >
<img id="lightbulbmr" src="pic_bulboff.gif" width="45" height="70" class="mr" >
<img id="lightbulbt" src="pic_bulboff.gif" width="30" height="50" class="t" >
<img id="lightbulbfmngr" src="pic_bulboff.gif" width="45" height="70" class="mngr" >
<img id="lightbulbar" src="pic_bulboff.gif" width="35" height="65" class="ar" >
</div>
CSS:
.background {
size: 80%;
position: relative;
left: 8%;
top: 40%
}
.br {
position: relative;
right: 15%;
top: 85%;
}
.fy {
position: absolute;
right: 79.8%;
top: 34%;
transform: rotate(90deg)
}
.mr {
position: absolute;
right: 57.5%;
top: 67.5%;
}
my html page
try overflow: visible; on .background and parent div.
And also I would use position absolute on .br

Slider code in email - Want it to work for Gmail

I have asked questions regarding this code before. It is working fine. The only issue is that I would like to use it so the it works in the Gmail web client. It seems to work on Gmail mobile but not desktop and normal online HTML works. I know email clients limit CSS functionality but any help in getting functionality like this working would be great.
WORKING SNIPPET:
body {
margin: 0;
padding: 0;
}
.container {
display:flex;
width:600px;
flex-wrap:wrap;
justify-content:space-between;
}
.slider-holder {
order:-1;
width: 600px;
height: 280px;
background-color: yellow;
text-align: center;
overflow: hidden;
}
.image-holder {
width: 3000px;
background-color: red;
height: 280px;
clear: both;
position: relative;
transition: left 7000s; /*Use a big value to block the image change*/
left: 0;
}
.slider-image {
float: left;
margin: 0px;
padding: 0px;
position: relative;
}
a[href="#slider-image-0"]:hover~.slider-holder .image-holder {
left: 0.5px; /*Yes it's not 0px here, we need something different from the initial state to be able to trigger the transition (Yes I know it's not intuitive ..)*/
transition: left 1s;
}
a[href="#slider-image-1"]:hover~.slider-holder .image-holder {
left: -600px;
transition: left 1s;
}
a[href="#slider-image-2"]:hover~.slider-holder .image-holder {
left: -1200px;
transition: left 1s;
}
a[href="#slider-image-3"]:hover~.slider-holder .image-holder {
left: -1800px;
transition: left 1s;
}
a[href="#slider-image-4"]:hover~.slider-holder .image-holder {
left: -2400px;
transition: left 1s;
}
.button-holder>a>img {
padding-left: 35px;
padding-right: 35px;
}
<div class="container">
<img src="https://via.placeholder.com/70x70" alt="" width="70" style="border-width:0 !important;outline-style:none !important;">
<img src="https://via.placeholder.com/70x70" alt="" width="70" style="border-width:0 !important;outline-style:none !important;">
<img src="https://via.placeholder.com/70x70" alt="" width="70" style="border-width:0 !important;outline-style:none !important;">
<img src="https://via.placeholder.com/70x70" alt="" width="70" style="border-width:0 !important;outline-style:none !important;">
<img src="https://via.placeholder.com/70x70" alt="" width="70" style="border-width:0 !important;outline-style:none !important;">
<div class="slider-holder">
<div class="image-holder">
<img src="https://via.placeholder.com/600x280/ff0000" class="slider-image" />
<img src="https://via.placeholder.com/600x280/00ff00" class="slider-image" />
<img src="https://via.placeholder.com/600x280/f0f0f0" class="slider-image" />
<img src="https://via.placeholder.com/600x280/0000ff" class="slider-image" />
<img src="https://via.placeholder.com/600x280" class="slider-image" />
</div>
</div>
</div>
You should use table layout, inline css and avoid using images as replace of content. Here is great guide: https://litmus.com/blog/a-guide-to-css-inlining-in-email
here is the list of CSS supported by email clients link.
Try to add you CSS classes in head section of HTML.

Absolute Positioning of other Element causes weird Image Spacing by 1px

I have been trying to add an overlay play icon to my videos which all works however after adding this im getting a weird 1px spacing on the bottom row of my images
When the absolute positioning is removed from (#icon) the images align perfectly - but when added back it adds the weird spacing
Could anybody help with this?
CODE: http://www.codeply.com/go/JC75OR4xpD
HTML CODE:
<div class="instaVideos">
<h1>Short Videos</h1>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xaf1/t50.2886-16/11661388_407770589406910_367605487_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-15/11325016_1163164417043690_1908545167_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xtp1/t50.2886-16/1489765_333969910114258_1680134671_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/10706968_601233316654119_1567865956_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xaf1/t50.2886-16/10679292_519402934860781_468618633_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-e-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-15/10665576_441425795996740_1661178998_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xfp1/t50.2886-16/10641919_684721938283340_2079757675_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xap1/t51.2885-15/924582_890120924350870_1658010424_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xfp1/t50.2886-16/10541299_371884109631916_1548975081_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/10538735_664550930296554_1249448005_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="https://scontent-lhr3-1.cdninstagram.com/hphotos-xaf1/t50.2886-16/11683107_112731029066100_1538573428_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-e-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/11386568_1455668744729300_108311835_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xfp1/t50.2886-16/10721731_1471532036461241_1447645097_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/10724656_765518650158719_1752400817_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
<a href="http://scontent-lhr3-1.cdninstagram.com/hphotos-xfa1/t50.2886-16/11679305_467034590127593_1579081935_n.mp4" class="html5lightbox">
<img src="https://igcdn-photos-e-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-15/11429736_699224963557660_1457167025_n.jpg"/>
<img id="icon" src="img/youtubePlayIcon.png"/>
</a>
</div>
CSS:
.instaVideos {
margin:0 auto;
margin-left: auto;
margin-right: auto;
max-width: 800px;
width:90%;
text-align: center;
margin-bottom: 50px;
transition:all .2s ease-in-out;
}
.instaVideos > h1 {
margin:0 auto;
text-align: left;
width:300px;
margin-left: 2%;
font-size: 30px;
font-family: 'raleway';
}
.instaVideos > a > img {
width:150px;
height:auto;
margin-top: 5px;
border:1px solid red;
text-align: center;
}
.instaVideos a:hover {
opacity: 0.7;
}
.instaVideos > a {
position:relative;
}
#icon {
width:auto;
height:30px;
position:absolute !important;
left:35%;
top:0px;
right:0px;
display:inline !important;
}
SOLVED
I fixed this by doing the follwing:
.instaVideos {
position:relative;
}
#icon {
position: absolute;
left:0;
right:0;
top:0;
margin: 0 auto;
}
Maybe this help you: Fiddle
CSS:
.instaVideos > a {
position: relative;
height: 100%;
width: auto;
display: inline-block;
}
#icon {
width:auto;
height:30px;
position:absolute !important;
left:50%;
top:50%;
transform: translate(-50%, -50%);
}

CSS slider not workin in IE

I am using a CSS slider on my ebay page (as ebay won't let you upload scripts, etc) but I found that it won't work in IE. Coyldn't figure out how to fix it. Is there a way around it? Or is there a slider with no scripts and that works in IE8+?
Here is the css:
img {
border: none;
}
a {
outline: none;
}
/* Fades in the slideshow. Hides the initial animation on the li tag.*/
#-webkit-keyframes fadeIn {
0% {
opacity: 0;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
ul#slider {
-webkit-border-radius: 10px;
margin: 0px;
padding: 0px;
list-style: none;
position: relative;
width: 700px;
height: 438px;
overflow: hidden;
}
ul#thumb {
overflow: none;
margin: 0px 0px 0px 0px;
padding: 0px;
list-style: none;
position: relative;
background: #000;
overflow: auto;
width: 700px;
}
ul#thumb a {
-webkit-transition: opacity .2s ease-in-out;
border: 1px solid #979797;
width: 70px;
height: 50px;
display: block;
overflow: hidden;
float: right;
margin: 10px 0px 0px 10px;
opacity: 0.75;
}
ul#thumb a:hover {
opacity: 1;
}
ul#slider li {
width: 700px;
height: 438px;
position: absolute;
}
ul#slider li p {
position: absolute;
bottom: -1px;
left: 0;
z-index: inherit;
color: #fff;
background: rgba(0, 0, 0, .5);
width: 100%;
}
ul#slider li p span {
line-height: 0.5em;
padding: 10px;
display: block;
}
/* Animation for the :target image. Slides the image in. */
#-webkit-keyframes moveTarget {
0% {
left:-700px;
}
100% {
left:0px;
}
}
ul#slider li:target {
-webkit-animation-name: moveTarget;
-webkit-animation-duration: .5s;
-webkit-animation-iteration-count: 1;
top:0px;
left: 0px;
z-index: 10;
}
/*
Animation for the current image. Slides it out the frame and back to the starting position.
Adds a lower z-index than the now current image.
*/
#-webkit-keyframes moveIt {
0% {
left:0px;
}
50% {
left:700px;
}
100% {
left:-700px;
z-index: 5;
}
}
ul#slider li:not(:target) {
-webkit-animation-name: moveIt;
-webkit-animation-duration: 1.5s;
-webkit-animation-iteration-count: 1;
top:0px;
left: 0px;
}
And HTML:
<ul id="slider"> <li id="1"> <img src="(image link)" alt="" width="700" height="438" />
</li><li id="2"> <img src="(image link)" alt="" width="700" height="438" />
</li>
<li id="3"> <img src="(image link)" alt="" width="700" height="438" />
</li>
<li id="4"> <img src="(image link)" alt="" width="700" height="438" />
</li>
<li id="5"> <img src="(image link)" alt="" width="700" height="438" />
</li>
</ul>
<ul id="thumb">
<li><img src="(image link)" alt="" width="70" height="50" /></li>
<li><img src="(image link)" alt="" width="70" height="50" /></li>
<li><img src="(image link)" alt="" width="70" height="50" /></li>
<li><img src="(image link)" alt="" width="70" height="50" /></li>
<li><img src="(image link)" alt="" width="70" height="50" /></li>
</ul>
</div>
Maybe you should check out canIuse.com to see browser compatibilities. It could be helpful!
Unfortunately a cross browser, pure CSS image slider is not cur­rently a real­istic option. Using this slider is going to cause issues in earlier ver­sions of Internet Explorer no mat­ter what you do. If you need reas­on­able browser sup­port then you will have to look at a slider that uses Javascript.
All of those -webkit prefixes indicate that whatever CSS you copied and pasted is intended to work only with webkit browsers (Google Chrome, Safari, etc...)
Unfortunately, without webkit, I can't think of many CSS-only gallery solutions.