You know how tekst (paragraphs) always wrap around a floated image, like so? [see img]
I would like the tekst to go OVER the image. Like in the example img below. I tried using z-index and display:inline but neither worked.
This is not my actual HTML, but basically what I looks like;
<img src="" alt="" style="float:right;" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sed eros tellus, sit amet ultrices quam. Sed quis justo metus, quis gravida orci. Vivamus porttitor fringilla massa at luctus. Quisque lacinia diam eget justo tempor vehicula. Nulla fringilla libero sit amet tortor bibendum imperdiet. Pellentesque in risus vel libero pellentesque hendrerit. Suspendisse vehicula fermentum pretium. Sed elementum eleifend dolor nec aliquam. Nam ac viverra dolor. Vivamus vitae ultricies velit.</p>
Try:
<div style="position: relative;">
<img src="" alt="" style="position: absolute; top: 0px; right: 0px;" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sed eros tellus, sit amet ultrices quam. Sed quis justo metus, quis gravida orci. Vivamus porttitor fringilla massa at luctus. Quisque lacinia diam eget justo tempor vehicula. Nulla fringilla libero sit amet tortor bibendum imperdiet. Pellentesque in risus vel libero pellentesque hendrerit. Suspendisse vehicula fermentum pretium. Sed elementum eleifend dolor nec aliquam. Nam ac viverra dolor. Vivamus vitae ultricies velit.</p>
</div>
The key is absolute positioning. Make sure the container has a position set (use relative if it doesn't have one currently).
(You may also need some z-indexing to make sure the layers are correct).
You could either use position: absolute and z-index to move the image behind the text, or use the image as the paragraph's background image.
eg
HTML:
<p><img src="xyz.jpg" /> Lorem ipsum</p>
CSS:
img {
position: absolute;
top: 0;
right: 0;
z-index: 1;
}
p {
z-index: 10;
}
Alternatively:
<p>Lorem ipsum</p>
CSS:
p {
background: url(xyz.jpg) top right no-repeat transparent;
}
If I understand the question, here is what you want jsfiddle .
Z-index only works with position: absolute.
Countdown coordinates depends on the value of the property position.
If the parent element is set to position: relative, then absolute positioning of child elements determines their position on top of the parent.
Related
I am making a personal page using bootstrap and want to use a blockquote element, however on just the left hand side I get a white line that will not go away even when I wrap the element in multiple divs and try to overwrite whatever border or margin issue that is preventing it from having the same background color. Could someone help me figure out what to do?
HTML
<div class="top-info">
<div class="row">
<div class="col-md-4"><img src="http://www.psdgraphics.com/file/male-silhouette.jpg" width="300" height="250" ></div>
<div class="col-md-8">
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla gravida velit sit amet dolor iaculis, nec semper felis dictum. Vestibulum commodo magna sed enim elementum, in euismod purus molestie. Nulla et nisl sit amet ipsum eleifend facilisis et a nisi. Cras lectus arcu, efficitur ac dictum vel, porttitor lobortis purus. Phasellus tincidunt velit eget ipsum aliquam, non egestas tellus consequat. Curabitur ullamcorper, massa et consequat mollis, metus neque rhoncus felis, eget condimentum lacus elit ac lacus. Pellentesque volutpat euismod neque, nec semper nisl interdum ac. </p>
</blockquote>
</div>
</div>
</div>
CSS:
.top-info{
background-color:#848484;
margin:0;
padding:0;
}
blockquote{
background-color:#848484;
padding:none;
margin:none;
}
Bootstrap uses border-left property to set this "white line" on the left. So all you need to do is to reset it with your custom CSS styles, for example like this:
blockquote {
border-left: 0;
}
Bootstrap by default use border-left in the blockquote element. Setting to none will remove the border.
CSS
blockquote {
border-left: none;
}
I'd like to create a grid of squares in the background of my webpage which already has a lot of different elements carrying content. My trouble now is that the div squares I'm creating are intefereing with the layout of everything else. I've tried setting z-index of the parent div of my square divs to like -3, but that doesn't seem to really help. What's are some good css rules that can help me sort this out? Thanks
Create the tiles in Photoshop and then save it out as a *.PNG or *.GIF. These have the smallest file sizes.
Use this within your container or wrapper div:
.contentContainer {
background:url(images/image_background.png) top left no-repeat;
}
background:url set's the URL of the image.
top left sets the position. You can use just "top", "center", "bottom", etc. or "top left", "top bottom" to align it how you need it.
no-repeat makes it so the BG image doesn't "tile" over and over again as you might have experienced with say, your windows wallpaper. It looks tacky.
As already mentioned, it may be best to use an image for this situation. Regardless, here is a jsfiddle showing how to use absolute positioning on the wrapper for the background squares to take it out of the flow of the document: http://jsfiddle.net/eL1w7kdz/
HTML:
<div id="container">
<div id="background-squares">
<div>Square 1</div><div>Square 2</div><div>Square 3</div><div>Square 4</div><div>Square 5</div><div>Square 6</div><div>Square 7</div><div>Square 8</div><div>Square 9</div><div>Square 10</div><div>Square 11</div><div>Square 12</div>
</div>
<div id="main-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin bibendum neque a venenatis dictum. Donec fringilla euismod sodales.</p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer leo ipsum, aliquam sit amet ligula non, fringilla commodo diam. Vivamus tortor mi, blandit vel mi at, feugiat rhoncus libero. Donec volutpat, tellus nec sagittis tempor, leo dui sollicitudin turpis, et fringilla nisl metus ac libero. In augue mauris, malesuada id ipsum vel, hendrerit vulputate justo.</p><p>Morbi aliquam est non fringilla cursus. Sed at felis et magna vehicula egestas. Integer finibus lectus lorem, a commodo nulla rutrum eu. Sed eleifend condimentum tristique. Curabitur eu nisl mi. Etiam imperdiet nisl metus, at iaculis ex consequat eget. In non eros dolor.</p>
</div>
</div>
CSS:
#background-squares {
position: absolute;
z-index: -1;
}
#background-squares div {
background-color: lightblue;
width: 100px;
height: 100px;
margin-right: 10px;
margin-bottom: 10px;
float: left;
}
#main-content {
padding: 10px;
}
I have an paragraph and an image (See Example in CodePen):
<div>
<p>
Lorem ipsum dolor sit amet ...
<img src="http://placehold.it/200x200"/>
</p>
</div>
And the following CSS:
div {
margin: 0 auto;
width: 60%;
}
img {
float: right;
padding: 20px;
}
How can I wrap he text around the image?
I tried float:right but this does not seem to work.
Place the image before the text:
<div><img src="http://placehold.it/200x200"/>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam nec eros enim. Donec et scelerisque nisl, nec luctus massa. Nullam ut laoreet sem. Sed ligula elit, auctor et sagittis facilisis, auctor in nulla. Nulla suscipit dignissim feugiat. Vivamus lacinia tellus elit, non bibendum purus tempus eget. Sed porttitor accumsan lacus, at aliquam nisi rutrum nec. Donec a dignissim tortor. Curabitur blandit non turpis tristique tincidunt. Sed dictum sem id sem lacinia mattis. Quisque pellentesque, sem sit amet auctor congue, enim lorem egestas nisi, sit amet accumsan turpis turpis et metus. Mauris pulvinar luctus felis, in feugiat dui vulputate ac. Sed faucibus libero nulla, placerat accumsan elit rutrum et. Maecenas id enim quis turpis pretium sollicitudin.
</p>
</div>
codepen example
You're using float correctly with the image, but since in your original example the image is coming after the text, you don't notice the effect. By moving the image before the text, it gets floated to the right, and the text that comes after it is then allowed to float up alongside it.
put the image at the top
<img src="http://placehold.it/200x200"/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam nec eros enim...
I have an HTML structure like this:
<div>
<div style="position:relative;">
<div style="position:absolute;float:left;top:0;left:0;width:50px;">57</div>
<div style="width:550px;position:absolute;float:left;top:0;left:50px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sed ipsum eu justo ornare euismod. Suspendisse bibendum venenatis nisl, ut blandit odio aliquet sit amet. Donec ultricies purus eu metus faucibus venenatis. Donec imperdiet sagittis pretium. Quisque pellentesque malesuada eros sit amet fringilla. Cras egestas vehicula pharetra. Nunc mattis aliquam erat pharetra tempus. Sed magna dui, facilisis nec pharetra dignissim, lobortis vel nulla. Etiam tellus dui, dapibus sit amet sodales vitae, tempus eu felis. Nam interdum sagittis libero, nec sagittis nisl dapibus et. Nulla facilisi.</div>
</div><br /><br />
<p style="margin-left:50px;">This is my paragraph</p>
</div>
As you can see from THIS FIDDLE, My Lorem Ipsum text overlaps with my paragraph. I tried putting somme <br /> between my div and my paragraph, but they still overlap. I want my paragraph to appear after my text. Any help please?
Thank you
You don't use position:absolute with a float. You can just use the float in this case and get rid of position and the related css.
Just this would be fine:
<div>
<div style="position:relative;">
<div style="float:left;width:50px;">57</div>
<div style="width:550px;float:left;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sed ipsum eu justo ornare euismod. Suspendisse bibendum venenatis nisl, ut blandit odio aliquet sit amet. Donec ultricies purus eu metus faucibus venenatis. Donec imperdiet sagittis pretium. Quisque pellentesque malesuada eros sit amet fringilla. Cras egestas vehicula pharetra. Nunc mattis aliquam erat pharetra tempus. Sed magna dui, facilisis nec pharetra dignissim, lobortis vel nulla. Etiam tellus dui, dapibus sit amet sodales vitae, tempus eu felis. Nam interdum sagittis libero, nec sagittis nisl dapibus et. Nulla facilisi.</div>
</div><br /><br />
<p style="margin-left:50px;">This is my paragraph</p>
</div>
Though, as the comments suggest - you should put this in a stylesheet and avoid inline declarations. It's cleaner and tends to be easier to maintain.
Remove your position absolute and put clear: both to your paragraph to reset the floating elements
<div>
<div style="position:relative;">
<div style="float:left;width:40px;">57</div>
<div style="width:550px;float:left;left:40px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sed ipsum eu justo ornare euismod. Suspendisse bibendum venenatis nisl, ut blandit odio aliquet sit amet. Donec ultricies purus eu metus faucibus venenatis. Donec im.</div>
</div>
<p style="clear: both;margin-left:40px">This is my paragraph</p>
</div>
Live exemple here
If you are using floats why are you mixing it with absolute positions?
I've changed this a little.
<div style="float:left;width:40px;">57</div>
<div style="width:550px;float:left;margin-left:40px;">
Try this one. By the way, I've added clearfix method too, as it is recommended to clear floating spaces when you are not floating anything anymore.
If you don't want them, you can remove the div with .clearfix and the CSS.
Here you go.
Looks like you've got the unholy duo of absolute positioning and float:left without a "clear". This means your first child div with those two children will have no height whatsoever. I recommend removing position:absolute and float:left from these divs, using instead:
display:inline-block;
vertical-align:top;
This will allow them to flow left -> right and have a height within the page flow.
I'm trying to make a page without the opacity css stuff, but with a transparant image over all the text and images. Only, i can't get the background over the text.
CSS:
background-image: url('spotlight.png');
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 100;
And HTML simple:
<div class="darkLayer"></div>
Result:
Thanks!
If you want the png overlay over everything in the page, you need to have your overlay div empty of all content, and increase z-index to something like 20000 or whatever.
Although, I'm not 100% sure what you are trying to do.
But it does beat css in terms of cross-browser compatiblity, I think.
Yes, use quotation marks on your image url.
The url should be url('spotlight.png'); and of course the png have to be transparent. I also suggest toninoj's idea with the high number z-index.
Anyway. Why do you want to do this? The only explanation I can guess is for making right click resist web pages, but there are other better way for reaching that goal.
How about this?
http://jsfiddle.net/Z8rkT/
In this example you'd just replace the background/opacity lines with your transparent background image.
<div class="wrapper">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla gravida, metus pharetra euismod eleifend, nisi est tempor massa, vel consectetur lorem elit non ante. Nulla facilisi. Nulla id libero eu erat suscipit pellentesque ultrices quis tellus. Donec ante dui, scelerisque nec venenatis id, suscipit sit amet ligula. Nulla turpis justo, fermentum id ullamcorper condimentum, posuere sit amet ligula. Praesent auctor, mi at tempor tincidunt, felis libero pretium ipsum, quis iaculis odio erat eu urna. Integer vel fermentum ipsum. Duis sit amet accumsan nunc. Nulla facilisi. Etiam condimentum nulla nec quam venenatis laoreet. Etiam massa ipsum, pellentesque sed imperdiet eget, ornare eget est. Fusce pulvinar lorem in nunc tempus fringilla. Vivamus posuere augue a mi interdum rhoncus. </p>
</div>
<div class="overlay"></div>
html, body {
width:100%;
height:100%;
}
.wrapper {
position:relative;
z-index:1;
}
.overlay {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:#333;
opacity:0.75;
}