I'm having a little trouble getting this image to be displayed correctly.
I have my site setup with a width of 940px and I want to keep this width but have a div within this that is wider and overflows so that you can still see this on larger displays.
<div id="cinema-wrapper">
<div id="cinema-displays"></div>
</div>
#cinema-wrapper {
width:940px;
height:764px;
}
#cinema-displays {
background-image: url(../mackbyte_files/img/cinema-bg.png);
height: 764px;
width: 3109px;
background-repeat: no-repeat;
position: absolute;
left:50%;
margin-left:-1554.5px;
overflow:visible !important;
}
This works (kinda) but I'm left with two problems.
It doesn't work in safari (chrome/firefox are fine)
It leaves a scroll option only to the right. (e.g. I can scroll further to the right to see the overflowed image).
For 2, I only want the user to see the amount of image depending on their screen resolution.
PS. I know 3109px is huge for web and screen res but im working on a fix before I continue with the image to make it smaller; however, when I do I will still have this issue.
what controls if the inner div is visible or not outside the cinema-wrapper is the overflow of the parent, that you are not setting. so, you should do
#cinema-wrapper {
width:940px;
height:764px;
overflow:visible;
}
I've also experienced that kind of problem so here's my approach.
for the HTML:
<div id="cinema-wrapper">
<div id="cinema-subwrapper">
<div id="cinema-displays"></div>
</div>
</div>
for the CSS:
#cinema-wrapper {
width: 940px;
height: 764px;
overflow: visible;
position: relative;
}
#cinema-subwrapper {
display: inline-block;
position: relative;
right: -50%;
}
#cinema-displays {
background: url(../mackbyte_files/img/cinema-bg.png) center top no-repeat;
height: 764px;
width: 3109px;
position: absolute;
left: -50%;
}
Hope this helps. :)
Related
I would just like to know how to resize an image width to fit the browser width, The image is basically my header image that i want to fit the screen width.
I would thereafter need to place a div on the image. I have the following at the moment but nothing seems to work.
#container {
position: relative;
}
#divWithin {
position: relative;
top: 20%;
left: 20%;
padding: 5px;
background-color: white;
}
#imgWithin{
width: 100vw;
height: 100vh;
left: 0;
}
<div id="container">
<img id="imgWithin" src="~/images/image(2).png" style="height:325px; margin-top: 75px;" />
<div id="divWithin">Testing</div>
</div>
Any help or ideas would be gladly appreciated
What I am trying to achieve is displayed in an image below:
With 1 being : The image that I want displayed across the screen width (fit screen width)
and with 2 being : The div that I would want to place upon the image
To make a image responsive You need to use a class like this:
.responsive {
width: 100%;
height: auto;
}
If you need more details about responsive images this link should help https://www.w3schools.com/howto/howto_css_image_responsive.asp
Try changing your css to this:
html, body {
width: 100%;
}
#container {
width: 100%;
position: relative;
}
#imgWithin {
width: 100%;
}
#divWithin {
position: absolute;
top: 20%;
left: 20%;
padding: 5px;
background-color: white;
}
This will make the image the full width of the browser window with the text overlaid on top.
You are going to warp the image with a fixed height in your html though. If you provide a link to an image mocking up what you are trying to achieve I might be able to help you further
Why don't you use background: url()?
so new html now is:
<div id="container">
<div id="divWithin">Testing</div>
</div>
and css:
#container {
background: url("Your image url") no-repeat center center;
background-size: cover;
}
learn more about background and background-size
what ever media query you use put every where
CSS:-
.container{
padding: unset;
width:auto;
}
i am expecting inside container id is your image this works perfectly fine in every screen if you face any problem ping me
So, I know this is something that has troubled others before me, but I simply cannot make it work. I am currently working on a 1000px width centered background that should go on for the entirety of the page. With height:100%; I can get it to fill the entire screen, but if I have Divs within that requires scrolling, the background is missing at the bottom.
I have searched the internet to solve this problem and have found a bunch of solutions, though none seem to work for me. Among them:
Change body position to relative.
Change body and or HTML to 100% height and 100% min-height (and every combination between).
Change the position of my Divs to all the available positions (absolute, fixed, relative etc.)
Try to use table at the Body and then table-rows for my divs.
All the various overflow opportunities (I am not interested in scrolling within my Divs)
And many more.
Here is my code.
HTML
<body>
<div class="headerMenu">
<div id="wrapper">
something
</div>
</div>
<div class="signMenu">
<div class="div_one">
something
</div>
<div class="div_two">
something
</div>
</div>
</body>
CSS
html, body {
margin: 0;
padding: 0;
width: 100%;
height:100%; }
.signMenu {
padding-left: auto;
padding-right: auto;
width: 1000px;
margin-left: auto;
margin-right: auto;
position: relative;
background-color: white;
height:100%; }
.div_one {
background-color: rgb(250, 250, 250);
height: 1250px;
width: 400px;
position: absolute;
top:105px;
left: 0px;
margin-left: 30px;
}
.div_two {
background-color: rgb(250, 250, 250);
height: 1200px;
width: 400px;
position: absolute;
top:120px;
right: 0px;
margin-right: 30px;
}
Forget the headerMenu and wrapper for now. The point is, that if/when div one and two exeeds the height of the screen then the scroll bar appears, and when I scroll down the white background from the signMenu goes no further. I want that background to fill the enitire page (with scrolling down no matter how long), and not just the specific window size, which it does with height: 100%;.
I hope that makes sense. I am kind of new to this. Thanks in advance!
I have found this vertical centring method which seems pretty common..
#container {
width: 960px;
height: 740px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -480px;
margin-top: -370px;
}
What I'm trying to center here is the entire site, and this code goes perfectly as expected when the screen preview is larger than the div height (larger than 740px). However, Once the browser window is minimized less than div's vertical size (740px) parts of the header disappear above the top of the page.
I can sort of understand why this is happening seeing that 50% becomes less than half the div's size which will be equalized with margin-top.
What I'm looking for is a fix for this issue? Or even a completely different method, I just need to center the site both vertically and horizontally.
try this:
#container {
height: 740px;
width: 960px;
position: absolute;
margin: auto;
top: 0; right: 0; bottom: 0; left: 0;
}
By the way, Smashing Magazine recently published a nice article about this.
You need to add a media query:
#media screen and (min-height:740px) {
#container {
top:0;
margin-top:0;
}
}
This will only apply the formatting where the screen is at least 740px tall. If you want to learn more about media queries, check http://www.w3.org/TR/css3-mediaqueries/
Absolute Centering like Lino Rosa mentioned is the best approach here for easy horizontal and vertical centering while allowing you to add some responsive touches, like fixing your height issue.
Ideally, you should be using percentages for the width and height declarations so that your content will vary with the viewport. Of course, sometimes you just need pixels :-)
Here's what I've done:
.Absolute-Center {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
margin: auto;
}
#container {
width: 960px;
max-width: 90%;
height: 740px;
max-height: 90%;
overflow: auto;
}
By setting a max-height and max-width, the box will never be more than 90% of the container (in this case, the browser viewport) even if it's less than 960px wide or 740px tall, so even small screens see a nice centered box. overflow: auto ensures that if the content is longer than the box, the user can scroll in the box to see the rest.
View the demo
If you must have the box exactly 960px by 740px no matter the screen size (forcing the user to scroll around to see all of the content on a small window), then only apply the Absolute Centering styles to #container using a media query, like so:
#container {
width: 960px;
height: 740px;
overflow: auto;
margin: auto;
}
#media screen and (min-height:740px) and (min-width: 960px) {
#container {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
}
}
View the demo
I encountered the same issue. As the height of my element is dynamically changed, I can't give it a fixed height.
Here is a demo below, hope it helps.
.wrapper {
display: table;
height: 100vh;
width: 100%;
}
#container {
display: table-cell;
vertical-align: middle;
background-color: lightblue;
}
.content {
width: 30%;
height: 30%;
background-color: red;
}
<html>
</html>
<body>
<div class="wrapper">
<div id="container">
<div class="content">
</div>
</div>
</div>
</body>
I have the following html:
<div class="fix-to-top">
<div class="background-image"></div>
</div>
I want to be able to fix the position of the image to the top of the page -- so that it is always at the top of the page no matter how far down the user scrolls. In addition, I want the image to always stay in the center of the page, so if a user re-sizes his browser, the image stays in the center. Here is what I tried, but wasn't getting the result:
.fix-to-top {
position: fixed;
top: 0px;
width: 2000px;
}
.fix-to-top .background-image {
margin: 0 auto;
}
However, the side margins aren't doing 'auto'. How would I correctly do this?
img {
position: fixed;
right: 50%;
width: 100px;
height: 100px;
margin-top: -50px;
margin-right: -50px;
background: orange;
top: 50%;
}
http://jsfiddle.net/jXdxr/1/
Check this fiddle
No need of using two div's
You can use background-attachment and background-postion properties to achieve it
I'm working with a piece of HTML similar to this:
<div id='headerBar'>
<div id='headerBarContent'>
<div id='leftContentSubdiv'></div>
<div id='rightContentSubdiv'></div>
</div>
</div>
With CSS like this:
#headerBar
{
position: fixed;
left: 0px;
right: 0px;
min-width: 1024px;
width: 100%;
height: 34px;
z-index: 10000;
}
#headerBarContent
{
display: inline-block;
position: absolute;
left: 50%;
margin-left: -512px;
width: 1024px;
}
#leftContentSubdiv, #rightContentSubdiv
{
position: relative;
width: 512px;
height: 34px;
}
What i'm trying to create is a header bar that scrolls vertically along with the page, and that scrolls horizontally when the window is smaller than the headerBarContent's width, without the use of JavaScript.
Facebook implements it exactly as I specified, without the use of JavaScript.
Twitter implements it with JavaScript
The Onion illustrates where I'm stuck at now. The page is unable to
scroll the header bar horizontally with the rest of the page once the
window size is smaller than the header's centered content
I can't figure out what exactly Facebook is doing in the markup have this functionality. Can anyone help?
If I correctly understand your problem, if the screen is < 1024px (headerBarContent) you want the header position to be relative.. right? (like Facebook)..
You could achieve this without JS by media queries i.e. :
#media screen and (max-width: 1024px){
#headerBar{
position:relative;
}
}
demo http://jsfiddle.net/BPcfB/