Fit image to its full width of screen - html

I am trying to fit an image to its full width of the browser. Please let me know CSS code for that. I am using px for container. So let me know according to that. I don't want scroll bars to full screen of the browser. I am trying width:100%, width in px. But nothing works I see scroll bar.

Images have their own display type in CSS, so when you say something like width:100%, it fills to 100% of the original image's dimensions rather than acting like a block and expanding to fill 100% of the parent element.
You can fix that by changing the display type, though only for that one image:
<style type="text/css">
img.big-img {
display:block;
width:100%;
}
</style>
…
<img src="my_image.jpg" class="big-img">

If you want it to depend on browser's viewport add this to your element's css and it will stretch automatically
background-size: 100% 100%;

img{
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
}

Related

How to make image stay at its size when i zoom the browser

I am trying to make a landing page consist only of images, basically its more like a banner. But the problem is, when i try to zoom in or zoom out on my chrome the image will resize itself. I have tried using width 100% and height auto but the problem still arise.
Can anyone help me solve the problem ?
Thanks
This is correct, 100% and auto are relative values, you want static, ie set width and heighth to some value via css.
do something like this
<div class="cover">
<img src="/set path" alt="" />
</div>
Write CSS like this way
.cover {
width:100vh;
height:100vh;
float:left;
}
.cover img {
width:100%;
height:100%; /* or you can set `vh` height */
}

Overflow has no background

I have an article styled like with this class:
.stretchedToMargin {
display: block;
position:absolute;
height:100%;
bottom:0;
top:0;
left:0;
right:0;
}
This is fine: the article takes always at least the whole vertical space. For articles longer than the screen, a scrollbar is shown.
But, for articles extending further than the screen, when I need to scroll to view the content, the background is not set. The article is split between a part with the right background and a part with the wrong background.
How can I force my article to be actually as high as the content, but at least as high as the viewport?
EDIT
Adding an example: http://jsbin.com/UvasEBik/1/
An the corresponding screenshot:
You could use min-height: 100vh which is 100% of the viewport height. So the article would be at least 100% of the viewport height.

overlay resize with CSS

I have a popup overlay that I'm currently resizing with some jquery code. I'm looking to change this implementation to work only with CSS. This is the general setup I have along with the jsFiddle
<div id="BigDiv"></div>
<div id="Overlay"></div>
#Overlay{
background:red;
opacity:0.6;
position:absolute;
top:0;
left:0;
width:100%;
height:100%}
#BigDiv{
height:2000px;
width:2000px;
background:blue;}
As you can see, the overlay is sized at 100% width and height so when the user looks at the overlay, it fills the screen. However, when the user scrolls, the overlay isn't resized. How can I change this to make the resize work only with CSS, if at all possible.
Thanks.
Using position:fixed instead of absolute which will place the overlay at a
specified position relative to the screen's viewport and doesn't move when scrolled
You can keep the width:100%;height:100% or use a full top:0;right:0;bottom:0;left:0; positioning system - both should make the overlay cover the whole viewport.

Fixed div background

I want to create a layout where I want to display an image to the left and content on the right. The image should stay constant when the content scrolls.
The css I'm using:
<style type="text/css">
#page-container
{
margin:auto;
width:900px;
background-color:Black;
}
#header
{
height:150px;
width:650px;
}
#main-image
{
float:left;
width:250px;
height:500px;
background-image:url('../images/main-image.png');
position:fixed;
}
#content
{
margin-left:250px;
padding:10px;
height:250px;
width:630px;
background-color:Teal;
}
</style>
The HTML:
<div id="page-container">
<div id="header"><img src="someimagelink" alt="" /></div>
<div id="main-image"></div>
<div id="content"></div>
</div>
Alot of time on this site and I have understood that background-attachment:fixed positions the image in the entire viewport and not the element it is applied to.
My question is how do I go about creating that kind of layout?
I do not want to give that image as a background image, as if the window is resized, it might get hidden. I want scrollbars to appear if the window size is less than 900px( my page width) so that the image can be viewed at all times.
That happens with this code, however I would like the image to start at my element instead.
How do I go about doing this??
Thanks in Advance :)
Edited:
I took the advice and added a position:fixed property to #main-image. Using the HTML and CSS as shown above.
Now, I also want to fix the header so that it does not move. Basically, only my content section should scroll.
However, if I add a position:fixed to the header, my #main-image and #content now sit on top of my header.
If I add a margin-top:150px (since my header height is 150px) to the #main-image, it works fine and moves down appropriately.
However if I add a margin-top:150px to the #content, my header moves down by 150px and still sits on top of my #content.
Can someone please explain why this is happening?
Thanks in Advance :)
Take a look at this link:
http://www.barelyfitz.com/screencast/html-training/css/positioning/
You can learn how to position Div's with it.
This will solve your problem:
#main-image {position:fixed;}
EDIT:
I'm not sure of what caused your problem but here is the solution:
#content{
position:relative;
top:150px;
}
My Guess:
I think that happened because when using position:fixed those 2 div's were positioned relative to the the browser window, while the other one was relative to the document itself.
In this link you will see more about positioning and you can test some of these features related to the position property:
http://www.w3schools.com/cssref/pr_class_position.asp
About the fact that one div was positioned over another, you should search for the 'z-index' property. Firefox has a 3D mode so you can see this more clearly:
http://www.addictivetips.com/internet-tips/browse-internet-in-3d-using-mozilla-firefox-11-tip/
Set a min-width on html and body.
Have you tried setting your #page-container to relative and your #main-image container to absolute and setting the position using top, bottom, etc. Then you should also be able to float your #content container to the right.

image won't position at bottom in html

I have a menu bar that I want to place at the bottom of my screen. I've set the positioning to absolute and the distance from bottom to '0', but for some reason, it won't move from the middle of the screen, regardless of how I try to position it. Can anyone catch what I am doing wrong?
<div class=bmenu>
<img src="bottommenu.gif" width=100% height="39" alt="" />
</div>
<style>
.bmenu
{
position:absolute;
z-index: 2;
bottom:0;
left:0;
width:100%;
}
</style>
Edit:
Several commenters have said that this code places it at the bottom for them. Does this mean that the problem is coming from the way this code fragment is interacting with the rest of the code? Does anyone know what could cause that?
If you use any of the browser's web inspectors, you'll see that the height of your <html> and <body> elements aren't 100%, but auto, which means they'll only be as tall as the content within them expands them to.
What you need to do is set the height of these elements, like so:
html, body {
height: 100%;
}
This will force them to fill the full height of the viewport. The only caveat is that this requires you to define margin-top, margin-bottom, padding-top and padding-bottom on other elements, since margins and paddings will be added on top of the height, which is not what you normally want when defining height (or width, for that matter) in %.
try to use this code:
.bmenu
{
position:fixed;
z-index: 2;
bottom:0;
left:0;
width:100%;
}