Dropdown menu without using a list - html

I'm just playing about with some code and trying to create a dropdown menu without using a list.
I cannot get the dropdown to show and I can't figure out what I'm doing wrong.
I have visibility set to hidden on the dropdown class and the visibility set to visible when on hover but it won't show. If I set the visibility to visible on the dropdown class it shows so it must be something to do with my hover?
* {
margin: 0;
padding: 0;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
display: grid;
margin: 0px;
grid-gap: 0px;
grid-template-columns: 1fr;
grid-template-rows: 70px calc(100vh - 70px);
}
.header {
background: red;
display: grid;
}
.header--container {
width: 1160px;
justify-self: center;
display: grid;
grid-column: 1;
grid-row: 1;
grid-auto-flow: column;
}
.header--container span:first-child {
background: purple;
display: grid;
grid-auto-flow: column;
justify-items: left;
display: grid;
align-items: center;
}
.header--container nav {
background: black;
display: grid;
grid-auto-flow: column;
justify-items: center;
display: grid;
align-items: center;
}
.header--container span:last-child {
background: yellow;
display: grid;
grid-auto-flow: column;
justify-items: right;
display: grid;
align-items: center;
}
.hero {
background: blue;
display: grid;
}
.hero--container {
width: 1160px;
justify-self: center;
background: pink;
}
.site-navigation .menu-item {
color: #fff;
background: #3498db;
display: block;
}
.site-navigation .menu-item a {
color: #fff;
text-decoration: none;
display: block;
}
.site-navigation .menu-item:hover {
background: #52a6df;
cursor: pointer;
}
.dropdown {
background: #52a6df;
visibility: hidden;
position: absolute;
transition: visibility 0.65s ease-in;
z-index: 999;
}
a:hover>.dropdown,
a .dropdown:hover {
visibility: visible;
z-index: 9999;
}
<div class="header">
<div class="header--container">
<span>
<img src="imgs/ID_Logo_Websitesmall.jpg" alt="logo" height="50px">
</span>
<nav id="navigation" class="site-navigation" role="navigation">
News
<a href="#" class="menu-item">Snippets
<div class="dropdown">
CSS
HTML
jQuery
PHP
WordPress
</div>
</a>
Inspiration
Tools
Tutorials
</nav>
<span>
01442 817767
</span>
</div>
</div>
<div class="hero">
<div class="hero--container">cd</div>
</div>

An anchor tag inside another is invalid syntax - you can see while inspecting that the dropdown div is moving out and getting place as the next sibling element. Change the a tags to say span - see demo below:
* {
margin: 0;
padding: 0;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
display: grid;
margin: 0px;
grid-gap: 0px;
grid-template-columns: 1fr;
grid-template-rows: 70px calc(100vh - 70px);
}
.header {
background: red;
display: grid;
}
.header--container {
width: 1160px;
justify-self: center;
display: grid;
grid-column: 1;
grid-row: 1;
grid-auto-flow: column;
}
.header--container span:first-child {
background: purple;
display: grid;
grid-auto-flow: column;
justify-items: left;
display: grid;
align-items: center;
}
.header--container nav {
background: black;
display: grid;
grid-auto-flow: column;
justify-items: center;
display: grid;
align-items: center;
}
.header--container span:last-child {
background: yellow;
display: grid;
grid-auto-flow: column;
justify-items: right;
display: grid;
align-items: center;
}
.hero {
background: blue;
display: grid;
}
.hero--container {
width: 1160px;
justify-self: center;
background: pink;
}
.site-navigation .menu-item {
color: #fff;
background: #3498db;
display: block;
}
.site-navigation .menu-item a {
color: #fff;
text-decoration: none;
display: block;
}
.site-navigation .menu-item:hover {
background: #52a6df;
cursor: pointer;
}
.dropdown {
background: #52a6df;
visibility: hidden;
position: absolute;
transition: visibility 0.65s ease-in;
z-index: 999;
}
a:hover>.dropdown,
a .dropdown:hover {
visibility: visible;
z-index: 9999;
}
<div class="header">
<div class="header--container">
<span><img src="https://via.placeholder.com/100" alt="logo" height="50px"></span>
<nav id="navigation" class="site-navigation" role="navigation">
News
<a href="#" class="menu-item">Snippets
<div class="dropdown">
<span href="#"class="menu-item sub-menu">CSS</span>
<span href="#" class="menu-item sub-menu">HTML</span>
<span href="#" class="menu-item sub-menu">jQuery</span>
<span href="#" class="menu-item sub-menu">PHP</span>
<span href="#" class="menu-item sub-menu">WordPress</span>
</div>
</a>
Inspiration
Tools
Tutorials
</nav>
<span>01442 817767</span>
</div>
</div>
<div class="hero">
<div class="hero--container">cd</div>
</div>

Related

How to align content inside rows of an <article> vertically with each other

I am trying to align content inside rows of an article vertically with each other
This is in the card component
`
<div className="user-card">
<img
className="avatar"
src={`/assets/${user.homeTeam}.png`}
alt={user.homeTeam}
/>
<img
className="avatar"
src={`/assets/${user.awayTeam}.png`}
alt={user.awayTeam}
/>
<div className="info">
<h3>
{user.homeTeam} vs {user.awayTeam}
</h3>
<span style={{ margin: "1em" }}></span>
<img
alt=""
src="/assets/calendar.svg"
style={{ height: "40px", width: "40px" }}
/>
<span style={{ margin: "0.5em" }}></span>
<h3>{user.Date}</h3>
<span style={{ margin: "1em" }}></span>
<img
alt=""
src="/assets/stadium.svg"
style={{ height: "40px", width: "40px" }}
/>
<span style={{ margin: "0.5em" }}></span>
<h3>{user.location} </h3>
<span style={{ margin: "1em" }}></span>
{/* <p>
Score: {user.homeTeamScore} - {user.awayTeamScore}
</p> */}
<button class="button button-green width-auto">Book Ticket</button>
</div>
</div>
`
App.css
`
.App {
text-align: center;
width: 95%;
max-width: 800px;
margin: 6rem auto 0;
}
.user-container {
display: grid;
justify-content: center;
grid-template-columns: 1fr 1fr;
gap: 0.5rem;
}
.card-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 100px 100px;
}
.button.width-auto {
width: 130px;
padding: 0 15px;
max-width: none;
}
.button.button-green {
background-color: #219f45;
}
[role="button"],
[type="button"]:not(:disabled),
[type="reset"]:not(:disabled),
[type="submit"]:not(:disabled),
button:not(:disabled) {
cursor: pointer;
}
.button {
display: block;
text-align: center;
width: 100px;
max-width: 130px;
margin: 0;
height: 45px;
line-height: 45px;
color: #fff !important;
padding: 0;
border: none;
cursor: pointer;
font-size: 14px;
transition: all 0.1s linear;
font-family: EncodeSansExpanded-Bold, arial, tahoma;
}
.user-card {
display: flex;
padding: 1rem;
text-align: left;
margin-left: 1rem;
margin-bottom: 0.5rem;
margin: 0 auto; /* Added */
float: none; /* Added */
margin-bottom: 10px; /* Added */
width: 1200px;
margin: 2em;
border: 1px solid grey;
border-radius: 5px;
cursor: pointer;
transition: all 0.25s ease;
}
.user-card:hover {
background-color: #0a0a0a;
}
.avatar {
display: flex;
width: 50px;
height: 50px;
border-radius: 50%;
}
.info {
align-items: center;
display: flex;
text-align: left;
margin-left: 1rem;
}
.info h3,
.info p {
align-items: center;
margin-bottom: 0.5rem;
}
div {
align-items: center;
justify-content: left;
}
.user-post {
max-width: 500px;
width: 95%;
margin: 0 auto;
}
.user-post h2 {
margin: 1rem auto;
color: white;
}
.user-post a {
cursor: pointer;
text-decoration: none;
}
.user-card__image {
display: flex;
}
.user-post a:hover {
color: #5dd4ac;
}
#media (max-width: 600px) {
.user-container {
grid-template-columns: 1fr;
}
}
`
and I am creating cards from my home file inside an article
I need every element in the card to be aligned on all rows. I tried placing every element in a div with a class that has display: flex and align-content: left, but no hope
Update:
You should first group the elements you want to be together in a div. So the country flags + names together, calendar icon + date and time, stadium icon + stadium name and you can leave the button as it is.
Then you should give .user-card a display: grid; and grid-template-columns: 2fr 2fr 2fr 1fr; (depends on what size you want every grid column to be).

How can I make this square-inside-square structure horizontal?

I'm trying to represent this structure horizontaly, but I'm having some issues on what should I change so that this can work properly. What I hope to achieve is that those small squares in the bottom appear the same, only verticaly, on top of each other, while the bigger square keeps it's model.
.date-grid {
width: 120px;
height: 100px;
display: flex;
flex-direction: column;
}
.node {
width: 100%;
height: 100%;
background: #e9ecef;
border: none;
padding: 0;
}
time {
display: block;
height: 75%;
font-size: 24px;
display: flex;
flex-direction: column;
justify-content: center;
}
.smallHolder {
width: 100%;
height: 25%;
display: flex;
}
.smallHolder>div {
width: 25%;
height: 100%;
flex-shrink: 0;
flex-grow: 1;
}
.next { background: #0060df; }
.last { background: #d53343; }
<div class="date-grid">
<button class="node">
<time>3</time>
<div class="smallHolder">
<div class="next"></div>
<div class="last"></div>
</div>
</button>
</div>
Is this the sort of thing you're looking for? grid is great for this sort of thing.
.date-grid {
height: 100px;
display: grid;
grid-template-columns: 120px 25px;
grid-template-rows: 1fr 1fr;
grid-template-areas: "gray next" "gray last";
padding: 0;
border-style: none;
}
.gray {
grid-area: gray;
display: grid;
place-content: center;
background: #e9ecef;
}
time {
font-size: 24px;
}
.next {
grid-area: next;
background: #0060df;
}
.last {
grid-area: last;
background: #d53343;
}
<button class="node date-grid">
<time class='gray'>3</time>
<div class="next"></div>
<div class="last"></div>
</button>

place a text between two arrows

I want to place a text inline and between two arrows. at first it seems easy but I can't place everything in their right place:
html, body {
height: 100%;
}
body {
background: #fafafc;
margin: 0;
}
.flex-container {
height: 100%;
padding: 0;
margin: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
.grid-container {
width: 50%;
display: grid;
grid-template-columns: 40px auto 40px;
}
.referenceText {
font-family: Arial;
display: inline-block;
font-size: 3vw;
color: #4287f5;
/*outline: 0.1vw dashed red;*/
}
.link {
font-size: 200px;
color: #a7a4bf;
text-decoration: none;
width: 100px;
height: 100px;
outline: 0.1vw dashed orange;
}
.link:hover {
color: #636175;
}
<div class="flex-container">
<div class="grid-container">
<a class="link" href="">‹</a>
<div class="referenceText">This is the reference</div>
<a class="link" href="">›</a>
</div>
</div>
Please note that we want the arrows to be at the edges of the screen and the text at the center...
Make these changes in .grid-container and .link
.grid-container {
width: 80%;
display: grid;
grid-template-columns: 100px auto 100px;
align-items: center;
justify-items: center;
}
.link {
font-size: 200px;
color: #a7a4bf;
text-decoration: none;
width: 100px;
/* height: 100px; remove height*/
outline: 0.1vw dashed orange;
}
check codepen
Add display: flex;, align-items: center; and justify-content: space-between; to .grid-container and change the width to 100%.

Can't understand how percentage work in html/CSS

Ok, so during the last weeks I've been trying to understand how html and CSS work, right now I'm struggling trying to make a grid layout. I'm trying to make my web responsive but when I work with percentages the percentages don't seem to apply correctly. For example there's an orange rectangle that's supposed to fit all the width of the screen, but with my code when the screen is pretty small it isn't large enough.
Here's the HTML and CSS (there are different settings depending on the media):
#media screen and (max-width:480px) {
body {
background-color: mediumspringgreen;
display: grid;
grid-template-columns: 100%;
grid-template-rows: 30% 6% 60% 4%;
grid-template-areas: "header" "nav" "main" "footer";
}
header img {
display: block;
align-self: center;
justify-self: center;
max-height: 5%;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.rectangle {
width: 100%;
height: 4%;
background: gold;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
}
.button1 {
background-color: green;
color: gold;
border: 3px solid mediumspringgreen;
border-radius: 12px;
display: inline-block;
cursor: pointer;
}
nav {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
main {
display: grid;
grid-template-columns: 100%;
grid-template-rows: 70% 30%;
grid-template-areas: "imatge" "descripcio";
}
.imatge {
background-color: mediumspringgreen;
display: inline-block;
}
.descripcio {
background: gold;
justify-content: center;
align-items: center;
display: inline-block;
width: 100%;
height: 50%;
}
footer {
display: inline-block;
width: 100%;
align-items: center;
justify-content: center;
}
}
#media screen and (min-width:481px) {
body {
background-color: mediumspringgreen;
display: grid;
grid-template-columns: 100%;
grid-template-rows: 30% 6% 60% 4%;
grid-template-areas: "header" "nav" "main" "footer";
width: 100%;
height: 100%;
}
header img {
display: block;
align-self: center;
justify-self: center;
max-height: 5%;
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
.rectangle {
width: 100%;
height: 4%;
background: gold;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
}
.button1 {
background-color: green;
color: gold;
border: 3px solid mediumspringgreen;
border-radius: 12px;
display: inline-block;
cursor: pointer;
}
nav {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
main {
display: grid;
grid-template-columns: 50% 50%;
grid-template-rows: 100%;
grid-template-areas: "imatge descripcio";
}
.imatge {
background-color: mediumspringgreen;
}
.descripcio {
background: gold;
justify-content: center;
align-items: center;
display: flex;
position: absolute;
width: 100%;
height: 50%;
}
footer {
display: inline-block;
width: 100%;
align-items: center;
justify-content: center;
}
span {
color: gold;
}
}
<header style="width: 100%;">
<p style="text-align:center;">
<a href="pàgina%20home.html">
<img src="https://i.imgur.com/BSHMhUe.png" alt="logo">
</a>
</p>
</header>
<nav style="width: 100%;">
<p class="rectangle">
<button class="button1" onclick="location.href='pàgina%20productes.html'">Productes</button>
<span> </span>
<button class="button1" onclick="location.href='pàgina%20contacte.html'">Contacte</button>
</p>
</nav>
<main>
<section style="text-align:center;" class="Imatge">
<h2 style="font-size:150%;">Producte Destacat</h2>
<a href="pàgina%20producte.html">
<p style="text-align:center;">
<img src="https://clubtech.es/wp-content/uploads/2018/12/playstation_4_console_controller_ps4_92842_3840x2160.jpg" alt="Producte destacat" style="width:40%">
</p>
</a>
</section>
<article style="text-align:center;" class="Descripcio">
<p></p>Description</article>
</main>
<footer>
<p style="text-align:center;">
Avís Legal-Privadesa-Termes d'ús
</p>
<p style="text-align:center; font-size:75%;">
Logo vector created by freepik - www.freepik.com
</p>
</footer>
Right now my problems are that elements don't change their size proportionally to the resolutions of the screen, they decrease or increase their size at different speeds. Also, sometimes elements from a grid cell overlap with elements of another cell, like if I leave the header img at 100% it overlaps with the rest of the elements in the html.
JSFiddle: https://jsfiddle.net/915seaLc/
Reset the margin of the body, and I recommend reset the padding to
body {
margin: 0;
padding: 0;
}

Multi row CSS grid without nesting

FOR EXAMPLE, SEE THIS PEN
I have 6 menu items and I want to achieve this grid layout without nesting. I'm a newbie in CSS grid and I thought using the CSS grid will be the best way to achieve what in the design.
This is what I have done so far.
ul {
list-style: none;
padding-left: 0;
}
.menu-items {
text-align: center;
display: grid;
grid-template-columns: 100%;
grid-template-rows: repeat(3, 33.33%);
}
.menu-items {
width: 100%;
height: 100vh;
overflow: hidden;
position: fixed;
top: 0;
left: 0;
grid-template-columns: 1fr 1fr;
grid-template-rows: 50% 50%;
grid-template-areas: "item1 item2" "item3 item4";
}
.menu__item {
height: 100%;
background: #212528;
border: 1px solid #333;
display: flex;
justify-content: center;
align-items: center;
}
.menu__item--1 {
grid-area: item1;
}
.menu__item--2 {
grid-area: item2;
}
.menu__item--3 {
grid-area: item3;
}
.menu__item--4 {
grid-area: item3;
}
.menu__item--5 {
grid-area: item3;
}
.menu__item--6 {
grid-area: item4;
}
.menu__item--3,
.menu__item--4,
.menu__item--5 {
display: block;
}
.menu-item-inner {
align-items: center;
}
.mainmenu {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.mainmenu {
counter-reset: menuitem;
}
.mainmenu__item {
text-transform: lowercase;
overflow: visible;
margin: 0.5rem 0;
padding: 0 0.5rem;
position: relative;
transition: color 0.3s;
}
.mainmenu__item:hover {
color: cyan;
}
.mainmenu__item:hover::after {
opacity: 1;
transform: scale3d(1, 1, 1);
}
ul.menu-items {
margin: 0;
padding: 0;
}
.mainmenu__item {
position: relative;
overflow: hidden;
transition: color 0.1s;
margin: 0.25rem 0;
display: block;
color: #fff;
font-size: 32px;
font-weight: 800;
}
<ul class="menu-items">
<li class="menu__item menu__item--1">
<div class="menu-item-inner">
<div class="mainmenu">
Menu 1
</div>
</div>
</li>
<li class="menu__item menu__item--2">
<div class="menu-item-inner">
<div class="mainmenu">
Menu 2
</div>
</div>
</li>
<li class="menu__item menu__item--3">
<div class="menu-item-inner">
<div class="mainmenu">
Menu 3
</div>
</div>
</li>
<li class="menu__item menu__item--4">
<div class="menu-item-inner">
<div class="mainmenu">
Menu 4
</div>
</div>
</li>
<li class="menu__item menu__item--5">
<div class="menu-item-inner">
<div class="mainmenu">
Menu 5
</div>
</div>
</li>
<li class="menu__item menu__item--6">
<div class="menu-item-inner">
<div class="mainmenu">
Menu 6
</div>
</div>
</li>
</ul>
CODPEN
Can anyone please guide me achieving this layout using CSS-Grid without nesting
(Changing the visual order without changing the logical order of the
document)
You can use grid-template-areas if you want complex layout:
* {
box-sizing: border-box;
}
body {
margin: 0;
display: flex;
align-items: center;
justify-content:center;
height: 100vh;
min-height: 600px;
}
.box {
display: flex;
align-items: center;
justify-content:center;
border: 1px solid #333;
background: #444;
color: #f9f9f9;
font-size: 2rem;
font-family: Open-sans, Arial, sans-serif;
}
.container {
width: 800px;
height: 100%;
display: grid;
padding: .5rem;
grid-gap: .5rem;
/* This is where Grid is defined*/
grid-template-areas:
'box-1 box-1 box-2 box-2'
'box-1 box-1 box-2 box-2'
'box-3 box-5 box-6 box-6'
'box-4 box-5 box-6 box-6';
}
.box-1 {
grid-area: box-1;
}
.box-2 {
grid-area: box-2;
}
.box-3 {
grid-area: box-3;
}
.box-4 {
grid-area: box-4;
}
.box-5 {
grid-area: box-5;
}
.box-6 {
grid-area: box-6;
}
<div class="container">
<div class="box box-1">1</div>
<div class="box box-2">2</div>
<div class="box box-3">3</div>
<div class="box box-4">4</div>
<div class="box box-5">5</div>
<div class="box box-6">6</div>
</div>