Hello this is my first attemp at creating a website and all this different languages seems a little overwhelming. I have some experience with programming guis and I have to say that the geometry manager of css seems incredibly weird to me.
Anyways my objective page is:
- To display images in an ordered way, the images are svg.
- To be able to reorganize the grid of images to make them bigger or smaller.
- To put the images in an array that way editing the page will be easier.
- To be able to put a link in an area of each image.
So far Ive accomplished all the points except the last one, I dont know how to put a clickable link in an area of each image.
Ive seen that I could use an area tag using a map but as far as I know the coordinates need to be absoulte values and cant be relative to the image, meaning that when the image changes size the area will be wrong.
I have also tried puting the link in the element of the svg file that I want directly, but doesnt work in the html file for some reason.
Any suggestions?
Here's what I have so far:
// Create images
var images_names = ["Images/article_0.svg", "Images/article_1.svg", "Images/article_2.svg", "Images/article_3.svg", "Images/article_4.svg",
"Images/article_5.svg", "Images/article_6.svg", "Images/article_7.svg", "Images/article_8.svg"
]
var i;
for (i = 0; i < images_names.length; i++) {
var img = document.createElement('img');
img.src = images_names[i];
document.getElementById('container').appendChild(img);
}
// Create Maps
// Geometry functions
function two() {
var i;
var elements = document.getElementsByTagName("img");
for (i = 0; i < elements.length; i++) {
elements[i].style.width = "49%"; // IE10
}
}
function four() {
var i;
var elements = document.getElementsByTagName("img");
for (i = 0; i < elements.length; i++) {
elements[i].style.width = "24%"; // IE10
}
}
function eight() {
var i;
var elements = document.getElementsByTagName("img");
for (i = 0; i < elements.length; i++) {
elements[i].style.width = "12%"; // IE10
}
}
function sixteen() {
var i;
var elements = document.getElementsByTagName("img");
for (i = 0; i < elements.length; i++) {
elements[i].style.width = "6%"; // IE10
}
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
img {
width: 24%;
top: 0;
}
.header {
text-align: center;
padding: 32px;
position: sticky;
top: 0;
background-color: white;
}
#container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;
align-content: space-between;
}
<!-- Header -->
<div class="header">
<h1>TITLE</h1>
<p>Click on the buttons to change the grid view.</p>
<button onclick="two()">2</button>
<button onclick="four()">4</button>
<button onclick="eight()">8</button>
<button onclick="sixteen()">16</button>
</div>
<div id="container">
</div>