Making image into a link won't work - html

So I'm having some difficulties making a list of images into working links. This is an example how they are addressed in my HTML:
<img src="img/plnt1_.png">
and then how they are referred to in my CSS:
a.plant1 {
position: absolute;
z-index: 1;
left: -20%;
width: 50%;
top: -20%;
}
now, the problem is, when i put the 'a' in front of my CSS part, my image disappears... but when I do it without an 'a', there is no link.

Try this
.plant1 {
position: absolute;
z-index: 1;
left: -20%;
width: 50%;
top: -20%;
}

The mistake here is the positioning:
a.plant1 {
position: absolute;
z-index: 1;
left: -20%;
width: 50%;
top: -20%;
}
positions your link outside of your viewport (or at least outside of the parent element which may hide overflowing children), I created a fiddle where you can see that:
http://jsfiddle.net/3ajrw1yg/
So, you need to reconsider what it is that you want to achieve position-wise and change your css accordingly.

You're not giving it height, when you have a position absolute, you must have your sizes defined, try this:
a.plant1 {
position: absolute;
z-index: 1;
left: -20%;
top: -20%;
width: 50%;
height: 100px;
}
and you should also close your IMG tag if you're not using HTML5...
<a href="plantvb1.html" class="plant1">
<img src="img/plnt1_.png" />
</a>

Related

How to remove space between bannner and content in wordpress theme?

I have a problem with some CSS ,maybe someone can help me out .
I dont see any margin or padding there that will be the problem.Only that the height is to big or something.
I am using wordpress Sydney theme.
This is the website.
How can i get the space out between the banner and the content of the page ?
Here is a screenshot of what i mean.
Thank You.
#sf-slider-overlay {
position: absolute;
top: 230 px;
z - index: 999;
width: 1170 px;
margin - left: auto;
margin - right: auto;
}
you only have to do this..
Position : absolute
Will work ☺
There is one element (#sf-slider-overlay) with wrong position.
#sf-slider-overlay {
position: relative;
top: 230px;
z-index: 999;
width: 1170px;
margin-left: auto;
margin-right: auto;
}
Change it to,
#sf-slider-overlay {
position: absolute;
top: 230px;
z-index: 999;
width: 1170px;
margin-left: auto;
margin-right: auto;
}
So Simple just add below code to custom css style of your theme
#sf-slider-overlay {
position: absolute;
}
Your problem will be solved or put above code in your page css.
That's because the space isn't caused by any margin or padding. The space is caused by an element that has been moved out of the way using position relative.
#sf-slider-overlay {
margin-left: auto;
margin-right: auto;
position: relative;
top: 230px;
width: 1170px;
z-index: 999;
}
If you change this to have a position:absolute; it fixes the extra space that you had.
Like this:
#sf-slider-overlay {
margin-left: auto;
margin-right: auto;
position: absolute;
top: 230px;
width: 1170px;
z-index: 999;
}
You may have to fiddle with the positioning slightly to get it right, I noticed that once absolute has been set, the word "Domestic" sits right on the edge of the screen, so perhaps add a left:2em; to the property, or even padding-left:2em;
You are using position: relative; in the element #sf-slider-overlay. position: relative; takes an element out of the float, but the space remains there.
You can use position: absolute; but have to set the left property to get the same result as now:
#sf-slider-overlay {
position: absolute;
left: 50%;
translate: translateX(-50%);
}

why does "top: -50%;" not work on this situation but "left: -50%" does

Here is my example code:
.container {
position: absolute;
left: 50%;
top: 50%;
}
.container .box{
position: relative;
width: 200px;
height: 200px;
left: -50%;
top: -50%;
background-color: red;
}
In the .container element, I set nothing on both width and height. But this example works on horizontal side, but not work on vertical side. In fact, the computed value of top is -100px, but the browser does not move the .box element 100px to the top.
This looks like a bug in webkit. If you search their bug tracker you'll see it shows up there from time to time (14762, 23570).
They even has a test case for this issue which surprisingly fails. You can try it here: https://bug-14762-attachments.webkit.org/attachment.cgi?id=15679
margin-top: -50%; will do the trick.
I know its too late but here is the replacement of top: -50% to transform: translateY(-50%);

Position fixed element within fixed element relative to page

I've got a fixed container which is vertically and horizontally centred on the page, and an element within that container. Ideally I would like to have this element positioned in the very top left of the window, however I'm struggling to make it work.
This JS Bin illustrates the problem.
https://jsbin.com/nodonatifo/edit?html,css,output
Initially I thought I would just be able to do something like this on the element.
#container {
width: 300px;
height: 400px;
background-color: #55ffdd;
/* Center on page */
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#element-actual {
background-color: red;
width: 100px;
height: 100px;
position: fixed;
top: 0px;
left: 0px;
}
<div id="container">
<div id="element-actual"></div>
</div>
However that just fixes the element in the top left corner of the parent container, rather than the window.
Is this possible with my current styles?
#container {
width: 300px;
height: 400px;
position: fixed;
top: 50%;
left: 50%;
background-color: #55ffdd;
margin-top: -200px;
margin-left: -150px;
}
If you use translate property then its children div will place relatively to the parent div only even when it is position:fixed so you can use the above code to place #container in center and you red div will be placed relatively to the window not the parent div :)
As Gaurav Aggarwal already pointed out, the fixed element will still be relative to the parent's transformed positioning. If you want the container element to be dynamically positioned (even if it has unknown dimensions), then you could use the following approach and avoid using transform: translate(-50%, -50%) for vertical/horizontal centering.
This method essentially positions the container element to fill the height/width of the window element with top: 0/right: 0/bottom: 0/left: 0, and then centers it vertically/horizontally using margin: auto.
Example Here
#container {
width: 300px;
height: 400px;
position: fixed;
top: 0; right: 0;
bottom: 0; left: 0;
margin: auto;
background-color: #55ffdd;
}
#element-actual {
background-color: red;
width: 100px;
height: 100px;
position: fixed;
top: 0;
left: 0;
}
<div id="container">
<div id="element-actual"></div>
</div>
Easy, add this to the child:
position: sticky;

Last element breaking all siblings in absolute positions

I have a container div which has 5 images, all absolutely positioned. I've added the top and left values for all of them but as soon as you define the last element as absolutely positioned, all other images lose their positions and stact at the top.
The container is relatively positioned
.responsive-container{
position: relative;
}
And it has the images inside
<img src="img/responsive-mac.png" id="res-mac">
<img src="img/responsive-laptop.png" id="res-lap">
<img src="img/responsive-tab.png" id="res-tab">
<img src="img/responsive-phone-portrait.png" id="res-ph-1">
<img src="img/responsive-phone-landscape.png" id="res-ph-2">
With following Css applied
.responsive-container{
position: relative;
}
#res-mac{
position: absolute; width: 97%; top: 0%;
}
#res-lap{
position: absolute; width: 85%; top: 232%; left: 30%;
}
#res-tab{
position: absolute; width: 35%; top: 414%; left: 7%;
}
#res-ph-1{
position: absolute; width: 20%; top: 573%; left: 36%;
}
#res-ph-2{
position: absolute; width: 25%; top: 26%; left: 28%;
}
In the demo here, you can just remove the position: absolute; from the 5th image and others would start working. It's not that particular image which is the problem, if you remove the 5th image completely, the 4th image will start doing the same thing.
I've tried removing all css and javascript to narrow down the cause but it;s still not working. What gives?
Try this:
.responsive-container { height: 66px; }

How to set a fixed position of my elements in my case

I am trying to set elements stay on the edge of left and right hand side of the screen no matter what device or screen size is.
I am using bootstrap and have something like
<a href='#' id='prev' class='btn btn-primary'>left button</a>
<a href='#' id='next' class='btn btn-primary'>right button</a>
My css is like
#prev{
position: fixed;
top: 50%;
left: 0%;
}
#next{
position: fixed;
top: 50%;
left: 95%;
}
I want something like
left button(edge of screen) right button(edge of screen)
Left button seems fine but my problem is right button.
My css only works for certain screen size but not all. Can someone help me to solve this issue? Thanks a lot!
Try setting the right property:
#prev{
position: fixed;
top: 50%;
left: 0;
}
#next{
position: fixed;
top: 50%;
right: 0;
}
JS Fiddle: http://jsfiddle.net/6gw3K/
Use right: 0 for #next
#prev{
position: fixed;
top: 50%;
left: 0;
}
#next{
position: fixed;
top: 50%;
right: 0;
}
Assuming that position fixed is not a hard requirement, you might look into using floating. E.g.:
#pref{ float:left; }
#next{ float: right; }
See this jsfiddle.