Image background on Both sides (left and right)? - html

I have a hard time to get background on both side of my page:
Style
.left {
background: url(wax.png);
width: 15%;
position: absolute;
left: 0px;
height: 100%;
}
.right {
background: url(wax.png);
width: 15%;
position: absolute;
right: 0px;
height: 100%;
}
.middle{
margin: 0 auto;
}
HTML
<div class="left">
</div>
<div class="middle">
</div>
<div class="right">
</div>
Result
Its close to what I am trying to achieve but the right image is misplaced.
Also the backgrund is not repeated vertically

background: url(wax.png) repeat-y 0 0;
To get the vert repeat.
Do you have something positioned relative? That input text field is probably pushing down the right div unless you have something else positioned relative?
If you're going to use position:absolute, wrap it all and use position:relative on that wrapping div.
Otherwise, you could use the body tag or even the html tag but it's probably better to use a wrapping container.

im not really sure what you are trying to do it looks align to me but for repeating image is this background: url(wax.png); background-repeat: no-repeat

Its close to what I am trying to achieve but the right image is
misplaced.
Add top:0 to the .right class
Also the backgrund is not repeated vertically
As others have mentioned add repeat-y in the background property value
background: url(wax.png) repeat-y

Maybe you just want to place your middle inside one div with the background repeated in both direction and middle having background white
html:
<div id="background">
<div id="content">
this was middle
</div>
</div>
css:
#content{
margin: 15%;
background: white;
}
#background {
background: url(wax.png);
}

Related

How to avoid Div changing positions when another element is added

I'm having a problem in which whenever I add another element inside, like for example, a P element, my div moves out of position vertically, it's supposed to stick with the top header at all times, but whenever I add another element inside it, it slightly shifts out of position
The background is supposed to be glued to the header on top like this
How it should be
How it looks
Is there any way to make so the mainbody div ALWAYS sticks to the main header div?
.menucontainer {
width: 1000px;
height: 150px;
margin: auto;
outline: solid black 1px;
background-image: url("images/backgrounds/mainheaderbanner.png");
background-position: -75% 40%;
}
.mainbody {
background-color: rgba(0, 0, 0, 0.8);
position: relative;
top: -18px;
margin: auto;
width: 1002px;
height: 1345px;
}
<div class="menucontainer">
<a href="index.html">
<div class="logocontainer">
<img src="images/logo.png" class="logo"></a></div>
</div>
<div class="mainbody">
</div>
In some Editors each time, after using automatic code indentation, an "Enter" will appear between two elements and create white space again!
To eliminate the space between two divs try to write them in the same line :
in your case :
<div class="menucontainer"><div class="logocontainer"><img src="images/logo.png" class="logo"></div></div><div class="mainbody"></div>
test it and tell me if it works!

adding "position: fixed;" prevents all scrolling, even on unattached elements

So, should be fairly straightfoward but i don't know why this isn't working (maybe i'm tired).
I'm trying to add position fixed to my webpage so i get a nice background that doesn't move, and then over the top, a text space where you can scroll (so the text moves, but the image stays the same). But when i add "position: fixed;" it just stops scrolling all together and as far as i'm aware, it should only stop the scrolling of the part it's attached to.
So here's my html
<div id="Home-background">
<div id="Home">
<a name="Home"></a>
<div class="page-padding"></div>
</div>
</div>
and my css
#Home-background {
**position: fixed;**
z-index: 1;
top: 20px;
width: 100%;
background: url('Pictures/lords-fallen-art-wallpapers-1080p.jpg');
background-size: 100%, 100%;
padding-top: 0px;
min-height: 700px;
}
#Home {
position: relative;
z-index: 10;
top: 400px;
width:70%;
min-height: 3000px;
background:#ffffff;
padding-top: 50px;
padding-bottom: 100px;
}
The marked position is what is causing the issue, but it should have no affect on the #Home set, right?
EDIT: I thought i should note, i am using other fixed elements ( i have a top bar and a menu bar at the side currently, both are fixed and both scroll till i add the fixed element as mentioned above. But having multiple fixed elements shouldn't stop other fixed elements from working either, right? (yes i've z-indexed them respectively)
#Home-background is wrapping the #Home div and will prevent scrolling if it is position: fixed
To place a fixed background, put a background on the body.
In your example it should look something like this:
no-repeat prevents the background image from repeating
background-position: fixed prevents the image from scrolling
background-size: 100% 100% stretches the image to fit the body element
Note: The image in this example does not make it obvious that it is fixed, but it is :)
body {
margin: 0;
background: url('http://www.placehold.it/1000') no-repeat;
background-size: 100% 100%;
background-position: fixed;
}
#Home {
position: relative;
width: 70%;
min-height: 3000px;
background: #ffffff;
padding-top: 50px;
padding-bottom: 100px;
}
<div id="Home">
<a name="Home"></a>
</div>
I managed to fix it, the problem was "Home" being inside "Home-Background" although i still don't understand why that would break it.
The following solves my problem
<div id="Home-background"></div>
<div id="Home">
<a name="Home"></a>
<div class="page-padding"></div>
</div>

Center an element in a fixed position on a resizable background

I'm trying to center an element of a precise size on a background that is built specifically for it, in order to make it appear seamless.
In the following code, #window represents the browser's window size in pixels (change it to anything). #background obviously refers to the background image I'll be using, and #positionMe is the object I want to fit on the background. I want the background to always be centered in the browser even if the window is resized, and I want the kitten to always be centered in the black box on the background.
As you can see below, the problem is that the background isn't centered on the viewport to begin with; it's centered based on total width of the browser. And when you resize the screen, it doesn't adjust accordingly.
HTML:
<div id="window">
<div id="background">
<img id="positionMe" src="http://cs421018.vk.me/v421018778/74bc/NearuIJQIck.jpg" />
</div>
</div>
CSS:
#window {
background-color: red;
width: 1280px;
height: 720px;
}
#background {
background: url('http://i.imgur.com/xzDclz5.jpg') no-repeat;
width: 500px;
height: 500px;
margin: 0 auto;
}
#positionMe {
position: relative;
top: 174px;
left: 154px;
}
This Fiddle demonstrates my issue.
Using a combination of display:table-cell and vertical-align:center will center your image vertically. In addition, you can simply use text-align:center to center your image horizontally.
http://jsfiddle.net/reinmcha/XtQ37/10/
Might need to do a little adjusting to keep the background div centered. So, we add another div and set to display:table. The "table cell" will fill the whole thing. Now we center the table with margin: 0 auto.
Final Product:
http://jsfiddle.net/reinmcha/XtQ37/20/
Might need to do some updating to get the image to center perfectly with the border (since it has width...)
Here's my go at it.
I hope you are aware there are tons of articles on this topic. Search around. You'll find your answer :)
You basically have two options, one would be using a div to display an image and making the image a centered background like so:
<div id="window">
<div id="background">
<div id="centerMe"></div>
</div>
</div>
with css:
#centerMe {
width: 100%;
height: 100%;
background: url('http://cs421018.vk.me/v421018778/74bc/NearuIJQIck.jpg') no-repeat center;
}
or for a pure css solution:
#background {
background: url('http://i.imgur.com/xzDclz5.jpg') no-repeat;
width: 500px;
height: 500px;
margin: 0 auto;
text-align: center;
}
#background:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
#centerMe {
vertical-align: middle;
}

Horizontally center an element and put another element to the right of it

As the title suggests, I am trying to horizontally center an element and put another element to the right of it WITHOUT centering both elements. I only want ONE of the two elements to be centered, while the other one is to the right of it (and on the same line in this case).
The following is the closest that I can get, but BOTH elements are centered as opposed to just the element containing 'CENTER'. I want 'CENTER' to be centered and 'right' to be to the right of it:
<div style="text-align:center;">
<div style="display:inline">CENTER</div>
<div style="display:inline">right</div>
</div>
I have also tried:
<div style="text-align:center;">
<div style="display:inline">CENTER</div>
</div>
<div style="display:inline">right</div>
which causes the element with 'right' to go to the next line. Adding display:inline to my div with text-align:center just takes away any centering.
Are there any ways to make this happen? There's plenty of information about centering out there, but nothing seems to answer what I am trying to do.
Try this - http://jsfiddle.net/dGSDF/2/
#center {
position: relative;
height: 100px;
width: 60%;
margin: auto;
background: beige;
}
#right {
position: absolute;
right: -20%;
/* the div's width */
top: 0;
width: 20%;
background: orange;
height: 100px;
}
<div id="center">
CENTER
<div id="right">right</div>
</div>

HTML: .jpg as a footer with repeat and a logo on it?

I have .jpg as footer that is 8x76 its just a simple line with height 76px and gradient blue color. I would like to put a logo on it. What's the best way to do that?
This is my CSS:
#light_footer_wrapper {
height: 110px;
background: url(../images/light_footer_repeat.jpg) repeat-x top left;
position: relative;
}
#light_footer_logo {
position: absolute;
top: 8px;
left: 600px;
height: 110px;
}
#light_footer {
width: 960px;
margin: 0 auto;
padding-top: 10px;
}
HTML:
<div id="light_footer_wrapper">
<div id="light_footer_logo"><img src="../a/images/logo.gif" /></div>
<div id="light_footer"></div>
I cant locate my logo now on my footer .jpg. but when I zoom in and out the logo moves around :S I want it locked
You could also set a background-image of the logo for #light_footer if you didn't want an extra div, but an extra div might give you more control.
#light_footer_wrapper is the full width of the browser, so when you resize, your logo will move with it.
You should put the image inside of #light_footer, make #light_footer position:relative, and then tweak your left and top values on #light_footer_logo.