1 Koji selector u CSS-u bira sve elemente /<p>/na stranici? b. p 2. Izaberite jedan odgovor: a. .nazivKlase b. @nazivKlase c. %nazivKlase d. #nazivKlase 3. Koja od sledećih vrednosti ne postoji za /position/svojstvo? a. relative b. absolute c. centered d. fixed 4. Izaberite jedan odgovor: a. position: absolute; b. float: left; c. display: inline; d. display: block; 5. Kako da selektujemo sve /<div>/elemente sa klasom box? d. div.box 6. Izaberite jedan odgovor: a. Povećava font b. Postavlja element iznad ili ispod drugih c. Menja poziciju elementa d. Rotira element 7. Koja je razlika između em i rem jedinica u CSS-u? a. rem je relativan na root, em na roditelja 8. Izaberite jedan odgovor: a. <script src="stil.css"> b. <link rel="stylesheet" href="stil.css"> Tačno c. <css src="stil.css"> d. <style href="stil.css"> 9. Izaberite jedan odgovor: a. align-content b. text-align c. justify-content d. align-items
for (const kljuc in korisnik.adresa) { console.log(`kljuc:${kljuc}, vrednost: ${korisnik.adresa[kljuc]}`); }
//vezba //napravite objekat, sa ugnjezdenim objektom, metodu po zelji, proci kroz objekat i ispisati parove kljuc: vrednost let osoba = { ime: "David", prezime: "Milenkovic", godine: 21, horoskop: { znak: "Bik", podznak: "Rak", mesec: "Rak", }, predstaviSe: function () { console.log( "Ja sam " + this.ime + " " + this.prezime + " i imam " + this.godine + " i znak mi je " + this.horoskop.znak ); }, };
for (const key in osoba) { // console.log(`${key}: ${osoba[key]}`); if (typeof osoba[key] === "object") { for (const innerKey in osoba[key]) { if (innerKey === "podznak") { continue; } console.log(innerKey); } } }
for (const key in osoba.horoskop) { console.log(key); } //vezba //napraviti objekat porodica //otac , majka, 2 deteta //ime, prezime, godine //treba da ispisete imena svih clanova //izracunate prosecnu starost porodice
for (const kljuc in korisnik.adresa) { console.log(`kljuc:${kljuc}, vrednost: ${korisnik.adresa[kljuc]}`); }
//vezba //napravite objekat, sa ugnjezdenim objektom, metodu po zelji, proci kroz objekat i ispisati parove kljuc: vrednost let osoba = { ime: "David", prezime: "Milenkovic", godine: 21, horoskop: { znak: "Bik", podznak: "Rak", mesec: "Rak", }, predstaviSe: function () { console.log( "Ja sam " + this.ime + " " + this.prezime + " i imam " + this.godine + " i znak mi je " + this.horoskop.znak ); }, };
for (const key in osoba) { // console.log(`${key}: ${osoba[key]}`); if (typeof osoba[key] === "object") { for (const innerKey in osoba[key]) { if (innerKey === "podznak") { continue; } console.log(innerKey); } } }
for (const key in osoba.horoskop) { console.log(key); } //vezba //napraviti objekat porodica //otac , majka, 2 deteta //ime, prezime, godine //treba da ispisete imena svih clanova //izracunate prosecnu starost porodice
// const newNum = num.map((el, i, arr) => { // // console.log(`element ${el} - pozicija ${i}, u nizu ${arr}`);
// });
const newNum = num.map((el) => el * 2);
console.log(newNum);
//filter() //vraca novi niz //duzina novog niza bice ili ista ili manja od orginalnog niza //koristimo kada zelimo da izbacimo elemente koji ne zadovoljavaju uslov
//sintaksa
// array.filter((element, index, arr) => { // //vraca elemente koji "prolaze uslov" // });
function ispisiSlova(a, b, c, d) { console.log(a, b, c, d); } const name = "Maja";
ispisiSlova(...name);
//Ii primer
// function makePizza(ing1, ing2, ing3) { // return `Pizza made with ${ing1}, ${ing2}, and ${ing3}`; // } // const ingredians = [ // prompt("Unesite prvi sastojak za pizzu"), // prompt("Unesite drugi sastojak za pizzu"), // prompt("Unesite treci sastojak za pizzu"), // ];
// const pizza = makePizza(...ingredians);
// console.log(pizza);
//Vezba //izracunati zbir svih vrednosti iz oba niza //koristeci metode
//sortiranje po rastucem poretku const sortiraniNizRastuci = [...brojeviSet].sort((a, b) => a - b); console.log(sortiraniNizRastuci);
//sortiranje po opadajem poretku const sortiraniNizOpadajuci = [...brojeviSet].sort((a, b) => b - a); console.log(sortiraniNizOpadajuci);
//sort() metoda //a-b >0 => a ide ispred b //a-b<0 => b ide ispred a //a -b=0 => ostaju na istom mestu
// vezba
//napravite niz brojeva //poredjajte brojeve po opadajucem poretku, ali tako da brojevi budu jedninstveni
//vezba2 const slova = "Hello world";
//treba da se poredjaju slova unazad, da imamo samo jedinstvene vrednosti // const slova = "Hello world"; const setLetters = new Set(slova); const sortedLetters = [...setLetters].reverse(); console.log(sortedLetters);
//sortiranje slova const sorted = [...slova].sort((a, b) => b - a); console.log(sorted);
why my div container won't be on center but its on left - ai
Quote from: ai
need html and css done, 3 country flag images to be set sticky horizontaly on center of the screen, image size should be equal to width which will be adjusted when i add my images, on click on the flag it should display name of country and redirect to additional page which i will add later. around flags i want to add image which will fly around flags
This solution uses HTML, CSS, and a small amount of JavaScript to achieve all the specified requirements. It includes three flags centered horizontally, made "sticky" to a certain position, and an image that flies around them.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Country Flags</title> <style> /* General body styling for context */ body { height: 200vh; /* Adds scroll to test sticky position */ margin: 0; display: flex; justify-content: center; align-items: flex-start; /* Aligns to the top initially, sticky handles the rest */ padding-top: 100px; /* Space from the top */ background-color: #f0f0f0; }
/* Container for the flags, positioned sticky */ .flag-container { display: flex; justify-content: center; /* Sticky positioning: stick at 20px from the top of the viewport */ position: sticky; top: 20px; z-index: 10; background: white; /* Optional: adds a background to the sticky container */ padding: 10px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
/* Styling for individual flag wrappers (including the name on click) */ .flag-wrapper { position: relative; /* Needed for positioning the name popup */ cursor: pointer; margin: 0 10px; /* Space between flags */ width: 150px; /* Default width for flags, adjust as needed */ height: auto; }
.flag-wrapper img { width: 100%; /* Image width is equal to the wrapper width */ height: auto; display: block; }
/* Styling for the country name display */ .country-name { display: none; /* Hidden by default, shown via JavaScript */ position: absolute; bottom: 100%; /* Position above the flag */ left: 50%; transform: translateX(-50%); background-color: #333; color: white; padding: 5px 10px; border-radius: 4px; white-space: nowrap; margin-bottom: 5px; }
/* --- Flying Image Animation --- */ .flying-image { position: absolute; width: 50px; /* Size of the flying image */ height: 50px; animation: orbit 5s linear infinite; /* Animation name, duration, timing, repeat */ z-index: 5; /* Positioning relative to the body or main container, adjust 'top' and 'left' values to center the orbit path around the flag group */ top: 100px; left: 50%; transform-origin: 0 0; /* Center of rotation is not the image itself, but the center of the orbit */ }
@keyframes orbit { 0% { transform: rotate(0deg) translate(-200px) rotate(0deg); /* Orbits at a radius of 200px */ } 100% { transform: rotate(360deg) translate(-200px) rotate(-360deg); } } </style> </head> <body>
<div class="flag-container"> <!-- Flying image element --> <img src="https://picsum.photos/id/237/50/50" alt="Flying image" class="flying-image"> <!-- Placeholder for the flying image -->
<script> function handleFlagClick(countryName, redirectPage) { // Display the country name temporarily (optional as we are redirecting immediately) console.log("Clicked on: " + countryName);
// Redirect to the additional page window.location.href = redirectPage; }
// Optional: you could modify the JS to show the name on hover or something else if the redirect wasn't immediate. </script>
</body> </html>
Spoiler for Hiden:
Key Features and How They Are Met:
Sticky and Horizontally Centered: The .flag-container uses position: sticky; top: 20px; to stay at the top of the viewport when scrolling, and display: flex; justify-content: center; to center the flags horizontally. Equal Image Size: The .flag-wrapper has a defined width (150px here, which you can adjust), and the images inside use width: 100% to match that size. Click Action (Display Name & Redirect): The onclick event in the HTML calls a JavaScript function handleFlagClick(). This function handles the redirect using window.location.href. The display name part is set up but commented out/minimal, as the redirect happens instantly. Flying Image: A separate <img> with the class .flying-image is absolutely positioned and uses a @keyframes orbit CSS animation to move in a circle around the flags. The transform: rotate(...) translate(...) rotate(...) ensures the image itself doesn't spin wildly, but moves in a circular path. You might need to adjust the top and left properties of .flying-image to align the orbit center perfectly with the center of your flags once you have your final images.
//primer arrow function ///return se izvrsava implicitno const sayHi = () => `Hi!`;
console.log(sayHi());
//Primer
const add = (a, b) => { const zbir = a + b; return zbir; };
//Vezba //napisati arrow funkciju koja ce u zavisnosti od godine rodjenja vratiti koliko je godina ostalo do penzije //u penziju se ide sa 65 godina const calcAge4 = (now, yearOfBirth) => { const brojGodinaOsobe = now - yearOfBirth; const brojGodinaDoPenzije = 65 - brojGodinaOsobe; return brojGodinaDoPenzije; }; const rezultat = calcAge4(2025, 1988); console.log(rezultat);
//Vezba 2 //arrow funkcijom napisati program koji ce faktorijel nekog broja !5=1*2*3*4*5 const faktorijel = (n) => { if (n < 0) { return `Faktorijel nije definisan za negativne brojeve.`; } let rezultat = 1; for (let i = n; i > 0; i--) { rezultat *= i; } return rezultat; }; const rez = faktorijel(5); const rez1 = faktorijel(10); console.log(rez); console.log(rez1);
"use strict";
// FUNKCIJE NASTAVAK OD PRETHODNOG DANA
const result = calcAge(2025, 2000); console.log(result);
//primer arrow function ///return se izvrsava implicitno const sayHi = () => `Hi!`;
console.log(sayHi());
//Primer
const add = (a, b) => { const zbir = a + b; return zbir; };
//Vezba //napisati arrow funkciju koja ce u zavisnosti od godine rodjenja vratiti koliko je godina ostalo do penzije //u penziju se ide sa 65 godina const calcAge4 = (now, yearOfBirth) => { const brojGodinaOsobe = now - yearOfBirth; const brojGodinaDoPenzije = 65 - brojGodinaOsobe; return brojGodinaDoPenzije; }; const rezultat = calcAge4(2025, 1988); console.log(rezultat);
//Vezba 2 //arrow funkcijom napisati program koji ce faktorijel nekog broja !5=1*2*3*4*5 const faktorijel = (n) => { if (n < 0) { return `Faktorijel nije definisan za negativne brojeve.`; } let rezultat = 1; for (let i = n; i > 0; i--) { rezultat *= i; } return rezultat; }; const rez = faktorijel(5); const rez1 = faktorijel(10); console.log(rez); console.log(rez1);
Domaci-objekti Zahtevi: Prikaz podataka o knjigama: Napišite metodu koja vraća niz naslova svih knjiga dostupnih u biblioteci. Filtriranje dostupnih knjiga: Napišite metodu koja vraća sve knjige koje imaju više od 3 primerka dostupnih u biblioteci. Provera statusa članstva: Napišite metodu koja proverava da li je određeni član biblioteke sa zadatim memberId još uvek aktivan. Dodavanje nove knjige: Napišite metodu koja dodaje novu knjigu u biblioteku. Metoda treba da prihvati parametre za bookId, title, author, genres, i copies. Nakon dodavanja knjige, metoda treba da ažurira objekat library. Ažuriranje broja primeraka: Napišite metodu koja ažurira broj primeraka knjige sa zadatim bookId. Ako knjiga već postoji u biblioteci, funkcija treba da poveća broj primeraka za zadatu vrednost. Ako knjiga ne postoji, funkcija treba da vrati poruku da knjiga nije pronađena. Transformacija podataka o članovima: Napišite metodu koja kreira novi niz objekata sa podacima o članovima, ali samo sa memberId i name poljima. Ukupno primeraka knjiga: Napišite metodu koja vraća ukupan broj primeraka svih knjiga u biblioteci. Prikaz aktivnih članova: Napišite metodu koja vraća niz imena svih članova čije je članstvo aktivno. Proveravanje knjiga koje nisu vraćene: Napišite metodu koja vraća niz naslova knjiga koje nisu vraćene u biblioteku. Kreiranje novog objekta sa određenim podacima: Napišite metodu koja vraća novi objekat sa informacijama o biblioteci, ali samo sa podacima o name, location, i broju članova sa aktivnim članstvom. Dodatni zahtevi (nisu obavezni): Loš način korišćenja metoda: Metode koje imaju parametre dodatno proširite logikom u slučaju lošeg prosleđivanja argumenta ili izostanka istog. Nedostatak podataka: Ukoliko zahtevamo neki podatak koji ne postoji, nemojte samo da vratite praznu listu, objekat ili slično. U nastavku je objekat sa kojim cete raditi. const library = { name: "Central City Library", location: { street: "Library Avenue 5", city: "Metropolis", state: "NY", postalCode: "10001", }, books: [ { bookId: "B001", title: "JavaScript: The Good Parts", author: "Douglas Crockford", genres: ["Programming", "Technology"], copies: 5, borrowed: [ { memberId: "M001", date: "2023-07-14", returned: false }, { memberId: "M002", date: "2023-07-20", returned: true }, ], }, { bookId: "B002", title: "Clean Code", author: "Robert C. Martin", genres: ["Programming", "Best Practices"], copies: 3, borrowed: [{ memberId: "M003", date: "2023-08-01", returned: true }], }, { bookId: "B003", title: "The Pragmatic Programmer", author: "Andrew Hunt", genres: ["Programming", "Development"], copies: 4, borrowed: [], }, ], members: [ { memberId: "M001", name: "John Doe", email: "john.doe@example.com", membershipActive: true, }, { memberId: "M002", name: "Jane Smith", email: "jane.smith@example.com", membershipActive: false, }, { memberId: "M003", name: "Emily Johnson", email: "emily.johnson@example.com", membershipActive: true, }, ],
<section id="projects" class="sec projectSec"> <h2>Projects</h2> <article class="default-article"> <h2>Project 1</h2> <p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Nam doloribus tempore eius cupiditate, atque quos nostrum eligendi unde saepe, itaque commodi hic iste laboriosam est provident ut voluptates, voluptatem necessitatibus! </p> </article>
<article class="default-article"> <h2>Project 2</h2> <p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsa tenetur sint ab nobis nesciunt quae neque, necessitatibus omnis quod animi. Earum molestias eos mollitia beatae fuga dolorem, totam voluptatem? Deserunt. </p> </article> </section> <button class="addProject">Add project</button> <button class="deleteProject">Delete project</button>
//DOM -document Object Model //DOM API- metode i propertiji koji nam omogucavaju da radimo sa DOM-om
console.log(document);
//"Dohvatanje " elemenata DOM-a
I nacin const sectionAbout = document.getElementById("about"); console.log(sectionAbout); ------
//null vrednost dobijamo kada ne mozemo da pronadjemo element const unknownElement = document.getElementById("xxx"); console.log(unknownElement); //null ------
// HTML Collection je nesto slicno nizovima const sectionProjects = document.getElementsByClassName("projectSec")[0]; console.log(sectionProjects); //HTMLCollection ------
//II primer Ako u html dodamo 2 klase koje imaju pre imena sec (sec ProjectSec), dobijamo u HTML Collection sve koje imaju sec i [0] za prvi, [1] za drugi, ili bez ovog u zagradama za sve const sections = document.getElementsByClassName("sec"); console.log(sections); ------
// HTML collection za header element const headerElement = document.getElementsByTagName("header"); //HTMLCollection console.log(headerElement); ------
// Dobija se NODE LIST kada logujemo prazno, mora da se stavi [0] da bi se uhvatio element const inputEl = document.getElementsByName("email"); console.log(inputEl); // NodeList
//Da li postoji vise elemenata if (inputEl.length > 0) { }
if (sectionAbout !== null) { // da li je section postoji } -------
// Da bismo pristupili DOM-u uvek mora = document. // daje nam h1 element const h1Element = document.querySelector("header > h1"); console.log(h1Element); ------
// header i h1 su sestrinski elementi ispod body const h1Element1 = document.querySelector("body > header > h1"); console.log(h1Element1); ------
// dobijaju se NODE list svih sekcija section i koliko elemenata trenutno ima const allSections = document.querySelectorAll("main > section"); //NodeList console.log(allSections);
// dobija se sekcija projects jer je poslednja sekcija console.log(allSections[allSections.length - 1]);
//DOM -document Object Model //DOM API- metode i propertiji koji nam omogucavaju da radimo sa DOM-om
console.log(document);
//"Dohvatanje " elemenata DOM-a
I nacin const sectionAbout = document.getElementById("about"); console.log(sectionAbout); ------
//null vrednost dobijamo kada ne mozemo da pronadjemo element const unknownElement = document.getElementById("xxx"); console.log(unknownElement); //null ------
// HTML Collection je nesto slicno nizovima const sectionProjects = document.getElementsByClassName("projectSec")[0]; console.log(sectionProjects); //HTMLCollection ------
//II primer Ako u html dodamo 2 klase koje imaju pre imena sec (sec ProjectSec), dobijamo u HTML Collection sve koje imaju sec i [0] za prvi, [1] za drugi, ili bez ovog u zagradama za sve const sections = document.getElementsByClassName("sec"); console.log(sections); ------
// HTML collection za header element const headerElement = document.getElementsByTagName("header"); //HTMLCollection console.log(headerElement); ------
// Dobija se NODE LIST kada logujemo prazno, mora da se stavi [0] da bi se uhvatio element const inputEl = document.getElementsByName("email"); console.log(inputEl); // NodeList
//Da li postoji vise elemenata if (inputEl.length > 0) { }
if (sectionAbout !== null) { // da li je section postoji } -------
// Da bismo pristupili DOM-u uvek mora = document. // daje nam h1 element const h1Element = document.querySelector("header > h1"); console.log(h1Element); ------
// header i h1 su sestrinski elementi ispod body const h1Element1 = document.querySelector("body > header > h1"); console.log(h1Element1); ------
// dobijaju se NODE list svih sekcija section i koliko elemenata trenutno ima const allSections = document.querySelectorAll("main > section"); //NodeList console.log(allSections);
// dobija se sekcija projects jer je poslednja sekcija console.log(allSections[allSections.length - 1]);