CSS Bottom Positioning - html

So, I have this:
.cmon
{
background-repeat: repeat-x;
background-image: url("line2.png");
position:absolute;
bottom:0px;
}
What it should do, is put the image (line in this case) on the bottom of the page, from what I understand, and repeat it. It does put it on the bottom, but doesn't repeat, anybody knows what's my problem?
This is how it looks like when the code is on:
http://goolag.pw/temptest.html
Also, in the menu (top right corner) the image doesn't even show up, nor does is it on the bottom.
I will be more than happy if anybody knows whats the problem.
(sorry if links are not allowed here, there are no commercials on the web, it's really just to show what's the problem)

To position background images you should use the background-position property:
.cmon {
background-repeat: repeat-x;
background-image: url("line2.png");
background-position: bottom;
}
The background-position CSS property sets the initial position, relative to the background position layer defined by background-origin for each defined background image.
You'll need to ensure your element has some height and width, however, as background images are not content and do not affect the size of the element.

So first, your problem is not only about CSS but HTML too. You have to attach your attribute .cmon on another tag like <span>, <p>or even <div>.
<div class="cmon"></div>
Then for your CSS :
.cmon {
background-repeat: repeat-x;
background-image: url("line2.png");
position: absolute;
bottom: 0px;
left: 0px; right: 0px; // For having a full width bar
z-index: 999999; // Will be always visible, even when the menu is showed up
height: 4px; // attribute the height of your image
}
Hope this help you.
Ps : Don't forget to use HTML5 !

Related

How does the stacking layer order of this code that uses the z-index

I am working on this project and have a question about this code stacking order. It has a z-index -1, background color, a background image of linear gradient and a background image of an image. I can't understand the layering involved in it.
What is the order of the positioning? Which ones are closer to the viewer and which ones are further away?
The code looks like this:
body::before {
content:"";
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
background: var(--darkblue);
background-image: linear-gradient(
to right,
rgba(58,58,158,0.8),
rgba(136,136,206, 0.7)
),
url(images/image.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
Since you mentioned z-index:-1, background and background-image all are on'-1' layer.
A better way to add color to background image is using 'linear-gradient' with 'background-image' property but using background with background-image like so,
background: var(--darkblue);
background-image: linear-gradient(
to right,
rgba(58,58,158,0.8),
rgba(136,136,206, 0.7)
),
url(images/image.jpg);
is useless.
And if you still want to use both, you can put them in diff 'divs'.
For the layering order for a HTML page, it will always have the following rules.
An element will always be in front of it's parent. This does not say anything about other elements inside it.
The CSS engine will always render higher z-indexes on front of lower z-indexes. If the z-index is not defined, it will act as being 0.
The elements will render static elements first, then relative, then absolute, then fixed.
If none of these rules are different, the elements will render on the order as written (first one on background, latest one on foreground).
For layering background images, the first one will render on the foreground and the latest one on the background. The background color will always render before the background image.

Background-image + Fixed + NOT Transparent

This is my css:
body {
background-image: url('mybackground.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100%;
}
But when I scroll down, the background image is transparent & this is not what I want.(my background image is like a header image, just like this website but the header if fixed).
What should I do?
Any suggestions?
This time it is better explained:
You need header element, with position fixed:
<header style="position: fixed;"> ... </header>
Try the JSFiddle link here
.
Best of luck.
(Mark this as answer if this serves your need)
What I would suggest is using a fixed div at the top of the page that the content can scroll behind. You can remove the background code. this way you have more options and can still add background texture if you like. Otherwise you are applying position FIXED to the whole body which you dont want to do you want to apply fixed to 1 image element. Please Check this JSFiddle
I would also read this article to read more on the layout position properties.
.header {
position: fixed;
top: 0px;
}
<div class="header"><img src="mybackground.jpg"></div>

background image, but with opacity css

I have an issue with my background not covering the whole site from top to bottom. I know what causes the problem, but as to fixing it I am unsure. My CSS looks like this:
#background-img{
display: block;
position: absolute;
background-image: url(http://images2.alphacoders.com/778/77840.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
width: 61.8%;
margin-left: 19.1%;
height: 100%;
opacity : .3;
}
The problem seems to happen where the at the point where I add height. But I am not allowed not to have it there as there wont be anything to have a background for. The problem initially is that I need opacity on the image, so I can't just make it cover the wrapper either, as that will give the whole site opacity, not just the background.
If anyone ever should read this post. I found a solution. I just moved the whole background-image div to the top of the very wrapper div, and made the position fixed, instead.

CSS Background-position relative to document not element?

I'm wondering if this is possible, the ability to set the background position of an image to the top left of the html document, not the top left of the element it's the background of.
Psuedo-code
body {
background-image: url(someurlhere);
background-position: top left;
}
element {
background-image: url(sameurlhere);
background-position: top left /*Relative to body not element*/;
}
If I need to provide anything else to this question let me know and I'll amend it, but I'm sure it's pretty straight forward.
Edit: I can't use absolute positioning, I'm loading dynamic content and I want a tiled image to fit the background of several elements to make the illusion of holes in the page.
Edit 2: Here are some pictures to better explain the problem.
Picture 1: Notice the repeated pattern in the header elements. http://i.imgur.com/3lWguRE.png
Picture 2:This variation is what I aim to achieve. http://i.imgur.com/WtOeCQ2.png
The first question would be why you are not just setting the background image on the body element.
But if that's not appropriate, you have the option to set a background image on an element to fixed, in which case it will be fixed to the top left of the browser window and won't scroll.
element {background: url(image.fig) repeat fixed;}
However, the background will only show on the element it's attached to, even though it starts at the top left corner of the screen. (This is handy for parallax effects.)
EDIT: As a side note, if you are using the longhand background properties, fixed is set with
background-attachment: fixed;
All you have to do is wrap your element in a div absolute, and position it as you wish.
Can you provide some more information on the context of the element? Does it have any positioning set? Where is it in the document? It's a little unclear to me what exactly you are trying to accomplish.
Would putting the background on the body work?
This would set the background at the top left, but I doubt this is actually what you are trying to accomplish:
<div class="test">
</div>
.test:before {
content: "";
position: absolute;
top: 0;
left: 0;
background: url(http://i1112.photobucket.com/albums/k497/animalsbeingdicks/abd-318.gif);
width: 352px;
height: 263px;
}
http://jsbin.com/imurah/1/

CSS - Can an image overlap a page border without affecting page width?

I have the following element in my initial page concept:
http://tinyurl.com/bcmcxp9
The ribbon is a PNG image. What I'd like to be able to do is position this image exactly over the border of a box-shadowed div (representing the page content), without affecting the page width.
I've tried a couple of techniques.
By using position:absolute, I've been able to achieve the visual effect I was looking for, but it brings up the dreaded horizontal scrollbars! I want the edge of the div (not the edge of the image) to represent the edge of the page.
#banner-ribbon {
background-image: url(ribbon-right.png);
background-repeat: no-repeat;
position: absolute:
width: 419px;
height: 114px;
left: 700px;
top: 400px;
}
By using a div that sits between the content wrapper and the background, I've been able to position the image in the right place without affecting the horizontal scrollbars (sort of, I might need a little javascript to absolute-position it relative to the center), but I can't raise the image's z-index above its child divs!
#banner-ribbon-wrapper {
background-image: url(ribbon-right.png);
background-repeat: no-repeat;
background-position: 90% 400px;
z-index: 70; /* does nothing */
}
Any ideas?
It sounds like the image is extending the boundaries of the page, causing the horizontal scroll bars. One way to fix this may be to set a width for your page and then hide anything that goes outside of it. Something like this may work for you:
body {
width: 100%;
overflow-x: hidden;
}
Example jsFiddle
Give your content div
position: relative
and to your ribbon
position: absolute
right:0
Make sure your image don't extend boundaries uncontrollably.
Working sample on JsFiddle:
http://jsfiddle.net/BrvJk/