Having a kind of silly issue where my HTML image won't link to the page and doesn't show up as clickable. I have a cart and icon of a cart that displays the number of items in the cart. The image is included in the CSS. I tried setting the z-index all the way up but nothing happened. Not sure if I'm missing something obvious. Fairly new to this so any help is appreciated! Below is my Code:
.cart {
background-color: #E55F5F;
background-image: url(images/shoppingcart.png);
background-size: contain;
color: white;
height: 60px;
width: 60px;
line-height: 60px;
text-align: center;
margin-top: -20px;
border-radius: 50%;
position: fixed;
z-index: 1000;
overflow: hidden;
}
<li>
<div class="cart">
</div>
<div id="quantityCount">0</div>
</li>
The link is an inline element by default and - having no content - occupies only very little space inside its container (if any). To change that make it a block element with the full size of its container:
.cart a {
display: block;
width: 100%;
height: 100%;
}
Your tag doesn't have any value, So that it can be made clickable.
You can use it like below:
<li>
<div class="cart">cart</div>
< id="quantityCount">0</div>
</li>
Otherwise if you want to show the count as clicable
<li>
<div class="cart"><span id="quantityCount">0</span></div>
</li>
Try these codes:
background-image: url(../images/shoppingcart.png);
well make sure the anchor tag inside card have same widht and height
.cart {
background-color: #E55F5F;
background-image: url(images/shoppingcart.png);
background-size: contain;
color: white;
height: 60px;
width: 60px;
line-height: 60px;
text-align: center;
margin-top: -20px;
border-radius: 50%;
position: fixed;
z-index: 1000;
overflow: hidden;
position: relative;
}
.cart a{
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
z-index: 10;
}
make your <a> tag a parent of the <div class="cart"> tag. otherwise, your code works fine for me. perhaps the path to your image is incorrect? i replaced your image path with a hosted image and everything worked fine
It's a fundemental issue. You added a link but with no content (nothing between the tags).
Because of that the link also has nothing that will be shown and therefor uses up no space. Because of that, you cant click it.
The right structuring for that is, to put the div between the tag and the entire div will be a button for the link.
.cart {
background-color: #E55F5F;
background-image: url(images/shoppingcart.png);
background-size: contain;
color: white;
height: 60px;
width: 60px;
line-height: 60px;
text-align: center;
margin-top: -20px;
border-radius: 50%;
position: fixed;
z-index: 1000;
overflow: hidden;
}
<li>
<a href="/homework_6/cart.html">
<div class="cart">
<id="quantityCount">0</div>
</div>
</a>
</li>
Wrap a link (a href tag) around your icon. Check out this example where I used Font-Awesome's shopping cart icon. see all of code here: https://codepen.io/susanwinters/pen/qBNYdBG
<h1>Shopping Cart Icon</h1>
<p>Go ahead and click the shopping cart icon:
<a href="https://teespring.com/stores/campsitecoders" target="_blank" />
<i class="fa fa-shopping-cart fa-3x"></i><span>5</span>
</a></p>
Related
I am trying to make a header with a fixed title, horizontally and vertically centred. With a home icon that acts as a link.
The problem is that link is clickable on everything left of the Home icon.
I have tried to replicate the problem in this codepen;
body {
margin: 0;
background-color: #2d2d2d;
}
#header {
margin: 0;
background-color: rgb(171, 228, 250);
height: 10vh;
display: flex;
}
#homeIcon {
position: absolute;
padding-top: 2px;
padding-left: 30vw;
height: 10vh;
}
#headerTitle {
margin: auto;
font-size: 5vh;
color: #2d2d2d;
}
<div id="header">
<a href="">
<img id="homeIcon" src="https://image.flaticon.com/icons/svg/846/846551.svg" alt="homeicon" />
</a>
<h1 id="headerTitle"> title </h1>
</div>
Is there a way to have the link only on the content of the img tag?
In your CSS you are specifying the homeIcon has a padding-left of 30vw. If you change this to margin-left instead, it will no longer be clickable. This is because padding is included inside your element, while margin is outside. See https://www.w3schools.com/css/css_boxmodel.asp.
The css is your problem: you can solve it by changing padding-left: 30vw; to margin-left: 30vw;
This answer may be useful background reading: Difference between margin and padding?
I'm just starting web development, and I'm trying to construct a page-navigation bar with a bunch of 'Div' elements, but I cant seem to get my second button ("AboutButton") to appear on the screen. Here is my HTML body code:
<body>
<div id="navbar" id="top">
<div id="pageselection">
<div id="HomeButton"> HOME </div>
<div id="AboutButton"> <a href="#About> ABOUT </a> </div>
</div>
</div>
</body>
and here is my CSS for the page:
#navbar{
Position: fixed;
Width: 100%;
Height: 10%;
}
#pageselection{
Position: absolute;
Width: 40%;
Height: 100%;
Right: 30%;
}
#HomeButton{
Position: absolute;
Width: 33%;
Height: 100%;
Left: 0%;
text-align: center;
}
#AboutButton{
Position: absolute;
Width: 33%;
Height: 100%;
Left: 33%;
text-align: center;
}
Essentially, I'm trying to build a 'div' that runs across the top of the page, then mark off the central 40% of that 'div' as a space for a second 'div' to sit, which will in turn hold the three links that users can use to navigate the page.
Thanks in advance, hopefully its a stupid error, and I hope my description was clear enough :)
You missed an quote mark in
<a href="#About>
If you are only starting, i recommend you to use some free editors like Atom or Sublime that will alert you about this kind of errors.
Also, it is not allowed to use "id" two times on an element. A better practice would be to use classes where you will be able to stack them like:
<div class="navbar top"></div>
You missed an ending quote " in <a href="#About>. I also recommend another approach on your nav bar. Don't absolute position the links in the nav bar, that's not needed. And also, one element can have one ID, not multiple. I've made some changes and used classes instead of IDs below. Please have a look.
#navbar{
position: fixed;
width: 100%;
height: 10%;
top: 0;
left: 0;
background-color: whitesmoke;
height: 40px;
}
#pageselection{
position: absolute;
width: 40%;
height: 100%;
right: 30%;
background-color: gray;
}
.nav-button{
float:left;
width:33%;
height: 100%;
text-align: center;
line-height:40px;
}
.nav-button a{
display:block;
height: 100%;
}
<div id="navbar" id="top">
<div id="pageselection">
<div class="nav-button">HOME</div>
<div class="nav-button">ABOUT</div>
<div class="nav-button">TEST</div>
</div>
</div>
Im trying to put a link button to amazon on a picture but not only is it not working its making my website all wonky
.review-page-lander > img {
width: 100%;
max-width: 1169px;
margin: 0 auto;
}
img.buy-from-button{
height: 35px;
width: 150px;
top: 35px;
float:left;
position: relative;
z-index: 1;
}
<div class="lander-image">
<a href="#">
<img class="buy-from-button" src="http://oathtohealth.com/wp-content/uploads/2016/05/Amazon.png" alt="buy at amazon">
</a>
<img src="amazon-item.jpg">
</div>
As i mentioned in my comment, difficult to answer without more info
First off, using .review-page-lander > img wont work as the > means immediate child, http://www.w3schools.com/cssref/css_selectors.asp
To find what else not working, use F12+inspect in chrome (or similar in other browsers) to find what css being applied
https://developers.google.com/web/tools/chrome-devtools/
https://developers.google.com/web/tools/chrome-devtools/inspect-styles/
I would suggest to keep your product image above your buy button and make buy button float right relatively with bottom: 40px;
.lander-image>img {
width: 100%;
max-width: 1169px;
margin: 0 auto;
}
img.buy-from-button {
height: 35px;
width: 150px;
float: right;
position: relative;
z-index: 1;
bottom: 40px;
}
<div class="lander-image">
<img src="http://placehold.it/250x300">
<a href="#">
<img class="buy-from-button" src="http://oathtohealth.com/wp-content/uploads/2016/05/Amazon.png" alt="buy at amazon">
</a>
</div>
footer {
width: 960px;
height: 100px;
background-color: #121212;
line-height: 100px;
color: white;
font-size: 10px;
position: relative;
}
#copyright {
margin-left: 3%;
opacity: 0.4;
}
#icon {
background-image: url('../img/icon.png');
background-repeat: no-repeat;
width: 85px;
height: 86px;
opacity: 0.050;
position: absolute;
right: 0;
margin-top: 7px;
margin-right: 5px;
display: block;
}
#top {
background-image: url('../img/backtop.png');
background-repeat: no-repeat;
width: 29px;
height: 29px;
margin-top: 4%;
margin-right: 6%;
float: right;
}
#top:hover {
background-image: url('../img/tophover.png');
background-repeat: no-repeat;
width: 29px;
height: 29px;
}
<footer>
<div id="top"></div>
<span id="copyright" class="left_content">GGLex is copyrighted © 2014, All rights reserved.</span>
<div id="icon"></div>
</footer>
What it looks like:
(source: gyazo.com)
I am trying to add a faded out icon, on the right side on my footer. I did it, works just fine, but when I tried to add back to top button with hover, it failed.
Basically, when I hover, it won't work, but if I remove the div "icon", it will work easily (the hover).
Why does it happen & how can I make it work?
Unfortunately this happens sometimes when css styles overlaps. You can use javascript to solve this...
onmouseover="window.location='URL HERE'"
Example
<div onmouseover="window.location='URL HERE'"></div>
Hope this helps and please comment back if this doesn't work or you need more help
the below works...
<footer>
<div id="top"></div>
<span id="copyright" class="left_content">GGLex is copyrighted © 2014, All rights reserved.</span>
<div id="icon" onmouseover="window.location='URL HERE'"></div>
</footer>
URL TO top of page. ID any element at top of page for example id="top" then replace URL with www.YOUR_WEB_NAME.CO.UK/#top
You can try to add pointer-events: none; to the absolutely positioned element. That way clicks/"pointer events" can go "through it", affecting the element behind it.
I have this landing page. I'd like the email to be a link to mailto:info#domain.tld.
I tried to use a map (usemap="#mail" on body and then map name="mail">) but it doesn't work. I tried also with a blank transparent png image (to set the usemap to) but the link isn't clickable.
How can I achieve the area of the email to have a link upon it? Of course it should work on different resolutions.
Why don't you just render the email link as text? It looks like it can be similar to Open Sans: http://www.google.com/webfonts/specimen/Open+Sans
You could do something like this:
ADD CSS:
div#mail {
margin-left: 67%;
margin-top: 31.8%;
overflow: hidden;
width: 16%;
}
a {
color: transparent;
}
ADD HTML:
<div id="mail">info#gioiellidisapone.it</div>
Demo: http://jsfiddle.net/fXats/
It's not perfect, but maybe it's good enough. :)
This is how I modified your page directly using Inspect element, and the link stays on top of the image text. This is another option, but has fixed width and height to support the positioning of the email.
<body>
<div style="
width: 1430px;
position: absolute;
border: 1px solid #000;
height: 700px;
background-image: url(home2.jpg);
background-repeat: no-repeat;
background-position: top center;
display: inline-block;
"><a href="#" style="
position: relative;
top: 450px;
right: 294px;
display: inline-block;
float: right;
">Info#gioiellidisapone.it</a>
</div>
</body>