So, I've being driven insane by this simplistic issue
through css and html i want to scale image and text by hovering over the image i already got the image transition to work. But I'm really struggling to get text to scale below the image by the same amount. I want the text to follow image below it and scale in tandem to the image. Soz if i'm not very good :)
img {
width: 370px;
height: 370px;
transition: all 1s;
}
img:hover {
width: 500px;
height: 500px;
}
<img src="https://i.imgur.com/TSfq6rd.jpg" alt="">
<img src="https://i.imgur.com/Pu8JqbA.jpg" alt="" style="padding-top: 300px; padding-left: 5px; padding-right: 20px">
<p style="position: absolute; padding-top: 600px">TEST</p>
I don't understand your question. What do you mean by "tandem"? Do you want that the text scales at the same time with the picture? If you want this is better to put both the picture and text insde a div.
Position absolute for p isn't the right choice here.
Maybe try position: relative.
You can also remove the top padding and position from your inline style then.
Related
So I have a simple element with a png image in it, however on my page, only some areas of the image are click-able. I have no idea what the problem is.
#thumbnail {
position: relative;
float: left;
height: 350px;
padding-left: 25px;
padding-right: 100px;
}
<img id="thumbnail" src="Design.png">
As you can see there is nothing unusual about the image, I don't know why it is doing this. Also in the areas that you can't click, the cursor of course does not change to the pointer.
Turns out it was an issue with the z-index of the image being the same as the div it was in.
I apologize if this has been answered time and time again. I remember searching thoroughly for an answer a couple years ago when I first wrote up my website script, but I couldn't ever find one. The same for now.
Recently I reworked my website's script so I can host it onto Weebly. Here is one of the four pages of my site that I need help with. As you can see, the images that pop up when the thumbnail is hovered over are absolutely positioned. For most computer resolutions and/or browsers, this will have the image appear out of the designated box.
How could I position them to the inner top left corner of the div? Or better yet, horizontally and vertically centered within it?
<section id="Sizes" style="float: left">
<a href="#Space">
<img class="Small" src="/files/theme/SampleD_Fun_Icon.png" width="150" height="150" alt="Sample 1: Day of Fun" />
<img class="Large" src="/files/theme/SampleD_Fun.png" width="150" height="150" alt="Sample 1: Day of Fun" />
</a>
...
</section>
<a id="Space"></a>
<span class="Popup">Hover over thumbnail to display sample artwork.</span>
<br style="clear: left" />
a:hover img.Small
{
border: 5px solid #21568b;
margin: 10px;
text-decoration: none;
}
section#Sizes a img.Large
{
border-width: 0;
height: 0;
left: 438px;
position: absolute;
top: 326px;
width: 0;
}
section#Sizes a:hover img.Large
{
height: 526px;
left: 438px;
position: absolute;
top: 326px;
width: 520px;
}
.Popup
{
border: 3px solid;
float: left;
height: 272px;
margin: 8px 20px 0px 0px;
padding-top: 254px;
text-align: center;
width: 520px;
}
Thank you for your time. :)
Your whole design is a bit fragile, and I wouldn't recommend building this this way in the first place, but you're looking for practical answers, so here's the smallest change I can think of that fixes your problem:
1) Add this to your style sheet:
body { position: relative; }
2) On line 40 from your main_style.css, change top: 326px to top: 316px and left: 438px to left: 428px, so that it becomes like this:
section#Sizes a:hover img.Large {position: absolute; top: 316px; left: 428px; width: 520px; height: 526px;}
How does that work?
Your images are place using absolute positioning. By default, that works relative to the viewport (the window). But by turning the body into position relative, it becomes a containing block, and position absolute is relative to the nearest containing block ancestor.
So now, your images are fixed within the body element, instead of being fixed relative to the window. Since the margins of the body element is what's changing size when you resize the window, that makes the various pieces of your content fixed relative to each other. You then just need to remove 10px from the top and left side, since that's the size of the border of your body element, and we're now measuring from inside the border.
TLDR: You can't do this in pure CSS.
You can easily position the image inside the container div if you place the image element inside the div element, and then use absolute positioning like top: 0; left: 0; (or with a number of other methods). But then you'd need JavaScript to correlate the hovered thumbnail with the popup full-size image.
Alternatively, you can have the full-size image be nested in the thumbnail element (like you currently have), but then you'd need JavaScript to position the full-size popup image inside the container div.
Of the two alternatives, I recommend the first: put all the popup images inside the target container, and use JavaScript to show or hide them when a thumbnail is hovered. Correlating the thumbnail and the full size image via JavaScript is going to be easier then writing positioning code.
I see you're using jQuery already so why not do something like this?
$('.Small').on('mouseover', function(){
$('.Popup').empty().html($(yourtarget).attr('img' , 'src'));
});
$('.Small').on('mouseout', function(){
$('.Popup').empty().html('Hover over thumbnail to display sample artwork.');
});
Just because everyone was saying it can't be done with pure css, I wanted to demonstrate that it can, and it is even quite easy. Have a look at the folowing example:
http://jsfiddle.net/aafa2zp5/
<div id='images-wrapper'>
<ul>
<li>
<img class='small' src='http://placehold.it/50/ff0000'/>
<img class='big' src='http://placehold.it/300/ff0000'/>
</li>
<!-- and some more similar thumb / image groups -->
</ul>
<div class='preview-area'></div>
</div>
CSS (or the relevant part at least)
#images-wrapper {
position: relative;
}
.big {
display: block;
position: absolute;
top: 54px;
right: 54px;
opacity: 0;
transition: opacity .5s;
}
.preview-area {
width: 350px;
height: 350px;
border: 4px solid blue;
position: absolute;
top: 21px;
right: 21px;
}
li:hover .big {
opacity: 1;
}
The key is to set a position relative to the wrapper (and keep all of the descendants as their default static). Then you can use this to position the preview area and the big images against by setting them to postion absolute and carefully calculating the correct postion. I even added a cross fade, just because it is so easy, but you could just as well work with display block / none if you prefer.
For smaller screens you may want to alter the dimensions and positioning inside a media query, but it still should be doable (though depending on the hover state is perhaps not the best idea on a touch device)
I hope you get the idea and you can figure out how to apply this technique to your own site. Feel free to ask if you want me to explain further or when you get stuck.
I have images being passed dynamically to the UI and they can sent as any size size. I then need to scale them to specific sizes depending on which img tag that image is going to be displayed in. These images need to be circles of a statically set size, but not ovals and when they are cropped I want the circle to come from the center of my image.
I have created a circular image using boostrap's img-circle:
<img class="img-circle" src="image.jpg" width="117px" height="117px"/>
I have many of similar images of various sizes being layed out using:
<div class="row" style="margin: -40px 10px 30px">
This is working, except my images are ending up stretched to fit the circle rather than just cropping from it. Is there any simple way I can cause them to crop vs stretch?
I'm hoping I can do this just using my img tag, as using something with "background-image" seems to mess up my layout.
Added a fiddle:
http://jsfiddle.net/jgt1qy7y/1/
You should enclose your image in a parent div.
The only thing .img-circle does is apply border-radius: 50%; It will inherit the width and the height of the chosen element. If those are not equal it will be an oval. In that case you will have to define sizes but then the images will get distorted. So that's why you need a parent div. To set the width and the height, and not distort the image.
.img-circle {
border-radius: 50%;
position: relative;
height: 117px;
width: 117px;
overflow: hidden;
float: left;
margin-right: 10px;
}
.img-circle.hor img {
position: absolute;
left: 50%;
width: auto;
height: 117px;
transform: translateX(-50%);
}
.img-circle.vert img {
position: absolute;
top: 50%;
width: 117px;
height: auto;
transform: translateY(-50%);
}
<div class="img-circle hor">
<img src="http://placehold.it/350x150" />
</div>
<div class="img-circle vert">
<img src="http://placehold.it/150x350" />
</div>
Right, as far as I can answer from the information you've provided, you're setting the image tag to have 117px in both height and width. This is the IMG tag you're changing, and so every image will be stretched TO that specification.
So, you have two options:
1) You can either set a specific width or height and allow the circle to be auto width or height, e.g
.img-circle{
width:auto;
height:auto;
width:117px;
max-height:117px;
}
On this I have set a max height of 117px so that HUGE long ones don't go overboard, but this will make them tiny in the circle http://jsfiddle.net/jgt1qy7y/8/
Or, secondly, you could create a DIV with fixed width 117px by 117px (I'm assuming you're using this as profile pictures or something?), then dynamically modify the style of the DIV to add a background image then configure that in your CSS:
.img-circle{
width:117px;
height:117px;
}
For your div. Then, you can dynamically output the URL of the image into your STYLE of the div
<div class="img-circle" style="background-image:url('echo your url here');"></div>
You can then style the background image by adding CSS to your .img-circle:
.img-circle{
background-size:contain/cover;
background-repeat:no-repeat;
backgrund-position:50% 50%;
}
You'll have to check out cropping an image in javascript if you want the image to fit exactly how you want it, but you get the jist.
Disclaimer: I've never properly learned CSS from websites, I've picked it up as I've gone along... Sorry if this is written badly!
I got a question: I have an image in a div. the image is bigger that the div and it has height:100% to make it look ok. So when I do a resize image becomes bigger and it looks fine. but when I resize the browser to make it smaller image becomes smaller, but its parent saves the width of the original image. In fact it just takes the width of an image. I got a fiddle for you, just try to resize your browser or the output section to see the red background appear. I'm curious is there any chance to make the div dimenstions the same as the image's dynamically. I need the container dimensions cause I have some other elements besides the image and they use the coordinates of the div. thanks.
important! it works the way I saw it only in FireFox. Chrome's behaviour is different.
.img-wrapper {
display: inline-block;
height: 100%;
position: relative;
background-color: red;
}
.gallery-image {
bottom: 90px;
left: 0;
position: absolute;
right: 0;
text-align: center;
top: 25px;
background-color: grey;
}
img {
height: 100%;
}
<div class="gallery-image">
<div class="img-wrapper">
<img src="http://www.ibm.com/big-data/us/en/images/bigdata_homepage_maininfographic_345x194.jpg" alt=""/>
</div>
</div>
This is usually done with CSS using background-image:url("http://www.ibm.com/big-data/us/en/images/bigdata_homepage_maininfographic_345x194.jpg").. This way your image and div become one object. Then you just control the div and the background image size accordingly.
Side Note... It helps with performance as well.
You can set the minimum dimensions of an image so it won't become any smaller like this
img {
min-height: 200px;
min-width: 400px;
}
I have a header in a HTML page that contains a curve.
My Problem: The curve is a picture & it sits at the highest z-index. It is meant to cut off some text below it so it has the highest z-index. As a result, none of the links below the image(curve) can be clicked because the picture sits on top of them.
Heres the simple JSFiddle: http://jsfiddle.net/hE7D5/2/
How can I get my links below the image to be clickable?
The easiest way I know is to make the image have the css: pointer-events: none; BUT this doesn't work in IE & I am looking for the most Cross-Browser friendly solution.
<div id="headerContainer" style="position: relative; width: 100%; text-align: center; background-color: yellow;">
<div id="header" style="width: 1100px; height: 400px; padding-left: 30px; padding-right: 30px;">
<ul id="navbar" style="background-color: red; width: 800px; height: 40px; float: left;"></ul>
<a id="logo" href="www.google.com" style="background-color: red; width: 190px; height: 40px; float: right; margin-top: 15px;">Cant be Clicked</a>
<br/>
<div id="cutOffText">
<p style="padding: 0; margin: 0; font-size: 200px;">ABCDEFG</p>
</div>
</div>
<div id="curveOverlay" style="z-index: 1; position: absolute; left: 0; top: 0; background-image: url('http://i44.tinypic.com/rs8y7m.png'); background-position: center bottom; background-repeat: no-repeat; width: 1100; height: 400px;">
</div>
</div>
PS: If theres no way to make the links clickable when under the image, can you suggest a HTML layout I can use to still achieve my look but also have my navbar links clickable?
You could have your elements, that currently sit under the graphic, be on top of it with their backgrounds set to be mostly transparent. This way, the text would be above the image, whereas the background color would seem to be behind or inline with the graphic.
If you are able to precisely control the layout of what's behind the image, you could duplicate that layout above the image using "empty" links with the same dimensions (which I've outlined with a dashed green line in the image below).
In your example you might be able to use cssSandpaper to rotate the image of the curve.
If you slightly modify your curve the button will become totally clickable.
Isn't this working?
#logo {
position: relative;
z-index: 10;
}
simply put : you can't. not without a lot of effort. to achieve this effect, you'd need the image to be a imagemap and then make sure that it's pixel-perfect to the stuff that it's obscuring.
to be honest, this looks like a pretty bad idea, but you may have some legitimate reason to do this
EDIT : looks like a duplicate of this