click target area overlapping over targets - javascript

I have 4 simple img and h4 which are targeted to 3rd party links. The class projectImage2 overlaps the other 3 and much of the page is targeted to the click
<a href="https://eliottenos.github.io/eliott-game/"<div class="game"<h4>Game Application</h4></div></a>
<a href="https://github.com/eliottenos/filebucket-client"><img class="projectImage2"src="http://i.imgur.com/iiGiuX7.png"
title="FileBucket Application" /></a>
<a href="https://eliottenos.github.io/filebucket-client/"><div
class="fileBucket"><h4>FileBucket Application</h4></div></a>
<a href="https://github.com/eliottenos/eliott-game"><img
class="projectImage1"src="http://i.imgur.com/iiGiuX7.png" title="Game
Application" /></a>
The only thing I can that think that could be throwing it off is the CSS?
.game {
position: absolute;
padding-left: 250px;
padding-right: 250px;
padding-top: 130px;
}
.fileBucket {
position: absolute;
padding-left: 250px;
padding-right: 250px;
padding-top: 200px;
}
.projectImage2 {
height: auto;
width: auto;
top: 450px;
left: 440px;
max-width: 100px;
max-height: 70px;
position: absolute;
display: inline;
}
.projectImage1 {
height: auto;
width: auto;
top: 380px;
left: 440px;
max-width: 100px;
max-height: 70px;
position: absolute;
display: inline;
}

So i had a proper look, the problem is not only the links but how your html is structured, there's position:absolute on pretty much everything, so everything is overlapping everything, i would strongly suggest you to use bootstrap template as a start, you can easily set columns and rows with bootstrap and it will be responsive. i tried to put the links in the correct position, but because you have position:absolute on everything, i would have to change how the html is laid out, for example some of the things which is below another part in html pops up on top of that content.
You have to think your html as horizontal rows, doesn't matter if they are left or right, if they appear on the same line, put it under one div.
For example, for your content with bootstrap, you could do something like this:
<div class="row">
<div class="col-md-4">
Contact Details, Phone Number etc...
</div>
<div class="col-md-8">
<p>
Fullstack Web Developer coming from a diverse, technical business background. Having worked and traveled the world, I have acquired a breadth of skill sets through different industries which has culminated in my goal of becoming a trained fullstack web developer.
</p>
<ul class="main">
<li>Write HTML, CSS, and JavaScript for displays in contemporary browsers with responsive design practices</li>
<li>Develop back-end web applications and APIs using a modern programming languages and MVC web development framework</li>
<li>Collaborate with teams using an agile development workflow and widely-accepted collaboration practices using Git and GitHub for version control</li>
<li>Improve and demonstrate web development skill-set by building a series of full-stack web applications</li>
</ul>
</div>
</div>
Where the left side takes up 4 columns and right side takes 8 columns and the total column width always adds up to 12. So you can do something like this as well.
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
<div class="col-md-1"></div>
</div>

Related

How do you horizontally center an element with "position: absolute"?

Okay..... So here is a list of things to know:
First, I am using fabric.js (I didn't include it in the tags because it's not the central focus of the problem), which means that when I create a new instance of a fabric.js canvas, it creates 2 canvas elements (.lower-canvas) and (.upper-canvas), which by interacting with it, I've come to find out that they are absolutely positioned, so long story short (with a huge run on) I can't change the fact there are 2 canvases and I can't change to a different library.
Second, I am using bootstrap to keep the UI looking slick. Right now it's structure looks like
<div class="row">
<div class="col" id="canvas_container">
<canvas id="canvas">
</canvas>
</div>
</div>
<div class="row">
<div class="col">
<br>
</div>
</div>
<div class="row">
<div class="col">
---some buttons---
</div>
</div>
So when the page is generated, it changes from the previous code block to
<div class="row">
<div class="col" id="canvas_container">
<div class="canvas-container">
<canvas id="canvas" class="lower-canvas">
</canvas>
<canvas class="upper-canvas">
</canvas>
</div>
</div>
</div>
<div class="row">
<div class="col">
<br>
</div>
</div>
<div class="row">
<div class="col">
---some buttons---
</div>
</div>
which changes the previous canvas to 2 different canvases with different classes but keeps the id of the initial canvas on one of the canvases, and creates a div with class "canvas-container" to encapsulate both canvases.
Third, the canvases will have dynamic sizes. The user will select which size canvas they want to use to interact with the fabric canvas.
Fourth, I have looked at various links on stackoverflow to try, and some have come really close, but still no cigar. The one I am thinking of specifically is here if you'd like to check it out.
Fifth, there shouldn't be any additional css affecting any of the elements apart from bootstrap - with the exception of the canvas elements to affect their size (measured currently in % but may change to vw or vh).
---The Problem Statement---
Just to restate the problem, I am trying to center both canvases that have absolute positions. I think this might be best accomplished if I can center just the .canvas-container, since both canvases are encapsulated in it and since they have absolute positioning. Any thoughts on this?
Let me know if there is anything else I can do to clear up anything I may not have touched on.
Thank you in advance.
--edit--
Just to give a little more context, the light blue boxes will always be the canvas element that needs to be centered.
Here is an update regarding one of the proposed solutions from #SoluableNonagon (it is the post that has a parent and 3 children that are vertically, horizontally, and "both" aligned), so you can see what is going on... for reference, the gray bar at the bottom is horizontally aligned.
The green box is the #canvas_container element which shares the class col.
The light blue box is made up of both canvases.
Moving the css "up" on level to where the child becomes the parent and the new parent's contents becomes the child results in this
#Gagandeep Sangh 's solution without making proper changes to affect the one specific element.
After making the changes to affect the 1 element, the result is like so
Generally, when an element is position: absolute the parent is position: relative.
Then, the absolute element is left: 50%; transform: translateX(-50%); for horizontal centering. For vertical centering top: 50%; transform: translateY(-50%);
.parent {
position: relative;
height: 200px; // needs height/width cause 'absolute' child takes no space
width: 200px;
border: 1px solid red;
}
.child-1 {
position: absolute;
height: 50px;
width: 50px;
border: 1px solid blue;
left: 50%;
transform: translateX(-50%);
}
.child-2 {
position: absolute;
height: 50px;
width: 50px;
border: 1px solid orange;
top: 50%;
transform: translateY(-50%);
}
.child-3 {
position: absolute;
height: 50px;
width: 50px;
border: 1px solid green;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class='parent'>
<div class='child-1'>horizontal</div>
<div class='child-2'>vertical</div>
<div class='child-3'>both</div>
<div>
The <div class="canvas-container"> can be centered respective to its parent <div class="col"> using position:absolute; and setting the col div to position:relative; but here comes a new issue that after setting the <div class="canvas-container"> as absolute it will flow out of its parent div and the height of parent div will collapse as it doesn't have any other content in it, than you need to add some height to that div also, so basically you can try this
.col{
min-height:500px;
position:relative;
}
.canvas-container{
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
}
Hope it works.

Displaying <div> in between two elements of a separate hierarchy

Consider the following HTML:
<div style="background-color: blue">
<div style="color: red">
some content some content some content some content
</div>
</div>
<div id="highlight" style="top: 0px; width: 200px; height: 40px;
background-color: yellow; position: fixed">
</div>
on jsfiddle
It looks like this:
What I want to do is to visually put the #highlight <div> between the blue background and the text. Here's what I want it to look like:
I am using this weird <div> hierarchy as in my real-life scenario I'm using JQuery to move #highlight with some mouse/keyboard events. I also have no control over the hierarchy of the <div>s containing the text.
I need #highlight's position to either be fixed or absolute.
Is there any way I can achieve my current result without changing the HTML structure? I've attempted using z-index, but it doesn't work as the hierarchy structure has priority over it. I am open to any kind of dirty hack involving JavaScript/JQuery.
On the content div, set z-index:1 and position:relative.
<div style="background-color: blue;">
<div style="color: red; z-index: 1;position:relative;">
some content some content some content some content
</div>
</div>
<div id="highlight" style="top: 0px; width: 200px; height: 40px; background-color: yellow; position: fixed;">
</div>

jQuery jScrollPane only works with text

I am trying to use jScrollPane to scroll through my gallery that is inside of an iframe. I am using the jQuery code for iframe scrolling from the official example.
Using this code doesn't work for my images (it just hides the original browser scrollbars, doesn't throw any errors and refuses to scroll), but it works perfectly if I replace my images with multiple paragraphs so they overflow (just like in the example).
EDIT: I forgot to mention that images scroll perfectly using the default browser scrollbar.
EDIT #2: Made a JSFiddle.
Here's how my gallery is structured:
...
</head>
<body>
<div id="content"> // Used the same way as in the example, works with text
<div class="gallery">
<div class='picture'>
<img class='pin' src='something'/>
<div class='wrapper'>
<img class='thumbnail' src='something'/>
<img class='border' src='something' />
</div>
</div>
<div class='picture'>
...
</div>
</div>
</div>
...
And here's the CSS for gallery and pictures:
.gallery {
position: relative;
width: 98%;
}
.picture {
float: left;
position: relative;
display: list-item;
list-style-type: none;
width: 11%;
}
.picture .pin {
position: absolute;
left: 48%;
width: 13%;
}
.picture .thumbnail {
position: absolute;
width: 89%;
margin-top: 19%;
}
.picture .border {
position: absolute;
width: 100%;
}
I ignored margins and some other irrelevant stuff, but you get the idea.
The jQuery code is exactly the same as presented in the example.
I think the problem is that images are loaded after scrollbar is initialized, and scrollbar does not detect container size changes by default. If you read documentation carefully, you can see next:
Demo showing how autoReinitialise can also be used so that content
with images in it displays correctly in jScrollPane
So, try autoReinitialise option. If it won't help - update your question with example of your iframe on jsFiddle.net
Solved it!
Apparently, the script didn't like the absolute position of my .picture .pin. Changing it to relative and restyling a bit solved my issue.
Updated JSFiddle

How to have Side-By-Side Divs with one taking remaining space?

My problem is I would like a set of side by side divs. These divs can grow to an arbitrary height so vertical aligning is important. As suggested by another SO post, in order to tackle the vertical align problem I have a structure similar to this. Please help me fill in the blanks.
<div id="main-container">
<div class="formatter">
<div class="content1">
<!--- I am fixed at 200px ---->
</div>
</div>
<div class="formatter">
<div class="content2">
<!--- I have a rendered element. I don't know exactly how high or wide I am, but I'm not going to take up the whole thing. --->
</div>
</div>
<div class="formatter">
<div class="content3">
<!--- I have some text and just want to take up the rest of the main container less padding and borders ----->
</div>
</div>
</div>
Display within the browser:
CSS:
#main-container {
width: 900px;
}
.formatter {
display: inline-block;
vertical-align: middle;
}
.content1 {
float: left;
width: 200px;
}
You need to declare them as table-cell.
Lets try an unorthodox approach
Auto width and vertical alignment becomes very easy using CSS flex display
Code to get your basic layout, vertical and horizontal alignment (withour padding or borders or text-alignment)
<div id="main-container">
<div class="content1">a
<!--- I am fixed at 200px ---->
</div>
<div class="content2">bbb
<!--- I have a rendered element. I don't know exactly how high or wide I am, but I'm not going to take up the whole thing. --->
</div>
<div class="content3">c
<!--- I have some text and just want to take up the rest of the main container less padding and borders ----->
</div>
</div>
#main-container {
width: 900px;
display: flex;
}
.content3 {
flex-grow: 1;
}
.content1 {
width: 200px;
}
Fiddle - http://jsfiddle.net/n3CwB/
Now you may want to retain your original HTML structure if you want more control of the alignment of the content (like vertically align middle the content), but this should get you started with the basic layout.

Floating repeated divs, how to keep XY together

I am currently creating many figures using the JavaScript library D3 (but I don't think D3 has any relevance for my problem). The figure is placed in div X and the text explaining the figure is in div Y. I basically want to create a pattern like this:
XYXYXY
XYXYXY
but instead (depending on how wide my window since I do not want to fix the width), what I get this:
XYXYX
YXYXY
I tried putting XY in a parent div Z<XY>, so that every pair of XY stays together, but that does not work. I also don't think clearing is necessarily the answer here, but I have tried all combinations without success.
Any help is greatly appreciated.
Try
white-space: nowrap
You may also have to change the floats to for your XY divs:
display: inline-block
If I understood the problem correctly, you don't need to use float. Display the divs as inline blocks: display: inline-block.
That will flow the divs as "character blocks" doing the wrap, you'll need to have a parent for the XY to keep the text together with the image.
An example: http://jsfiddle.net/D9BAv/
HTML:
<div class="figure">
<div class="picture"></div>
<div class="text">Example 1</div>
</div><!-- reapeated ... -->
CSS:
.figure {
display: inline-block;
}
.picture {
width: 3rem;
height: 3rem;
margin:auto;
background-color: blue;
}
If I have understood you correctly, maybe this will work. You could also use display: inline-block instead of float: left if you don't need to support IE8 and below.
http://jsfiddle.net/GQ8Uw/
HTML
<div class="cont">
<div class="x">X</div><div class="y">Y</div>
</div><div class="cont">
<div class="x">X</div><div class="y">Y</div>
</div><div class="cont">
<div class="x">X</div><div class="y">Y</div>
</div><div class="cont">
<div class="x">X</div><div class="y">Y</div>
</div><div class="cont">
<div class="x">X</div><div class="y">Y</div>
</div>
<div class="cont">
<div class="x">X</div><div class="y">Y</div>
</div>
CSS
.cont {
width: 100px;
float: left;
}
.x, .y {
width: 50%;
float: left;
}
.x {
background: #ccc;
}
.y {
background: #ecc;
}
Ok, I solved the problem. So I was wrong, it did have something to do with D3. Each time, I was essentially adding a child div to the same parent, and therefore the inline-block simply had no effect.
I ended up adding a "last-child" feature in my code like "d3.select(".figure:last-child").append(...", for both the picture and the text, and it works perfectly.
I saw the problem by adding a border around the parent div, and I noticed that all children were in the same div. I then found the solution from: What is the equivalent of jQuery's $(".cell:first") in D3?

Categories