Stop background from repeating after a specific point - html

Is there a way to stop a background image from repeating after a specific(though dynamic) point?
Currently I have the following html
<ul>
<li>variable</li>
<li>amount</li>
<li>of</li>
<li>items</li>
</ul>
and css:
ul {
background-image: url('./imgs/gridlines.png');
background-repeat: y-repeat;
}
Now, the above repeats the image for the entire length of the ul element. My issue is I need the repeating to stop 8px from the bottom of the ul.
I've tried using background-position but this just shifts the background, while still repeating it to the end of the ul element.
I've also tried using background-size: 1 calc(100% - 8px); but this fails for chrome.
fiddle

You can do this in CSS...sort of. You cannot tell background-repeat to repeat a specified number of times; it doesn't work that way. So my idea is to stick an 8px white block at the bottom of the list, which should accomplish something very close to the desired effect:
ul {
background-image: url('http://i.imgur.com/B5k8FTP.png');
background-repeat: y-repeat;
padding-left:0;
color:black;
width:200px;
position:relative;
}
li:last-child{
position:relative;
z-index:10;
}
ul::after{
display:block;
background-color:white;
position:absolute;
bottom:0px;
height:8px;
width:100%;
content:"";
z-index:1;
}
<ul>
<li>variable</li>
<li>amount</li>
<li>of</li>
<li>items</li>
</ul>
The ul style sets a width for the sake of the demo. padding-left:0 removes the margin from the left side of the <ul>, also optional. The position is set to be relative, because after content will be positioned absolutely, relative to the <ul>/
The ul::after style inserts the white block after the list. position:absolute and bottom:0px place it at the bottom of the list, relative to the <ul>. The z-index is set to ensure it sits behind the bottom <li>
The li:last-child makes sure that it sits on top of the ul::after content.

You can wrap the content you want inside a frame that is set to inherit the size from parent - the 8 px you want.
If I am misunderstanding something a jsfiddle would be nice.
EDIT:
Like this?
.wrapper{
position: relative;
left: 20px;
height: 46px;
background-image: url('http://i.imgur.com/qIaw9Lc.png');
background-repeat: repeat-y;
}

Related

getting something outside a div

Well I'm not sure how to ask this with words so I will post an image:
So in the image, there is a main div, lets call it "red".
Inside "red" there is another div called: "green"
Inside "green" there is an ul, with some li elements, they are supposed to have an underline, but that underline must get out of the div, so the problem I have, is getting that line outside of "green", when in the code, it is inside.
I'm guessing there might be some kind of overflow setting or some technique to achieve this, maybe its much easier than I think, but I just can't figure it out.
The sum it up, I need to get something from within a div, and get it to show outside of it as well.
I tried to google it as much as I could but I couldn't find anything that worked for me, maybe because I'm not even sure how to ask.
That depends on situation. If it is fixed size elements and they are always same size no matter what you could do it:
Position red div as relative, then green div as absolute and ul again as absolute. That will allow you move elements. Relatively to red div.
If it is stretching elements depending on size of window, it is harder and margin-left, margin-top and float:left would do the trick, but you should be very careful with it as it is hard to make cross-browser.
You cannot solve this with overflow. What you need to do is to let the ul inside green be set to position: absolute and the red box to position: relative.
I made a jsfiddle for it (my first).
see the demo as per your requirement :-
DEMO
HTML
<div class="red">
<div class="green">
<ul>
<li>loreum</li>
<li>loreum</li>
<li>loreum</li>
<li>loreum</li>
</ul>
</div>
</div>
CSS
.red {
width:300px;
height:300px;
background:red;
}
.green {
float: right;
height: 200px;
margin: 30px 30px 0;
width: 200px;
background:green;
}
.green ul {
left: 8px;
margin: 0;
padding: 0;
position: absolute;
width: 200px;
}
.green ul li {
list-style-type:none;
display:block;
border-bottom:1px solid white;
text-align:right;
}
Use "overflow : hidden" (css) for green div

div under another div

with css, can I put a div under another div without using absolute positioning?
I have these two divs, and I would like the solid white one to appear directly under the one with the yellow opacity (but not direct in the corner, at the corner of the outline).
How can this be accomplished. I've been experimenting with z-index and relative positioning, but to no avail.
Thanks
http://jsfiddle.net/loren_hibbard/WtGsv/
Without using positioning, I added a style to your content div using negative margins:
.content {
margin-top:-100px;
}
Working demo here: http://jsfiddle.net/WtGsv/3/
I suggest adding an id to your .fixed_width div which houses the .content div though, and using the id to give the negative margin to, that way the parent div has the negative margin, not the child div.
However if you want to use absolute positioning, I have updated your jsfiddle here:
http://jsfiddle.net/WtGsv/12/
Basically, you add a parent div with position:relative; around your other two divs that you want to use position:absolute;
I guess you should rewrite the markup, it is very simple, I don't know whether you are aware of this or not but you can pick up the div and place it in a relative positioned container, than you wont need negative margins
Demo
HTML
<div class="wrap">
Add a line item
<div class="inner_wrap"><textarea></textarea></div>
</div>
CSS
body {
background-color: #aaaaaa;
}
.wrap {
border: 4px dashed #ff0000;
height: 100px;
text-align: center;
line-height: 100px;
font-size: 20px;
font-family: Arial;
position: relative;
}
.inner_wrap {
position: absolute;
width: 100%;
height: 100%;
background-color: #919191;
top: 0;
}
Yuu can use position: relative; top -100px, http://jsfiddle.net/WtGsv/1/
or you can use negative margins margin-top: -100px http://jsfiddle.net/WtGsv/5/
With both solutions, the div at the bottom still takes space where it would be originally
Note that adding a div dynamically doesn't preclude you from making it absolutely positioned, you just have to make the parent be positioned relative, and the dynamic absolutely positioned div will be inserted right where you want it http://jsfiddle.net/WtGsv/10/
You can place the div you want to be on top inside the div you want underneath, and position the one on top absolutely inside the parent.
Example HTML:
<div id="bottom">
lorem ipsum
<div id="top">
hello world
</div>
</div>
CSS:
#bottom {
background:red; /* to see dimensions */
position:relative;
}
#top {
background:rgba(0, 255, 0, 0.3); /* only to prove that it's on top */
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
Here is a JSfiddle.
If you put them both inside a parent div, and set that to have a width equal on the width of the yellow box, then by default the white one would be placed directly below.
I did this way
.mainUnderline{
height:8px;
background-color:yellow;
margin-top:-15px;
}
.header{
width:400px;
text-align:center;
font-weight:900;
font-size:30px;
color:black;
padding-bottom: 2%;
margin-left: auto;
margin-right: auto;
}
<div class="header">
“See line under me”
<div class="mainUnderline"></div>
</div>

Background image left margin problem

I have a series of background images that need to fade in and out and appear in the background. This background image appears behind my content, is centered, and is wider than my content. I do not want this image to affect the width of my page so there is no width set on the container div, ul, or li elements. I need to determine why there is a white left margin showing up over my background image. This margin shows up no matter how wide the browser window is as shown by my "test" li. The problem appears across browsers (tested: FF, Safari, Chrome, IE8) and has nothing to do with the javascript used for the rotation and fade.
I'm sure this is something dead simple that I'm overlooking. Many MANY thanks to anyone who can point me in the right direction here.
Link to an screenshot showing the problem.
Live example of the problem.
The HTML for this is:
<div id="hdrHomeWrap">
<ul id="hdrHome">
<li class="hdrHome1"></li>
<li class="hdrHome2"></li>
<li class="test"></li>
</ul>
CSS:
#hdrHomeWrap {
margin: 0 auto;
position:relative;
top:-20px;
}
#hdrHome #hdrHome li {
margin:0;padding:0;
position:relative;
list-style:none;
}
#hdrHome li {
display: block;
height: 400px;
display:none; /* hide the items at first only */
list-style:none;
}
#hdrHome li.hdrHome1 {
background: url('images/hdr-home1.jpg') no-repeat top center;
}
#hdrHome li.hdrHome2 {
background: url('images/hdr-home2.jpg') no-repeat top center;
}
#hdrHome li.hdrHome3 {
background: url('images/hdr-home3.jpg') no-repeat top center;
}
#hdrHome li.test {
background: #F00;
}
Have you tried giving the ul (#hdrHome) a margin & padding of 0?
In your CSS, you have
#hdrHome #hdrHome li
I'm guessing that's a mistake. You are either missing a "Comma" in between.
So it should be like #hdrHome, #hdrHome li instead of the other

Why is there a gap in my layout?

Its been a few hours now and I cannot figure out why there is a gap in my layout.
picture:
http://dl.dropbox.com/u/4123377/gap.png
html: http://pastebin.com/7WktN5EA
css: http://pastebin.com/Fj8rukJ8
The button is "#login"
The #login ul ul seems to be setting a top value of 50, which applies to the first element as well as all the others - so the first element seems to be causing the gap.
#login ul ul {
background-image: url(../assets/loggeddarkfill.png);
background-repeat: no-repeat;
position: absolute;
top: 50px; /* this guy */
visibility: hidden;
}
The right value is 40px - that will get rid of the gap and position the list like you want it.
Looks like you need to adjust the top value for #login ul ul.

why is div inheriting the property of sub div?

in the header section of my web page, the design is something like the logo and navigation div should overlap a repeat-x image(i.e bg-header).
this is the html i have used
<div id="header">
<div id="header-bar">
<p>kljslakdjlaskjdkljasdlkjasdlkjaskldjasjd</p>
</div>
</div>
and this is the css
#header {
min-width: 1040px;
height: 111px;
position: relative;
}
#header-bar {
margin-top:50px;
height:53px;
}
now when in the #header-bar if i give margin-top:50px then the header div shifts the position to 50px from top. i want to achieve something like
the header div is to define the height of the header content.
i want to wrap header-bar in the header div and the elements or the div wrapped inside the header div should should have the margin of 50px from within the header.
for example the header-bar should have a margin of 50px from the top of the header div.
when i use the above code it moves the position of header div too. i want the header div to be fixed on top only the sub div or content within the header div is what i want to position.
hope i am not confusing you.
where i am going wrong?
thank you
EDIT: it works if i use padding-top but excluding the background with repeat-x property.
i want to move the image with repeat-x property. in the header-bg div
Margin doesn't affect the position of elements relative to their parents.
To achieve the effect you want, you need to use padding on the #header, for example:
#header {
min-width: 1040px;
height: 61px;
position: relative;
padding-top: 50px;
}
#header-bar {
height:53px;
}
If you add "overflow:hidden" to the #header div, it'll work like a charm! Note that there is padding, but also margin. If you remove the padding, there will still be space left, that's the margin!
Jsfiddle example here
Use padding on the header div rather than margin.
#header {
min-width: 1040px;
height: 111px;
padding:50px 0px 0px 0px;
}
#header-bar {
height:53px;
}
You're running into something called margin-collapse. In essence, adjacent margins will collapse together, and only display the larger one - that is, the one with more absolute distance from 0. Since your #header margin (0px) is adjacent to your #header-bar margin (50px), the 50px margin is the one that is displayed, and it affects both of your elements.
If you were to add even 1px of padding to the top of #header, you would get the desired effect:
#header {
min-width: 1040px;
height: 111px;
position: relative;
padding-top: 1px;
}
I'm not sure I understood the question.
Does it seem like your answer : link ?