Jump to content

Website image "problem"

robeng
Go to solution Solved by linusforsell,

The solution depends a bit on how you've implemented the image.

The simplest way would be to use a background image, center it and set it to cover the available space.
 

.image-class-you-use {
	background-image: url(your-url);
	background-position: center;
	background-size: cover;
}


 

Hi! We have a school project were we shall make a website. I have a "problem" with a image. It is kind of hard to explain the problem but I will try and I have uploaded a video to try to make it more understandible. What I want to do is to make a image not scale on the width when it scale on the height. At the moment when I drag the window witch makes the height change the image width changes and the picture looks realy bad. Look at this video and see for your selfs.

I want the picture to work as in gmail.

Thanks in advance!

 

Link to comment
Share on other sites

Link to post
Share on other sites

Can you give me some of the code of the image? (either just the HTML or the CSS if you have that too).

I feel like you are setting the height and width of the image independently, so the image always wants to have half the page's width, but at the same time also wants to be the height of the text. Causing this effect.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

The image in gmail is centered, fixed height+width, and has overflow on so that the edges just get hidden when the width changes.

If you want more help you will need to post your html code so that people can see and fix it.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

The solution depends a bit on how you've implemented the image.

The simplest way would be to use a background image, center it and set it to cover the available space.
 

.image-class-you-use {
	background-image: url(your-url);
	background-position: center;
	background-size: cover;
}


 

Cheers,

Linus

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Minibois said:

Can you give me some of the code of the image? (either just the HTML or the CSS if you have that too).

I feel like you are setting the height and width of the image independently, so the image always wants to have half the page's width, but at the same time also wants to be the height of the text. Causing this effect.

For the code I have an class that sets the image width to 50% of the page. To set the hight I use the event onrezise that calls a function that gets the height of the section next to the image and set the image height to that. javascript code:

function sätHöjd() {
	var y = document.getElementById("s1").offsetHeight;
	document.getElementById("img1").style.height = y + "px";
}
sätHöjd();

 

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, linusforsell said:

The solution depends a bit on how you've implemented the image.

The simplest way would be to use a background image, center it and set it to cover the available space.
 


.image-class-you-use {
	background-image: url(your-url);
	background-position: center;
	background-size: cover;
}


 

So I should have a div with a background image or can I set thouse properties in my img tag?

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, robeng said:

So I should have a div with a background image or can I set thouse properties in my img tag?

A div would be preferable, yes. :)

Cheers,

Linus

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×