I'm trying to split an image into a left and right side. I did this but I want the div to be centered and fill the browser so the images are edge to edge and be responsive. Right now it's all flush to the left.
I put a border so you can see that it's in fact two images put together to make one - 600x900 each.
JSFIDDLE: https://jsfiddle.net/omarel/vnc522vu/3/
HTML
<div id="centercontainer">
<div id="scrollablecontainer">
<img id="leftside" class="halfCompositionLeft" src="https://dl-web.dropbox.com/get/pool_left.jpg?_subject_uid=9047713&w=AAC25lQ4ebCI8ajjRKwfi_TANvxEYQruCRN5PQDEEZ70Uw">
<img id="rightside" class="halfCompositionRight" src="https://dl-web.dropbox.com/get/pool_right.jpg?_subject_uid=9047713&w=AABZnKZrODSr9rGU5kOX7q2EHycNMAqq-mvlUxn0T5tVAg">
</div>
</div>
CSS:
.scrollableSectionContainer section>img {
position:absolute;
}
.centercontainer {
margin: 0 auto;
overflow: hidden;
top: 0%;
right: 0%;
width: 100%;
height: 100%;
opacity: 0;
position: relative;
}
.scrollablecontainer {
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%
}
.halfCompositionLeft {
position:absolute;
top:0px;
left:0px;
width:600px;
height:900px;
}
.halfCompositionRight {
position: absolute;
top: 0px;
left: 600px;
width: 600px;
height: 900px;
border:#FFF solid thin;
}
Try this:
#halfCompositionLeft{
position: absolute; //Absolute Positioning.
top: 0px; //Top of the page.
left: 0px; //Leftmost side.
width: 50%; //Fill half the page.
height: 100%; //Fill page vertically.
}
#halfCompositionRight{
position: absolute; //Absolute Positioning.
top: 0px; //Top of the page.
left: 50%; //Start halfway through the page.
width:50%; //Fill rest of page.
height: 100%; //Fill page vertically.
}
That uses CSS percentages rather than pixel values, which dynamically sets size and position based on page size. To complete this, simply make the full box 100% wide and 100% high, and it will fill the page appropriately.
EDIT: CSS for placing div parallel underneath:
#halfCompositionLeft2{
position: absolute; //Absolute Positioning.
top: 100%; //Similar, but at the bottom of the page, under the top div.
left: 0px; //Leftmost side.
width: 50%; //Fill half the page.
height: 100%; //Fill page vertically.
}
#halfCompositionRight2{
position: absolute; //Absolute Positioning.
top: 100%; //Similar, but at the bottom of the page, under the top div.
left: 50%; //Start halfway through the page.
width:50%; //Fill rest of page.
height: 100%; //Fill page vertically.
}
Related
I'm trying to solve my problem since one week, and I really try everything !
I have a two column layout (left: content / right: description of the content).
I want this two columns full height page and the only way I found is :
body {
margin: 0;
height: 100%;
padding: 0;
}
#rightcol {
position: absolute;
top: 0;
bottom: 0;
right: 0;
overflow-y: scroll;
height: 100%;
text-align: right;
}
The closest way to center a div in my columns was to use (in CSS3) flexbox. But there is conflicts with the absolute position of my columns.
Here's the bootply I made to be more explicit :
http://www.bootply.com/1OovYNhx1E#
In this example, I'd like to center (horizontally and vertically) the <h1>TEXT</h1>
UPDATE
Bootply is a terrible tool. So I used Plunker to replicate your example. This includes Bootstrap and everything you had originally except:
.fluid-container and .row are combined.
#inner is now moved out of #leftcol
#inner has the rulesets previously mentioned.
Both columns changed height: 100vh
Added position: relative to body.
Added width:100% and height:100% to html and body elements.
#inner {
position: absolute;
left: 50%;
top: 50%;
bottom: -50%; /* This was added to offset the top: 50% which was keeping the #inner from scrolling any further to the top. */
transform: translate(-50%, -50%);
z-index: 9999;
}
PLUNKER
OLD
Use the following ruleset on your center element:
.center {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 9999;
}
You weren't clear as to where this centered div should be center in relation to. If you want it to be centered in relation to viewport, (i.e. edge to edge of screen) then the center div shouldn't be inside any column. I f you want it centered within the left column, then it's in the correct place. Regardless, if you use this solution it will center itself perfectly inside of whatever you put it into.
SNIPPET
body {
position: relative;
margin: 0;
height: 100%;
padding: 0;
}
#leftcol {
position: absolute;
top: 0;
bottom: 0;
left: 0;
overflow-y: scroll;
height: 100%;
width: 50%;
text-align: left;
background: brown;
}
#rightcol {
position: absolute;
top: 0;
bottom: 0;
right: 0;
overflow-y: scroll;
height: 100%;
width: 50%;
text-align: right;
background: yellow;
}
.center {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 9999;
outline: 3px solid red;
width: 25%;
height: 25%;
background: rgba(0,0,0,.4);
}
<div id='leftcol'></div>
<div class='center'></div>
<div id='rightcol'></div>
Finally find the answer HERE
With flexbox just add to your inner container :
margin: auto;
It will prevent the top scroll problem !
I have a div that is using padding-bottom:100% to lock the aspect ratio of the div to 1:1 (for responsive purposes):
<div class="image-container">
</div>
css:
.image-container {
width: 100%;
height: 0;
padding-bottom: 100%;
background:yellow;
}
Now, I have an image inside of this container with width:100%. However, the image stays at the top and I can't use vertical-align:middle on the image.
Is there a way I can get this image centered vertically? JSFiddle: http://jsfiddle.net/g819gz2a/
Unfortunately I will need this to work for not only IE 9 but the deadly IE 8
You could do the following using absolute positioning:
JS Fiddle
(in example background of image made green to show its centered)
.container {
width:300px;
}
.image-container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 100%;
background:yellow;
}
img {
width:100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate3d(-50%, -50%, 0px);
}
And for older browsers:
JS Fiddle
img {
background: green;
width:100%;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
So I've seen this How do I center an image if it's wider than its container?
I have something like this
.section-background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
overflow: hidden;
}
.section-background-image {
position: relative;
right:-30%;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.section-background-image img {
position: relative;
right:-30%;
min-width: 100%;
max-width: none;
min-height: 100%;
top: 0;
left: 0;
}
<div class="section-background">
<div class="section-background-image " data-stellar-ratio="0.4">
<img src="my_huge_image.png" alt="" style="opacity: 0.3;">
</div>
</div>
And I want the right portion of the image to appear if it does not fit the container, (by default its the top left hand corner portion).
With this code, it doesn't always work on the first browser request (shows top left corner portion of image), but it shows the right positioning on refreshes.
If there won't be text in the div, you can use direction: rtl;
.section-background-image {
....
direction: rtl;
}
For vertical aligning, use below css
.section-background-image img {
...
top:50%;
transform: translateY(-50%);
}
http://jsfiddle.net/afelixj/q4o08e8u/1/
I am trying to achieve two fixed banners on either side of my sites wrapper. I have used absolute positioning to attach the banner divs to each side of the wrapper and have set a fixed background within each so the banner follows the users down the page.
I seem to be having issues setting the background position of the banners, the background position does not seem to be relative to the parent div. I would like the banner backgrounds to be centered within the divs.
Code and example site
<style>
.page-container {
position: relative;
background: #FFF;
width: 970px;
margin-left:auto;
margin-right: auto;
background-color:#F00;
}
#left-bg {
width: 306px;
height: 100%;
position:absolute;
top: 0px;
left: -306px;
background:url(http://www.superfreeslotgames.com/basecamp/L-Leovegas-banner.gif);
background-position: center center;
background-attachment: fixed;
}
#right-bg {
width: 306px;
height: 100%;
position:absolute;
top: 0px;
right: -306px;
background:url(http://www.superfreeslotgames.com/basecamp/R-Leovegas-banner.gif);
background-position: top center;
background-attachment: fixed;
background-position: center right;
}
</style>
<div class="page-container">
<div id="left-bg"></div>
<div id="right-bg"></div>
</div>
change your CSS like this:
.page-container {
position: relative;
background: #FFF;
width: 970px;
margin-left:auto;
margin-right: auto;
background-color:#F00;
}
#left-bg {
width: 306px;
height: 100%;
position:absolute;
top: 0px;
left: -306px;
background:url(http://www.superfreeslotgames.com/basecamp/L-Leovegas-banner.gif) no-repeat 100% 0;
}
#right-bg {
width: 306px;
height: 100%;
position:absolute;
top: 0px;
right: -305px;
background:url(http://www.superfreeslotgames.com/basecamp/R-Leovegas-banner.gif) no-repeat 100% 0;
}
Also, unless you're doing it by design, you should consider changing right: -305px; (which I also changed from your column because it adds a 1px blank space to the left of the column) to right:0
My objective is to make a website for my portfolio.
I have a div for the menu that wanted to be on top of another div that works as a container for all of my images. The images have to fill 100% height of the browser.
The problem is, that I wanted my website to scroll horizontally and when I start to add content, as soon as the width goes over the 100% of the browser window the new image goes under the first image making it scroll horizontally.
What can I do to correct this?
CSS
body, html {
height: 100%;
}
#main {
width: 100%;
height: 100%;
background-color: #000;
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}
#menu {
width: 200px;
height: 500px;
background-color: #fff;
position: absolute;
top: 10px;
left: 10px;
overflow: scroll;
z-index: 2;
}
#img {
height: 100%;
float: left;
overflow: scroll;
}
Remove the width from your #main tag. As soon as an element hits that 100% it's going to move down to the next line.