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!
Related
I have two divs like:
<header id="header">
<div>Hello Vai</div>
</header>
<div id="banner">
<div><img src="http://www.encodedna.com/images/theme/easy-image-resizer.jpg" /></div>
</div>
CSS:
#header {
width: 100%;
background: #f5f5f5;
position: fixed;
z-index: 10;
}
#banner {
background-color: #CCCCCC;
}
See carefully while I fixed the upper div, image div will get close to upper div.
I don't want to fixed any div height. They will get auto height with their inner divs. And two divs will come one after another.
I didn't get any solution!! But I saw a lot of questions about it.
#header {
width: 100%;
background: #f5f5f5;
z-index: 10;
}
#banner {
background-color: #CCCCCC;
}
In the code that you shared, remove position fixed to achieve the desired behaviour.
Position: fixed
Will overlap with other divs however if u really want to use it, specify it inside a div and then apply top:inherit in order to shift down the lower div.
I am trying to center some text within a banner (classic question I know). This banner is split into 12 columns, and there is a cross icon for closing the window in the left-most column. The text is centering in the available space between the cross icon and the end of the banner, rather than centering within the whole banner width. From the way the code is written I cannot see why it would be doing this. Here's the HTML:
<div class='col-xs-12 banner'>
<a class="navbar-brand cross-link" href="" ng-click="close()">
<img class="cross" src="/components/cross.png" alt="close">
</a>
<h1>{{title}}</h1>
</div>
with CSS:
.banner {
height: 70px;
background-color: red;
h1 {
color: white;
text-align: center;
}
.navbar-brand {
&.cross-link {
padding: 0px;
img.cross {
margin: auto;
width: 70px;
height: 70px;
padding: 29px 28px 27px 28px;
}
}
}
When I inspect this on Chrome, the h1 is quite happily sitting within a full-width container as expected, but the image appears to be shifting it across so that it doesn't center properly. Can you see how to resolve this?
Thanks
You could set the .cross-link to absolute position. Remember to set the container position property to a value different from "static":
.container{ position: relative; }
.cross-link{ position: absolute; left: xxxx; top: xxxx; }
What you are missing is a closing } at the end of your .banner block OR at the end of the css you shared.
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>
I'm developing my template with bootstrap which has a fullscreen slider that gets specifics featured images, but when I put position: relative and position: absolute in the containers, the one with position absolute don't stay on center anymore.
Here is my example:
http://jsfiddle.net/vqcf1L5d/
<div class="container-full header">
<div class="container">
<div class="row">
<div class="col-md-12">
header
</div>
</div>
</div>
I need that the header overlays the background and that the scrolling doesn't show.
position: absolute does exactly what it says: it positions itself absolutely to it's parent display context. This means that your .header is not going to automatically center, because it's going to see the top, left corner as it's 0, 0 and display down and away from that point. It's also "behind" your .bg element, so you're not even seeing it.
You could instead manipulate it's inner .container, though (and fix the z-index):
.header {
position: absolute;
width: 100%;
z-index: 100;
}
.header .container {
width: 150px;
margin: 0 auto;
background: #fe634e;
opacity: 0.8;
text-align: center;
}
http://jsfiddle.net/userdude/vqcf1L5d/4/
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);
}