How to maintain position and size for all window sizes in CSS?
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
add a comment |
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
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
add a comment |
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
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
html css web-frontend visual-web-developer
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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';
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
add a comment |
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.
1
This doesn't make it centered though. For instance, usemargin: auto
– ProgrammerPer
Nov 24 '18 at 8:41
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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';
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
add a comment |
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';
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
add a comment |
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';
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';
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
add a comment |
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
add a comment |
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.
1
This doesn't make it centered though. For instance, usemargin: auto
– ProgrammerPer
Nov 24 '18 at 8:41
add a comment |
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.
1
This doesn't make it centered though. For instance, usemargin: auto
– ProgrammerPer
Nov 24 '18 at 8:41
add a comment |
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.
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.
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, usemargin: auto
– ProgrammerPer
Nov 24 '18 at 8:41
add a comment |
1
This doesn't make it centered though. For instance, usemargin: 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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