How to maintain position and size for all window sizes in CSS?












-2















I want the image to be at the center of the window, and of the same size irrespective of the window size. Im not sure on how to do this, any kind of help will be appreciated.










share|improve this question























  • Can you add the HTML code where you're placing this image, please?

    – Angel Garcia
    Nov 24 '18 at 8:25






  • 3





    What do you mean by “center”? Vertically? Horizontally? Both? Should it be on top of other elements or does it stay within the normal document flow? Currently your question is too broad as there are so many ways to do this.

    – insertusernamehere
    Nov 24 '18 at 8:25






  • 1





    Can't answer properly without seeing your HTML and how you are placing the image. Also mention what you have tried and how it is different from your expected html behavior.

    – Bidhan Majhi
    Nov 24 '18 at 10:21
















-2















I want the image to be at the center of the window, and of the same size irrespective of the window size. Im not sure on how to do this, any kind of help will be appreciated.










share|improve this question























  • Can you add the HTML code where you're placing this image, please?

    – Angel Garcia
    Nov 24 '18 at 8:25






  • 3





    What do you mean by “center”? Vertically? Horizontally? Both? Should it be on top of other elements or does it stay within the normal document flow? Currently your question is too broad as there are so many ways to do this.

    – insertusernamehere
    Nov 24 '18 at 8:25






  • 1





    Can't answer properly without seeing your HTML and how you are placing the image. Also mention what you have tried and how it is different from your expected html behavior.

    – Bidhan Majhi
    Nov 24 '18 at 10:21














-2












-2








-2


0






I want the image to be at the center of the window, and of the same size irrespective of the window size. Im not sure on how to do this, any kind of help will be appreciated.










share|improve this question














I want the image to be at the center of the window, and of the same size irrespective of the window size. Im not sure on how to do this, any kind of help will be appreciated.







html css web-frontend visual-web-developer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 8:08









Deeraj TheepshiDeeraj Theepshi

123




123













  • Can you add the HTML code where you're placing this image, please?

    – Angel Garcia
    Nov 24 '18 at 8:25






  • 3





    What do you mean by “center”? Vertically? Horizontally? Both? Should it be on top of other elements or does it stay within the normal document flow? Currently your question is too broad as there are so many ways to do this.

    – insertusernamehere
    Nov 24 '18 at 8:25






  • 1





    Can't answer properly without seeing your HTML and how you are placing the image. Also mention what you have tried and how it is different from your expected html behavior.

    – Bidhan Majhi
    Nov 24 '18 at 10:21



















  • Can you add the HTML code where you're placing this image, please?

    – Angel Garcia
    Nov 24 '18 at 8:25






  • 3





    What do you mean by “center”? Vertically? Horizontally? Both? Should it be on top of other elements or does it stay within the normal document flow? Currently your question is too broad as there are so many ways to do this.

    – insertusernamehere
    Nov 24 '18 at 8:25






  • 1





    Can't answer properly without seeing your HTML and how you are placing the image. Also mention what you have tried and how it is different from your expected html behavior.

    – Bidhan Majhi
    Nov 24 '18 at 10:21

















Can you add the HTML code where you're placing this image, please?

– Angel Garcia
Nov 24 '18 at 8:25





Can you add the HTML code where you're placing this image, please?

– Angel Garcia
Nov 24 '18 at 8:25




3




3





What do you mean by “center”? Vertically? Horizontally? Both? Should it be on top of other elements or does it stay within the normal document flow? Currently your question is too broad as there are so many ways to do this.

– insertusernamehere
Nov 24 '18 at 8:25





What do you mean by “center”? Vertically? Horizontally? Both? Should it be on top of other elements or does it stay within the normal document flow? Currently your question is too broad as there are so many ways to do this.

– insertusernamehere
Nov 24 '18 at 8:25




1




1





Can't answer properly without seeing your HTML and how you are placing the image. Also mention what you have tried and how it is different from your expected html behavior.

– Bidhan Majhi
Nov 24 '18 at 10:21





Can't answer properly without seeing your HTML and how you are placing the image. Also mention what you have tried and how it is different from your expected html behavior.

– Bidhan Majhi
Nov 24 '18 at 10:21












2 Answers
2






active

oldest

votes


















0














Or you can use JavaScript to do it



In case the piscture is 600px x 400px:



var w = ((window.innerWidth)-600)/2;
var h = ((window.innerHeight)-400)/2;
var img = document.getELementByTagName('IMG')[0];
img.style.marginLeft = w+'px';
img.style.marginTop = h+'px';





share|improve this answer
























  • Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

    – Bidhan Majhi
    Nov 24 '18 at 10:26



















-2














You must just add the concrete size of the picture in CSS, like this:



      img {
width: 600px;
height: 400px;
}


The image will be 600px x 400px in all screen resolutions.






share|improve this answer



















  • 1





    This doesn't make it centered though. For instance, use margin: auto

    – ProgrammerPer
    Nov 24 '18 at 8:41











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456347%2fhow-to-maintain-position-and-size-for-all-window-sizes-in-css%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Or you can use JavaScript to do it



In case the piscture is 600px x 400px:



var w = ((window.innerWidth)-600)/2;
var h = ((window.innerHeight)-400)/2;
var img = document.getELementByTagName('IMG')[0];
img.style.marginLeft = w+'px';
img.style.marginTop = h+'px';





share|improve this answer
























  • Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

    – Bidhan Majhi
    Nov 24 '18 at 10:26
















0














Or you can use JavaScript to do it



In case the piscture is 600px x 400px:



var w = ((window.innerWidth)-600)/2;
var h = ((window.innerHeight)-400)/2;
var img = document.getELementByTagName('IMG')[0];
img.style.marginLeft = w+'px';
img.style.marginTop = h+'px';





share|improve this answer
























  • Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

    – Bidhan Majhi
    Nov 24 '18 at 10:26














0












0








0







Or you can use JavaScript to do it



In case the piscture is 600px x 400px:



var w = ((window.innerWidth)-600)/2;
var h = ((window.innerHeight)-400)/2;
var img = document.getELementByTagName('IMG')[0];
img.style.marginLeft = w+'px';
img.style.marginTop = h+'px';





share|improve this answer













Or you can use JavaScript to do it



In case the piscture is 600px x 400px:



var w = ((window.innerWidth)-600)/2;
var h = ((window.innerHeight)-400)/2;
var img = document.getELementByTagName('IMG')[0];
img.style.marginLeft = w+'px';
img.style.marginTop = h+'px';






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 8:48









Bálint CséfalvayBálint Cséfalvay

649




649













  • Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

    – Bidhan Majhi
    Nov 24 '18 at 10:26



















  • Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

    – Bidhan Majhi
    Nov 24 '18 at 10:26

















Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

– Bidhan Majhi
Nov 24 '18 at 10:26





Consider adding both of your answer at one place, when you want to write two. That will give a proper idea to the person who is asking.

– Bidhan Majhi
Nov 24 '18 at 10:26













-2














You must just add the concrete size of the picture in CSS, like this:



      img {
width: 600px;
height: 400px;
}


The image will be 600px x 400px in all screen resolutions.






share|improve this answer



















  • 1





    This doesn't make it centered though. For instance, use margin: auto

    – ProgrammerPer
    Nov 24 '18 at 8:41
















-2














You must just add the concrete size of the picture in CSS, like this:



      img {
width: 600px;
height: 400px;
}


The image will be 600px x 400px in all screen resolutions.






share|improve this answer



















  • 1





    This doesn't make it centered though. For instance, use margin: auto

    – ProgrammerPer
    Nov 24 '18 at 8:41














-2












-2








-2







You must just add the concrete size of the picture in CSS, like this:



      img {
width: 600px;
height: 400px;
}


The image will be 600px x 400px in all screen resolutions.






share|improve this answer













You must just add the concrete size of the picture in CSS, like this:



      img {
width: 600px;
height: 400px;
}


The image will be 600px x 400px in all screen resolutions.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 8:21









Bálint CséfalvayBálint Cséfalvay

649




649








  • 1





    This doesn't make it centered though. For instance, use margin: auto

    – ProgrammerPer
    Nov 24 '18 at 8:41














  • 1





    This doesn't make it centered though. For instance, use margin: auto

    – ProgrammerPer
    Nov 24 '18 at 8:41








1




1





This doesn't make it centered though. For instance, use margin: auto

– ProgrammerPer
Nov 24 '18 at 8:41





This doesn't make it centered though. For instance, use margin: auto

– ProgrammerPer
Nov 24 '18 at 8:41


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456347%2fhow-to-maintain-position-and-size-for-all-window-sizes-in-css%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland