This question already has answers here:
How to position text over an image with CSS
(8 answers)
Closed 7 years ago.
I am new to html and css. I am trying to make a website. I have four images on a line that works as links. When you hold the mouse over them, they turn transparent. I also want a headline to show up over the transparent image when you hold the mouse over it. But when I put text there it ends up on the line over the images instead of on top of them. The text also do not appear only when the mouse is over it, but it is there all the time. Here is my css:
p2 {
color: white;
font-size: 15px;
font-family: 'Verdana';
}
img {
box-shadow: 7px 7px 4px grey;
padding-left: 18px;
padding-right 18px;
}
img:hover {
opacity: 0.5;
filter: alpha(opacity=50);
}
Here is the html:
<p> TITLE THAT I WANT OVER THE FIRST IMAGE </p>
<a href="LINK1">
<img border="0" src="PHOTOLINK1" width="310" height="214">
</a>
<a href="LINK2">
<img border="0" src="PHOTOLINK2" width="310" height="214">
</a>
<a href="LINK3">
<img border="0" src="PHOTOLINK3" width="310" height="214">
</a>
<a href="LINK4">
<img border="0" src="PHOTOLINK4" width="310" height="214">
</a>
Please help me if you know how to do this, thank you. <3
Try assigning z-index css property to text
You can set your top margin to a negative value.
margin-top: -100px;
This is wrong:
p2 {
Change it with:
p {
You need to nest all the <a>s correctly. You didn't close a lot.
And a solution for you would be, you might need to change the code a little bit:
a {
position: relative;
}
span {
position: absolute;
color: white;
font-size: 15px;
font-family: 'Verdana';
bottom: 0;
left: 0;
right: 0;
background: #000;
}
img {
box-shadow: 7px 7px 4px grey;
padding-left: 18px;
padding-right 18px;
}
img:hover {
opacity: 0.5;
filter: alpha(opacity=50);
}
<a href="LINK1">
<img border="0" src="PHOTOLINK1" width="310" height="214" />
<span> TITLE THAT I WANT OVER THE FIRST IMAGE </span>
</a>
<a href="LINK2">
<img border="0" src="PHOTOLINK2" width="310" height="214" />
</a>
<a href="LINK3">
<img border="0" src="PHOTOLINK3" width="310" height="214" />
</a>
<a href="LINK4">
<img border="0" src="PHOTOLINK4" width="310" height="214" />
</a>
You can use position:absolute and put <p> child of <a> with a class
CSS
p2{
color: white;
font-size: 15px;
font-family: 'Verdana';
}
img {
box-shadow: 7px 7px 4px grey;
padding-left: 18px;
padding-right 18px;
}
img:hover {
opacity: 0.5;
filter: alpha(opacity=50);
}
.LINK1 p {
position: absolute;
top: 20px;
padding: 0px 20px;
}
HTML
<a href="LINK1" class="LINK1">
<p> TITLE THAT I WANT OVER THE FIRST IMAGE </p>
<img border="0" src="PHOTOLINK1" width="310" height="214">
</a>
<a href="LINK2">
<img border="0" src="PHOTOLINK2" width="310" height="214">
<a href="LINK3">
<img border="0" src="PHOTOLINK3" width="310" height="214">
<a href="LINK4">
<img border="0" src="PHOTOLINK4" width="310" height="214">
</a>
Note: Adjust your needs
DEMO HERE
Related
I have a store with a gallery. I was looking to overlay the Thumbnail if a Sold stamp that I made.
If i disable the image the overlay is showing bellow, so I know it is inserting the image, it isn't on top though.
What I see:
How I know the overlay is below (thumbnail disabled):
HTML:
<li class="post-66 product type-product status-publish has-post-thumbnail sold-individually shipping-taxable purchasable product-type-simple outofstock">
<center>
<a href="http://url.com">
<img width="150" height="150" src="thumbnail.jpg" class="attachment-shop_catalog wp-post-image" alt="coelho1" />
<h3>Coelho de Peluxe</h3>
</a>
</center>
</li>
CSS:
.outofstock {
background: url("soldoverlay.png") top left no-repeat;
position: relative;
z-index: 200;
}
.attachment-shop_catalog{
z-index: 1;
}
Can anyone please help me?
Kind Regards
The best way to make an overlay is use a pseudo-element using the class you already have outofstock. Check this snippet as an example:
li {
position: relative;
display: inline-block;
white-space: nowrap;
text-align:center;
margin:10px;
}
.outofstock:after {
content: " ";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, .6);
z-index: 10;
}
<ul>
<li>
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>WITHOUT OVERLAY</h3>
</a>
</li>
<li class="outofstock">
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>OVERLAY</h3>
</a>
</li>
</ul>
Edit
To keep the link to of the href you can create the pseudo-element inside the a tag like this:
li {
display: inline-block;
white-space: nowrap;
text-align: center;
margin: 10px;
}
a {
position: relative;
display:block;
}
.outofstock a:after {
content: " ";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, .6);
z-index: 10;
}
<ul>
<li>
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>WITHOUT OVERLAY</h3>
</a>
</li>
<li class="outofstock">
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>OVERLAY</h3>
</a>
</li>
</ul>
you could avoid to use an image and play with CSS 2D transformations (supported even on IE9)
e.g. http://codepen.io/anon/pen/NPydBP
Markup
<ul>
<li data-in-stock="vendido">
<a href="">
<img src="http://dummyimage.com/400x280/cccccc/fff.jpg" />
</a>
</li>
</ul>
CSS
li {
position: relative;
overflow: hidden;
}
[data-in-stock]:after {
position: absolute;
top: 0;
left: 0;
z-index: 1;
content: attr(data-in-stock);
display: block;
min-width: 160px;
color: #fff;
background: #222;
padding: 6px 10px;
text-transform: uppercase;
font: 1em Arial;
-webkit-transform: rotate(-42deg) translateX(-50px);
-moz-transform: rotate(-42deg) translateX(-50px);
transform: rotate(-42deg) translateX(-50px);
}
The text overlapped comes from the data-in-stock attribute in the markup, so you can easily change the text or optionally serve a different page language
This approach could also work if you need to show an image instead of a text (the content property also accepts an url to an image): see http://codepen.io/anon/pen/dPdNBQ
Final Result
1) Create a DIV to place your image in, set left and top css, and set z-index to 5, set width and height to be same as image
2) Create another DIV with same left, top, width, and height, but set z-index higher. Place img tag with outofstock in it
I am having an issue with positioning a caption on top of a picture. The pictures are in a column, there are 4 columns. The first 3 columns seem to work fine but then when it comes to the last column, it does not look right at all and I feel like it may have to do with wordpress css? I have tried to add css to the last column which positions it correctly but then the width is not right... I am so confused. This may be such a simple fix but I can't seem to figure it out
Here is the link to the website
http://aminkhalil.com
Here is my html code
[fourcol_one]
<a href="#" class="caption">
<img class="hover" alt="Services" src="http://growinggood.com/wp-content/uploads/2014/02/billboard-slider-images.jpg" />
<span class="caption">Services</span></a>
[/fourcol_one]
[fourcol_one]
<a href="#" class="caption">
<img class="hover" alt="Keep Healthy" src="http://growinggood.com/wp-content/uploads/2014/02/billboard-slider-images.jpg" />
<span class="caption">Keep Healthy</span></a>
[/fourcol_one]
[fourcol_one]
<a href="#" class="caption">
<img class="hover" alt="Meet The Staff" src="http://growinggood.com/wp-content/uploads/2014/02/billboard-slider-images.jpg" />
<span class="caption">Meet The Staff</span></a>
[/fourcol_one]
[fourcol_one_last]
<a href="#" class="caption">
<img class="hover" alt="Portal" src="http://growinggood.com/wp-content/uploads/2014/02/billboard-slider-images.jpg" />
<span class="caption">Portal</span></a>
[/fourcol_one_last]
Here is my css
a.caption{
position:relative;
}
a:hover img.hover{
opacity: 0.5;
filter: alpha(opacity=530);
}
span.caption{
color: #fff !important;
position: absolute;
bottom: 0;
left: 2%;
padding: 1.9%;
width: 93%;
background-color: rgba(0,0,0,0.5);
}
.last span.caption{
bottom: 22px;
left: 3px;
}
Any help is appreciated. Thank you in advance!!
I figured it out!! I had some extra spaces/breaks in the HTML which was making the first 3 columns different than the last. I added/changed a couple of things to span.caption and deleted the CSS for .last span.caption
span.caption{
color: #fff !important;
position: absolute;
padding: 1.9%;
width: 93.5%;
background-color: rgba(0,0,0,0.5);
display: block; /* added */
bottom: 0; /* changed */
left: 3px; /* changed */
}
Thanks to anyone who may have done any research!!
I used a website called niftybuttons to generate an html code for social icons for my website. Can anybody tell me how I can center the icons and possibly add space between them?
HTML
<a href="http://facebook.com/makemoneywithjus" target="_blank">
<img src="http://www.niftybuttons.com/retro/32/facebook.png" align="left" border="0" style="margin:1px;"></a><a href="http://twitter.com/makemoneywitjus" target="_blank">
<img src="http://www.niftybuttons.com/retro/32/twitter.png" border="0" style="margin:1px;" align="left">
</a>
<a href="http://youtube.com/user/makemoneywithjus" target="_blank">
<img src="http://www.niftybuttons.com/retro/32/youtube.png" border="0" style="margin:1px;" align="left">
</a>
<a href="www.linkedin.com/pub/justina-cipriano/92/779/6b5/" target="_blank">
<img src="http://www.niftybuttons.com/retro/32/linkedin.png" border="0" style="margin:1px;" align="left">
</a>
<a href="https://plus.google.com/u/0/b/106075638630703080775/106075638630703080775/posts/p/pub" target="_blank">
<img src="http://www.niftybuttons.com/retro/32/google-plus.png" border="0" style="margin:1px;" align="left">
</a>
To add space between the Icons use padding
#list-left #set li a{
padding: 0 8px 0 0;
}
ul#set li:nth-child(2) {
display: table-cell;
padding: 10px 2px 10px 30px;
}
Try this fiddle: Demo
div{
position: relative;
left: 35%;
}
div a{
margin: 5px;
display: inline-block;
}
I actually previously had a much longer question but I figured this would be the easiest to get situated. When I initially load my page, some of the items in the navigationBanner get displaced. But after I enter an order number in the text box and it reloads... everything is where it should be. I'm assuming my CSS is not loading when it should be, but I'm not entirely sure because I am entirely noobish at html and css.
Could anyone explain this to me?
Here's my html for the nav bar
<div id="background"><img src="images/blue%20background.jpg" alt="background" width="100%" height="100%" /></div>
<div id="header">
<div id="navigationContainerWrap">
<div id="navigationBanner">
<a href="">
<img src="images/facebook.png" alt="Facebook Link" border="0" style="margin: 4px 0 5px 44px;" /></a>
<a href="">
<img src="images/twitter-2.png" alt="Twitter Link" border="0" style="margin: 4px 0 5px 2px;" /></a>
<a href="">
<img src="images/pinterest-icon.png" alt="Pinterest Link" border="0" style="margin: 4px 0 5px 2px;" /></a>
<img src="images/txtNewCustomers.png" alt="New Customers txt" style="margin: 0px 0 5px 50px;" />
<img src="images/txtExistingCustomers.png" alt="Existing Customers txt" style="margin: 0 0 5px 50px;" />
<a href="">
<img src="images/email.png" alt="Email Link" border="0" style="margin: 4px 10px 6px 0;
float: left;" /></a>
<p style="float: left;">
1.800.BLAH.BLAH</p>
<a href="">
<img src="images/btnOrder.png" alt="New Customers Button" border="0" style="float: left;
margin: 0 0 0 45px;" /></a>
<a href="">
<img src="images/btnLogIn.png" alt="Log in Button" border="0" style="float: left;
margin: 0 10px 0px 25px;" /></
<!-- Order tracking Form input -->
<div class="trackingInput">
Order Status<br />
BloopBloop Order Number:<br />
<input id="txtOrderID" type="text" onkeydown="if (event.keyCode == 13) document.getElementById('btnOrder').click()" />
<input type="button" id="btnOrder" value="Submit" onclick="return btnOrder_onclick()" />
</div>
</div>
Annnnd what I believe is relevant CSS
.trackingInput
{
float: right;
/*padding: 0 5px 0px 0;*/
z-index: 35;
font-weight: normal;
font-family: "Century Gothic";
height: 85px;
margin-top: -45px;
position: relative;
margin-left: -1px;
width: 178px;
}
#navigationBanner
{
background-color: black;
background-repeat: no-repeat;
height: 85px;
width: 600px;
float: right;
color: White;
font-weight: bold;
font-size: small;
}
#navigationContainerWrap
{
background-position: center;
}
#header
{
background-color: White;
background-image: url(../Images/GenericLogo.png);
width: 960px;
height: 140px;
background-repeat: no-repeat;
margin: 0 auto;
position: relative;
z-index: 10;
}
Thanks in advance! And sorry for the info overload.
Possibilities:
You don't emit the same CSS both times
You don't emit the same HTML both times (e.g. you use different tags and/or classes)
One method to track this down using Internet Explorer:
Load your first page (the one that is not working as you expect) in IE
Hit F12 to open developer tools
Click on the Arrow icon in Developer Tools to enter Select mode
Click on a a part of your web page that isn't displaying correctly
Click on the Trace Styles tab (in Developer Tools)
Explore the style tree to see where each style is deriving from
I have the following code
<html>
<head>
<title>Test</title>
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
#Pictures {
position:absolute;
width:591px;
height:214px;
z-index:1;
left: 17%;
top: 30%;
text-align:center;
}
#Links {
width:600px;
height:30px;
z-index:2;
top: 184px;
font-family: "Broadway", Broadway, monospace;
font-size: 14px;
color: #FFFFFF;
text-align: center;
}
.links2 {
font-family: Broadway;
color: #FFFFFF;
text-decoration: none;
}
a:links2, a:visited {
color: #ffffff;
}
a:hover, a:active {
color: #333333;
}
#Main {
position:absolute;
width:800px;
height:600px;
z-index:2;
left: 15%;
top: 10%;
right: 15%;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
}
#Logo {
position:absolute;
float: left;
width:104px;
height:100px;
z-index:2;
}
</style>
</head>
<body>
<div id="Main">
<div id="Pictures">
<div>
<a href="1.html" ><img src="1.gif" alt="x" width="181" height="173" border="0" /></a>
1
</div>
<div>
<img src="2.gif" alt="x" width="181" height="173" border="0" align="top" />
2
</div>
<div>
<img src="3.gif" alt="3" width="181" height="173" border="0" />
3
</div>
</div>
</div>
<div id="Logo"><img src="logo.gif" alt="x" width="104" height="100" border="0"/></div>
</div>
</body>
</html>
Which is displaying the picture layers vertically.
I am trying to make it o the 3 images are aligned horizontally with the text centered underneath them. Why are they defaulting to vertical, and can I change this behavior?
You don't actually need that much code to achieve what your're after. For example:
<style>
body {
background-color: #000;
color: #FFF;
}
a {
font-family: "Broadway", Broadway, monospace;
font-size: 14px;
color: #FFF;
}
#images a {
width: 24.99%;
display: block;
float: left;
text-align: center;
}
</style>
<div id="images">
<a href="1.html" >
<img src="1.gif" alt="x" width="181" height="173" border="0" /><br />
One
</a>
<a href="2.html" >
<img src="2.gif" alt="x" width="181" height="173" border="0" /><br />
Two
</a>
<a href="3.html" >
<img src="3.gif" alt="x" width="181" height="173" border="0" /><br />
Three
</a>
<a href="4.html" >
<img src="4.gif" alt="x" width="181" height="173" border="0" /><br />
Four
</a>
</div>
The trick to get the items to align horizontally rather than vertically is to "float" the containers (left or right). By setting the links to display: block; you can use them as the containers instead of wrapping everything in extra <div>s. I have set the width to 25% (or 24.99% to avoid a rounding error in some browsers) so that they're spread out evenly across the page but you might want a different alignment which is easily done using margins/padding and/or a different width on the containers. Note also that when you set a text colour on the body {} you do not need to specify it again elsewhere apart from for links. Same thing goes for font-family, allthough this is also inherited by links. Good luck with the project!
Look at this code and test it: you can do the same thing in a more efficient, semantic and clean way:
Css:
div.imageBox {
float: left;
margin-right: 10px;
}
div.imageBox p {
text-align: center;
}
Html:
<div class="imageBox">
<a href="#">
<img src="image1.gif" width="100" height="100"
alt="image 1" /></a>
<p>1</p>
</div>
<div class="imageBox">
<a href="#">
<img src="image2.gif" width="100" height="100"
alt="image 1" /></a>
<p>2</p>
</div>
<div class="imageBox">
<a href="#">
<img src="image3.gif" width="100" height="100"
alt="image 1" /></a>
<p>3</p>
</div>
That's all you need!
If you want to keep your code, there are no reasons to use the attribute align inside the img tag. You can use span instead of div, but in this case is better to keep using div and give them a width:
div#Pictures div
{
float: left;
margin-right: 5px;
}
This code:
a:links2
has no sense. links2 is a class made by you, not a pseudo-class or a pseudo-element.
I think a display: block; on your links2 class should put the links under the images correctly.
Also, to get the images to line up horizontally, use <span>s instead of <div>s inside the 'Pictures' div, and float them left.
#Pictures span
{
float: left;
margin-right: 5px;
}