This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Is there a "previous sibling" selector?
(30 answers)
Closed 2 years ago.
This is for a Rock, Paper, Scissors game that I'm working on. I'm trying to make the sub-text slide in when you hover over the hands, but I can't seem to get it to work. What am I missing?
.choices {
display: flex;
flex-direction: column;
}
.hands {
height: 50%;
display: flex;
align-items: flex-end;
justify-content: space-evenly;
}
.far {
font-size: 5vh;
cursor: pointer;
}
.subText {
height: 50%;
display: flex;
justify-content: space-evenly;
}
#rock,
#paper,
#scissors {
opacity: 0;
height: 0;
background-color: rgb(100, 100, 100);
text-align: center;
margin-top: 0.5vh;
margin-left: 2vh;
font-size: 2vh;
transition: 0.3s;
}
.fa-hand-rock:hover+#rock {
opacity: 1;
height: 40%
}
.fa-hand-paper:hover+#paper {
opacity: 1;
height: 40%
}
.fa-hand-scissors:hover+#scissors {
opacity: 1;
height: 40%
}
<section class="choices">
<div class="hands">
<i class="far fa-hand-rock" onclick="game(1)"></i>
<i class="far fa-hand-paper" onclick="game(2)"></i>
<i class="far fa-hand-scissors" onclick="game(3)"></i>
</div>
<div class="subText">
<h6 id="rock">Rock</h6>
<h6 id="paper">Paper</h6>
<h6 id="scissors">Scissors</h6>
</div>
</section>
.hands{
padding:40px;
}
.choices {
display: flex;
flex-direction: column;
}
.far {
font-size: 20px;
cursor: pointer;
margin:0 50px;
}
.subText {
display: block;
}
#rock,
#paper,
#scissors {
opacity: 0;
background-color: rgb(100, 100, 100);
font-size: 12px;
transition: 0.3s;
display:inline-block;
text-align:center;
width:100px;
margin:10px 15px;
}
.fa-hand-rock:hover~.subText #rock {
opacity: 1;
}
.fa-hand-paper:hover~.subText #paper {
opacity: 1;
}
.fa-hand-scissors:hover~.subText #scissors {
opacity: 1;
}
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<section class="choices">
<div class="hands">
<i class="far fa-hand-rock" onclick="game(1)"></i>
<i class="far fa-hand-paper" onclick="game(2)"></i>
<i class="far fa-hand-scissors" onclick="game(3)"></i>
<div class="subText">
<h6 id="rock">Rock</h6>
<h6 id="paper">Paper</h6>
<h6 id="scissors">Scissors</h6>
</div>
</div>
</section>
Related
I've been coding for a while. then use Bootstrap later make me see the problem by only my first section(home) background turns white but in html background-color is black. Maybe I've used Bootstrap before, it's causing the error.enter image description here
html {
background-color: #222831;
font-size: calc(60% + 0.8vmin);
width: 100%;
height: 100%;
height: 1000px;
}
.pic-me img{
max-height: 500px;
border-radius: 12px;
}
.home {
display: relative;
max-width: 1000px;
min-height: 100vh;
margin-top: calc(6rem + 2rem);
margin-left: auto;
margin-right: auto;
padding: 4rem 2rem;
text-align: center;
}
.home-container {
text-align: left;
display: flex;
justify-content: space-between;
align-items: center;
}
.home-container .media {
display: flex;
flex-direction: column;
row-gap: 1rem;
}
.home-container .media a {
font-size: 1.5rem;
}
.home-container .media a :hover {
color: #ff6768;
}
.home-container .me {
margin: 0 10px;
}
.home-container .me h2 {
font-size: 3rem;
color: #FD7013;
font-weight: 600px;;
}
.home-container .me h3 {
font-size: 1.5rem;
color: #F3AA29;
font-weight: 600px;;
}
.home-container .me p {
max-width: 380px;
font-size: 2rem;
color: #EEEEEE;
font-weight: 500px;
}
.home a {
font-size: 1.5rem;
}
.home .scroll-down i{
color: #ff6768;
font-size: 1.5rem;
margin-top: 30px;
animation: scroll-down 2s ease infinite;
}
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<section class="home" id="home">
<div class="home-container">
<div class="media">
<a href="https://www.facebook.com/webbalaka/" target="_blank"
><i class="fa-brands fa-facebook-f"></i
></a>
<a href="https://www.instagram.com/web.wafu/" target="_blank"
><i class="fa-brands fa-instagram"></i
></a>
<i class="fa-brands fa-twitter"></i>
</div>
<div class="me">
<h2>Pasit Khumsena</h2>
<h3>SCiUS Student</h3>
<p>"Don't worry about what you can't control"</p>
</div>
<div class="pic-me">
<!-- <img src="/AnotherPort/img/IOIOIOIO.JPG" alt="" /> -->
<div style="background-color: red; width: 350px; height: 400px"></div>
</div>
</div>
<a href="#about" class="scroll-down"
>Scroll Down <i class="fa-solid fa-angles-down"></i
></a>
</section>
or perhaps caused by nav-bar high over section.
.nav-bar {
position: relative;
height: calc(4rem + 1rem);
display: flex;
justify-content: space-between;
align-items: center;
margin-left: auto;
margin-right: auto;
padding: 0 1.25rem;
transition: 0.5s ;
}
.nav-item {
justify-content: space-around;
display: flex;
column-gap: 2rem;
}
.nav-bar h1{
font-size: 3em;
color: #ff6768;
}
.nav-item a {
font-size: 1.2em;
font-weight: 500px;
color: #EEEEEE;
}
.nav-item a:hover {
color: #F3AA29;
}
.pic-me img{
max-height: 500px;
border-radius: 12px;
}
<header>
<div class="nav-bar">
<div class="Portfolio">
<h1>Portfolio</h1>
</div>
<div class="nav-item">
Home
About
Education
Skill
Contact
</div>
</div>
</header>
I am trying to add a close effect with Keyframe css to the dropdown menu. I have succeeded with the opening, but I cannot do the same with the close. If you take a look you see the animation on entry, but on exit the menu simply disappears.
Sorry but I'm relatively new, someone kindly explain to me what I'm doing wrong?
I know that I can achieve the same result also with Javascript, but I would like to obtain the result only with css and understand if this is possible.
Updated Snippet: I was looking for an alternative to visibility property because even with hidden menu I have the "ghost container" in front of other elements. I was thinking about display none to block and keyframe animation, but this did not allow me to add a closing effect. Anyway I kept visibility and solved the "ghost container" with height property.
var usermenu = document.querySelector(".user_menu_button");
function userMenu() {
var x = document.getElementById("mts_menu");
if (x.classList.toggle ("show")) {
usermenu.innerHTML = '<i class="icn_button fa-solid fa-xmark"></i><span class="txt_button">Account</span>';
} else {
usermenu.innerHTML = '<i class="icn_button fa-solid fa-bars"></i><span class="txt_button">Account</span>';
}
}
/*Items menu*/
.user_menu {
display: flex;
flex-direction: column;
}
/*Menu header info*/
.display.name {
font-size: 15px;
font-weight: 500;
color: #303238;
}
.display.mail {
font-size: 13px;
color: #3d5afe;
}
hr.solid {
border-top: 1px solid #e0e0e0;
margin: 10px 0px 10px 0px;
}
/*Text Link css*/
.user_menu.item > a {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 8px 0;
font-size: 13px;
color: #75777D;
}
.user_menu.item:hover > a {
color: #2E323A;
}
/*Icon Button Toggle Menu*/
.user_menu_button {
display: flex;
align-content: center;
justify-content: center;
align-items: center;
width: 100%;
background: #282c33!important;
font-weight: 500!important;
font-size: 13px!important;
}
.icn_button {
margin: 0;
}
.icn_button:before, .icn_button:after {
margin: 0;
}
.txt_button {
margin-left: 10px;
}
/*Icon Items Menu*/
.icn_menu:before, .icon_menu:after {
margin: 0px;
padding: 0px;
font-size: 16px
}
.icn_menu {
margin-right: 10px;
display: flex !important;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
}
/* User Menu For header website */
.mts_menu_container {
display: flex;
flex-direction: column;
align-content: flex-end;
align-items: flex-end;
}
.dropdown_box {
position: absolute;
margin-top: 17px;
}
.mnu_padding {
padding: 20px;
}
.mts_dropdown_content {
background-color: #fff;
min-width: 160px;
width: 280px;
border-radius: 3px;
overflow-x: hidden;
overflow-y: hidden;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 999;
position: relative;
visibility: hidden;
opacity: 0;
top: 50px;
height: 0;
transition: visibility 0.2s, max-height 0.2s, opacity 0.2s, top 0.2s, height 0.2s;
}
.mts_dropdown_content.show {
height: 100%;
visibility: visible;
opacity: 1;
top: 0;
transition: visibility 0.2s, max-height 0.2s, opacity 0.2s, top 0.2s, height 0.2s;
}
<button onclick="userMenu()" class="user_menu_button">
<i class="icn_button fa-solid fa-bars"></i>
<span class="txt_button">Account</span>
</button>
<div class="mts_menu_container">
<div class="dropdown_box">
<div id="mts_menu" class="mts_dropdown_content">
<div class="mnu_padding">
<div class="user_menu header">
<span class="display name">Ciao [display_name]</span>
<span class="display mail">[display_email]</span>
</div>
<hr class="solid">
<div class="user_menu item">
<a href="/account">
<i class="icn_menu fa-regular fa-user"></i>
<span class="link_text">Dashboard</span>
</a>
</div>
<div class="user_menu item">
<a href="ordini">
<i class="icn_menu fa-regular fa-basket-shopping"></i>
<span class="link_text">I miei ordini</span>
</a>
</div>
<div class="user_menu item">
<a href="libreria">
<i class="icn_menu fa-regular fa-cloud-arrow-down"></i>
<span class="link_text">Downloads</span>
</a>
</div>
<div class="user_menu item">
<a href="impostazioni">
<i class="icn_menu fa-regular fa-gear"></i>
<span class="link_text">Impostazioni</span>
</a>
</div>
<div class="user_menu item">
<a href="wp-login.php?action=logout">
<i class="icn_menu fa-regular fa-arrow-right-from-bracket"></i>
<span class="link_text">Logout</span>
</a>
</div>
</div>
</div>
</div>
</div>
Original Snippet
var usermenu = document.querySelector(".user_menu_button");
function userMenu() {
var x = document.getElementById("mts_menu");
if (x.classList.toggle ("show")) {
usermenu.innerHTML = '<i class="icn_button fa-solid fa-xmark"></i><span class="txt_button">Account</span>';
} else {
usermenu.innerHTML = '<i class="icn_button fa-solid fa-bars"></i><span class="txt_button">Account</span>';
}
}
/*Items menu*/
.user_menu {
display: flex;
flex-direction: column;
}
/*Menu header info*/
.display.name {
font-size: 15px;
font-weight: 500;
color: #303238;
}
.display.mail {
font-size: 13px;
color: #3d5afe;
}
hr.solid {
border-top: 1px solid #e0e0e0;
margin: 10px 0px 10px 0px;
}
/*Text Link css*/
.user_menu.item > a {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 8px 0;
font-size: 13px;
color: #75777D;
}
.user_menu.item:hover > a {
color: #2E323A;
}
/*Icon Button Toggle Menu*/
.user_menu_button {
display: flex;
align-content: center;
justify-content: center;
align-items: center;
width: 100%;
background: #282c33!important;
font-weight: 500!important;
font-size: 13px!important;
}
.icn_button {
margin: 0;
}
.icn_button:before, .icn_button:after {
margin: 0;
}
.txt_button {
margin-left: 10px;
}
/*Icon Items Menu*/
.icn_menu:before, .icon_menu:after {
margin: 0px;
padding: 0px;
font-size: 16px
}
.icn_menu {
margin-right: 10px;
display: flex !important;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
}
/* User Menu For header website */
.mts_menu_container {
display: flex;
flex-direction: column;
align-content: flex-end;
align-items: flex-end;
}
.dropdown_box {
position: absolute;
margin-top: 17px;
}
.mnu_padding {
padding: 20px;
}
.mts_dropdown_content {
background-color: #fff;
min-width: 160px;
width: 280px;
border-radius: 3px;
overflow-x: hidden;
overflow-y: hidden;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 999;
position: relative;
display: none;
animation: fade_in_hide 0.2s;
}
.mts_dropdown_content.show {
display: block;
animation: fade_in_show 0.2s;
}
#keyframes fade_in_show {
0% {
opacity: 0;
top: 50px;
}
100% {
opacity: 1;
top: 0;
}
}
#keyframes fade_in_hide {
0% {
opacity: 1;
top: 0;
}
100% {
opacity: 0;
top: 50px;
}
}
<button onclick="userMenu()" class="user_menu_button">
<i class="icn_button fa-solid fa-bars"></i>
<span class="txt_button">Account</span>
</button>
<div class="mts_menu_container">
<div class="dropdown_box">
<div id="mts_menu" class="mts_dropdown_content">
<div class="mnu_padding">
<div class="user_menu header">
<span class="display name">Ciao [display_name]</span>
<span class="display mail">[display_email]</span>
</div>
<hr class="solid">
<div class="user_menu item">
<a href="/account">
<i class="icn_menu fa-regular fa-user"></i>
<span class="link_text">Dashboard</span>
</a>
</div>
<div class="user_menu item">
<a href="ordini">
<i class="icn_menu fa-regular fa-basket-shopping"></i>
<span class="link_text">I miei ordini</span>
</a>
</div>
<div class="user_menu item">
<a href="libreria">
<i class="icn_menu fa-regular fa-cloud-arrow-down"></i>
<span class="link_text">Downloads</span>
</a>
</div>
<div class="user_menu item">
<a href="impostazioni">
<i class="icn_menu fa-regular fa-gear"></i>
<span class="link_text">Impostazioni</span>
</a>
</div>
<div class="user_menu item">
<a href="wp-login.php?action=logout">
<i class="icn_menu fa-regular fa-arrow-right-from-bracket"></i>
<span class="link_text">Logout</span>
</a>
</div>
</div>
</div>
</div>
</div>
Since you don't want to go the JS route, transitions would be easier here. However, you can't transition display so you'll need to swap that out for visibility and have your menu display set to block from the start and just hide it with visibility and opacity.
var usermenu = document.querySelector(".user_menu_button");
function userMenu() {
var x = document.getElementById("mts_menu");
if (x.classList.toggle("show")) {
usermenu.innerHTML = '<i class="icn_button fa-solid fa-xmark"></i><span class="txt_button">Account</span>';
} else {
usermenu.innerHTML = '<i class="icn_button fa-solid fa-bars"></i><span class="txt_button">Account</span>';
}
}
/*Items menu*/
.user_menu {
display: flex;
flex-direction: column;
}
/*Menu header info*/
.display.name {
font-size: 15px;
font-weight: 500;
color: #303238;
}
.display.mail {
font-size: 13px;
color: #3d5afe;
}
hr.solid {
border-top: 1px solid #e0e0e0;
margin: 10px 0px 10px 0px;
}
/*Text Link css*/
.user_menu.item>a {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 8px 0;
font-size: 13px;
color: #75777D;
}
.user_menu.item:hover>a {
color: #2E323A;
}
/*Icon Button Toggle Menu*/
.user_menu_button {
display: flex;
align-content: center;
justify-content: center;
align-items: center;
width: 100%;
background: #282c33 !important;
font-weight: 500 !important;
font-size: 13px !important;
}
.icn_button {
margin: 0;
}
.icn_button:before,
.icn_button:after {
margin: 0;
}
.txt_button {
margin-left: 10px;
}
/*Icon Items Menu*/
.icn_menu:before,
.icon_menu:after {
margin: 0px;
padding: 0px;
font-size: 16px
}
.icn_menu {
margin-right: 10px;
display: flex !important;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
}
/* User Menu For header website */
.mts_menu_container {
display: flex;
flex-direction: column;
align-content: flex-end;
align-items: flex-end;
}
.dropdown_box {
position: absolute;
margin-top: 17px;
}
.mnu_padding {
padding: 20px;
}
.mts_dropdown_content {
background-color: #fff;
min-width: 160px;
width: 280px;
border-radius: 3px;
overflow-x: hidden;
overflow-y: hidden;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: -1;
opacity: 0;
top: 50px;
position: relative;
display: block;
visibility: none;
transition: opacity, top, 0.2s linear;
}
.mts_dropdown_content.show {
opacity: 1;
top: 0px;
z-index: 999;
visibility: visible;
transition: opacity, top, 0.2s linear;
}
#keyframes fade_in_show {
0% {
opacity: 0;
top: 50px;
}
100% {
opacity: 1;
top: 0;
}
}
#keyframes fade_in_hide {
0% {
opacity: 1;
top: 0;
}
100% {
opacity: 0;
top: 50px;
}
}
<button onclick="userMenu()" class="user_menu_button">
<i class="icn_button fa-solid fa-bars"></i>
<span class="txt_button">Account</span>
</button>
<div class="mts_menu_container">
<div class="dropdown_box">
<div id="mts_menu" class="mts_dropdown_content">
<div class="mnu_padding">
<div class="user_menu header">
<span class="display name">Ciao [display_name]</span>
<span class="display mail">[display_email]</span>
</div>
<hr class="solid">
<div class="user_menu item">
<a href="/account">
<i class="icn_menu fa-regular fa-user"></i>
<span class="link_text">Dashboard</span>
</a>
</div>
<div class="user_menu item">
<a href="ordini">
<i class="icn_menu fa-regular fa-basket-shopping"></i>
<span class="link_text">I miei ordini</span>
</a>
</div>
<div class="user_menu item">
<a href="libreria">
<i class="icn_menu fa-regular fa-cloud-arrow-down"></i>
<span class="link_text">Downloads</span>
</a>
</div>
<div class="user_menu item">
<a href="impostazioni">
<i class="icn_menu fa-regular fa-gear"></i>
<span class="link_text">Impostazioni</span>
</a>
</div>
<div class="user_menu item">
<a href="wp-login.php?action=logout">
<i class="icn_menu fa-regular fa-arrow-right-from-bracket"></i>
<span class="link_text">Logout</span>
</a>
</div>
</div>
</div>
</div>
</div>
I have a problem. Specifically with my images on my site. When I see my site on Android phone, images displays normally without any issues. iPhone displays it like "stretched" to height. I would love to get help, how to fix this problem. I tried some ways how to avoid that, but I found nothing. Sorry for long code. Here are pictures for visualization:
IPhone Image
Android Image
#import url('https://fonts.googleapis.com/css2?family=Commissioner:wght#400;500;700&display=swap');
:root {
--main-font: Commissioner;
--main-font-weight: 500;
--color-background-first: #1D201F;
--color-content-red: #C58882;
--color-content-yellow: #EAD2AC;
--color-content-blue: #D1DEDE;
--color-content-pink: #DF928E;
--color-background-second: #404040;
}
* {
font-family: var(--main-font);
font-weight: var(--main-font-weight);
margin: 0;
padding: 0;
}
html {
box-sizing: border-box;
}
#navbar {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
background-color: var(--color-background-second);
width: 100%;
height: 5rem;
box-shadow: 0px 5px 10px 2px black;
margin-top: -3px;
}
#navbar>ul {
display: flex;
list-style-type: none;
font-size: 2.1rem;
min-height: 100%;
}
#navbar>ul>li {
padding: 1vw;
min-height: 100%;
display: flex;
align-items: center;
transition: ease-out 0.3s;
}
#navbar>ul>li>a {
text-decoration: none;
color: var(--color-content-red);
max-height: 100%;
}
li:hover {
background-color: rgba(0, 0, 0, 0.5);
}
#welcome-section {
display: flex;
align-items: center;
background-color: var(--color-background-first);
min-height: 100vh;
}
#welcome-section>div {
max-width: 65vh;
margin-left: 3vw;
margin-right: 3vw;
}
#welcome-section>div>h1 {
color: var(--color-content-yellow);
letter-spacing: 0.2em;
font-size: 4rem;
margin-top: 7rem;
}
#first-line {
color: var(--color-content-blue);
text-align: center;
letter-spacing: 0.2em;
margin: 2em auto 0 auto;
font-size: 3rem;
}
#second-line {
color: var(--color-content-pink);
text-align: center;
letter-spacing: 0.2em;
font-size: 2rem;
font-style: italic;
}
#project-link {
font-size: 15pt;
padding: 1rem;
border-radius: 3px;
border: none;
background-color: #404040;
color: white;
transition: ease-in-out 0.2s;
text-align: center;
}
#project-link:hover {
cursor: pointer;
background-color: var(--color-content-red);
}
#project-link>i {
transition: ease-in-out 0.2s;
}
#project-link:hover>i {
transform: translateX(5px);
}
#welcome-section>i {
font-size: 1500%;
color: var(--color-background-first);
}
#emoji {
margin: 0 auto;
transition: ease-in 0.5s;
}
#project-link:hover+#emoji {
color: var(--color-content-blue);
}
#projects {
min-height: 100%;
width: 100%;
background-color: var(--color-content-red);
display: flex;
justify-content: center;
}
tile-image {
aspect-ratio: 1 / 1;
}
#project-tiles-container {
display: grid;
grid-template-columns: repeat(2, minmax(2px, 500px));
grid-gap: 4rem;
max-width: 80%;
max-width: 1280px;
margin: 0 2rem 6rem 2rem;
justify-content: center;
padding-top: 3rem;
}
.tile-desc {
padding: 2rem;
text-align: center;
background-color: var(--color-background-first);
}
.project-tile {
display: flex;
flex-direction: column;
text-decoration: none;
color: var(--color-content-yellow);
font-size: 1.2em;
box-shadow: 0px 0px 30px 1px black;
}
.code {
font-size: 100%;
color: var(--color-background-first);
transition: ease-out 0.5s;
}
.align-right {
transform: translateX(20px);
}
.align-left {
transform: translateX(-20px);
}
.project-tile:hover .align-left {
transform: translateX(0px);
color: var(--color-content-blue);
}
.project-tile:hover .align-right {
transform: translateX(0px);
color: var(--color-content-blue);
}
#contact-section-container {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
min-height: 100vh;
background-color: var(--color-content-yellow);
color: var(--color-background-second);
text-shadow: 2px 1px 0px var(--color-content-pink);
gap: 1vh;
}
#contact-section-container>div {
display: flex;
gap: 4rem;
font-size: 1.8rem;
max-width: 80%;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
#contact-section-container>div>div>a {
text-decoration: none;
color: var(--color-background-second);
}
#contact-section-container>div>h1 {
font-size: 4rem;
text-align: center;
}
#contact-section-container>div>div {
display: flex;
align-items: center;
}
.contact-icon {
font-size: 2rem;
}
#contact-section-container>div>div>a {
transition: ease-out 0.2s;
}
#contact-section-container>div>div>a:hover {
transform: translateY(8px);
}
#media only screen and (max-width: 1000px) {
#welcome-section {
display: flex;
flex-direction: column;
margin: auto;
justify-content: center;
width: 100%;
text-align: center;
gap: 3rem;
}
html {
font-size: 75%;
}
#welcome-section>div>h1 {
margin-top: 12rem;
}
#project-tiles-container {
display: grid;
grid-template-columns: repeat(2, minmax(2px, 500px));
grid-gap: 4rem;
max-width: 80%;
max-width: 1280px;
margin: 0 2rem 6rem 2rem;
justify-content: center;
padding-top: 3rem;
}
#projects {
font-size: 150%;
}
#contact-section-container>div {
font-size: 200%;
}
}
#media only screen and (max-width: 800px) {
#project-tiles-container {
display: grid;
grid-template-columns: repeat(1, minmax(50px, 350px));
grid-gap: 4rem;
width: 80%;
max-width: 1280px;
margin: 0 auto;
margin-bottom: 6rem;
justify-content: center;
align-items: center;
}
#projects {
font-size: 150%;
}
}
#media only screen and (max-width: 330px) {
html {
font-size: 50%;
}
#projects {
font-size: 200%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://kit.fontawesome.com/7290e96d25.js" crossorigin="anonymous"></script>
<title>Robin Weiss</title>
</head>
<body>
<main id="main">
<nav id="navbar">
<ul>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
<section id="welcome-section">
<div id="container-about">
<h1>Hello, welcome to my portfolio!</h1>
<p id="first-line">I’m Robin</p>
<p id="second-line">a web developer</p>
</div>
<a id="project-link" href="https://codepen.io/weissrobin">
See all projects! <i class="fa-solid fa-chevron-right "></i>
</a>
<i id="emoji" class="fa-regular fa-face-smile-wink code "></i>
</section>
<section id="projects">
<div id="project-tiles-container">
<a class="project-tile" target="_blank" href="https://codepen.io/weissrobin/full/OJQMRvd">
<img class="tile-image" src="https://i.pinimg.com/564x/81/4d/6c/814d6c2caabab89b3c2608db7a11a6ba.jpg" alt="">
<p class="tile-desc">
<i class="fa-solid fa-chevron-left icon code align-left"></i> Survey Form
<i class="fa-solid fa-chevron-right icon code align-right"></i>
</p>
</a>
<a class="project-tile" target="_blank" href="https://codepen.io/weissrobin/full/KKQdYQw">
<img class="tile-image" src="https://i.pinimg.com/564x/7d/54/d0/7d54d0a35d57de79dacfe8662661523f.jpg" alt="">
<p class="tile-desc">
<i class="fa-solid fa-chevron-left icon code align-left"></i> Tribute Page
<i class="fa-solid fa-chevron-right icon code align-right"></i>
</p>
</a>
<a class="project-tile" target="_blank" href="https://codepen.io/weissrobin/full/zYRreRR">
<img class="tile-image" src="https://i.pinimg.com/564x/5f/ea/74/5fea74ebc53df1b0ad3534a1523b1256.jpg" alt="">
<p class="tile-desc">
<i class="fa-solid fa-chevron-left icon code align-left"></i> Product Page
<i class="fa-solid fa-chevron-right icon code align-right"></i>
</p>
</a>
<a class="project-tile" href="">
<img class="tile-image" src="" alt="">
</a>
</div>
</section>
<section id="contacts">
<div id="contact-section-container">
<div>
<h1>Lets work together</h1>
</div>
<div>
<div>
<a target="_blank" href="https://www.facebook.com/robin.hubacek/">
<i class="fa-brands fa-facebook contact-icon"></i>Facebook
</a>
</div>
<div>
<a target="_blank" href="https://www.instagram.com/robiwei/">
<i class="fa-brands fa-instagram-square contact-icon"></i>Instagram
</a>
</div>
<div>
<a id="profile-link" target="_blank" href="https://github.com/WeissRobin">
<i class="fa-brands fa-github-square contact-icon"></i>GitHub
</a>
</div>
<div>
<a href="">
<i class="fa-solid fa-at contact-icon"></i>Send a mail
</a>
</div>
<div>
<a href="">
<i class="fa-solid fa-mobile-screen contact-icon"></i>Call me
</a>
</div>
</div>
</div>
</section>
</main>
</body>
</html>
This website that I've been working on is giving me some problems. Whenever I give it a <a href> tag, it repositions it (the link) and changed how the text is formatted. I've excluded a lot of code from the main of the website and just added the menu bar, so it should be easier to read.
Wihtout the link:
With the link:
Here's the code:
body{
margin: 0;
font-family: HebrewRegular;
background-color: white;
}
.menuBar {
position: sticky;
top: 0;
z-index: 1;
background-color: rgb(168, 123, 81);
}
.fa-brands, .fab{
font-size: 30px;
margin: 10px;
}
.fa-solid, .fas{
font-size: 30px;
margin: 10px;
margin-left: 10px;
}
.menuIcons{
display: flex;
flex-wrap: wrap;
flex-direction:row;
justify-content: center;
align-items: center;
}
.facebook{
font-size: 25px;
}
.menu{
font-size: 25px;
}
a.fbLink{
text-decoration:none;
color:inherit
}
<script src="https://kit.fontawesome.com/a590c06ed2.js" crossorigin="anonymous"></script>
<body>
<div class = "menuBar" id = "menuBar">
<div class = "menuIcons">
<a href = "https://www.facebook.com/benniecharmthai" class = "fbLink">
<i class="fa-brands fa-facebook"></i>
<p class = "facebook">Facebook</p>
</a>
<i class="fa-solid fa-bowl-food"></i>
<p class = "menu">Menu</p>
</div>
</div>
</body>
p elements go to the new lines (display: inline-block; by default), and you added flexbox for menuIcons to align them. The main problem is you wrap Facebook's child elements into a which makes your flexbox not work for them.
For the fix, you should add flexbox for .menuIcons > a too.
One side note, to make all containers consistent (not required), I added div to wrap Menu's elements as well
body{
margin: 0;
font-family: HebrewRegular;
background-color: white;
}
.menuBar {
position: sticky;
top: 0;
z-index: 1;
background-color: rgb(168, 123, 81);
}
.fa-brands, .fab{
font-size: 30px;
margin: 10px;
}
.fa-solid, .fas{
font-size: 30px;
margin: 10px;
margin-left: 10px;
}
.menuIcons{
display: flex;
flex-wrap: wrap;
flex-direction:row;
justify-content: center;
align-items: center;
}
.facebook{
font-size: 25px;
}
.menu{
font-size: 25px;
}
a.fbLink{
text-decoration:none;
color:inherit
}
/* The fix is here */
.menuIcons > a, .menuIcons > div {
display: flex;
align-items: center;
}
<script src="https://kit.fontawesome.com/a590c06ed2.js" crossorigin="anonymous"></script>
<body>
<div class="menuBar" id="menuBar">
<div class="menuIcons">
<a href="https://www.facebook.com/benniecharmthai" class="fbLink">
<i class="fa-brands fa-facebook"></i>
<p class="facebook">Facebook</p>
</a>
<div>
<i class="fa-solid fa-bowl-food"></i>
<p class="menu">Menu</p>
</div>
</div>
</div>
</body>
If you don't prefer using flexbox for the fix, you can consider to use span (display: inline;) instead of p (display: inline-block;)
body {
margin: 0;
font-family: HebrewRegular;
background-color: white;
}
.menuBar {
position: sticky;
top: 0;
z-index: 1;
background-color: rgb(168, 123, 81);
}
.fa-brands,
.fab {
font-size: 30px;
margin: 10px;
}
.fa-solid,
.fas {
font-size: 30px;
margin: 10px;
margin-left: 10px;
}
.menuIcons {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
align-items: center;
}
.facebook {
font-size: 25px;
}
.menu {
font-size: 25px;
}
a.fbLink {
text-decoration: none;
color: inherit
}
<script src="https://kit.fontawesome.com/a590c06ed2.js" crossorigin="anonymous"></script>
<body>
<div class="menuBar" id="menuBar">
<div class="menuIcons">
<a href="https://www.facebook.com/benniecharmthai" class="fbLink">
<i class="fa-brands fa-facebook"></i>
<span class="facebook">Facebook</span>
</a>
<i class="fa-solid fa-bowl-food"></i>
<span class="menu">Menu</span>
</div>
</div>
</body>
The thing which makes formatting different is both i tag and p tag are block-level elements.Which means it takes whole line to the each elemnt.And after an element it takes into a new line.
So in order to solve this you have to use a In-line element.An inline element does not start on a new line.
body{
margin: 0;
font-family: HebrewRegular;
background-color: white;
}
.menuBar {
position: sticky;
top: 0;
z-index: 1;
background-color: rgb(168, 123, 81);
}
.fa-brands, .fab{
font-size: 30px;
margin: 10px;
}
.fa-solid, .fas{
font-size: 30px;
margin: 10px;
margin-left: 10px;
}
.menuIcons{
display: flex;
flex-wrap: wrap;
flex-direction:row;
justify-content: center;
align-items: center;
}
.facebook{
font-size: 25px;
}
.menu{
font-size: 25px;
}
a.fbLink{
text-decoration:none;
color:inherit
}
<script src="https://kit.fontawesome.com/a590c06ed2.js" crossorigin="anonymous"></script>
<body>
<div class = "menuBar" id = "menuBar">
<div class = "menuIcons">
<a href = "https://www.facebook.com/benniecharmthai" class = "fbLink">
<i class="fa-brands fa-facebook"></i>
<span class = "facebook">Facebook</span>
</a>
<i class="fa-solid fa-bowl-food"></i>
<p class = "menu">Menu</p>
</div>
</div>
</body>
use span instead of p like below code:
....
<span class="facebook">Facebook</span>
....
because span has inline display style
I started a new electron project(angulat 9 : using scss), currently stuck at making custom title bar. Here is my code:
app.component.html
<div class="container">
<app-titlebar></app-titlebar>
<div id="router_outlet">
<router-outlet></router-outlet>
</div>
</div>
titlebar.component.html
html, body{
margin: 0 ;
padding: 0 ;
width: 100% ;
height: 100% ;
}
.titlebar {
display: flex;
position: relative;
border: 1px solid black ; /* for reference*/
top: 0;
left: 0;
justify-content: space-between;
height: 3rem;
flex-direction: row;
}
.window-button,
.back-button {
font-size: 12pt;
font-weight: lighter;
-webkit-app-region: no-drag;
-webkit-font-smoothing: antialiased;
text-rendering: geometricPrecision;
}
.window-button {
padding-left: 15px;
padding-right: 15px;
}
.back-button {
padding-left: 17px;
padding-right: 17px;
}
#restore {
transform: rotate(180deg);
}
.window,
.navigation {
display: flex;
align-items: center;
}
.normal:hover {
background-color: rgba(0,0,0,0.2);
}
.danger:hover {
background-color: red;
color: white;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="titlebar">
<div class="navigation">
<a class="back-button normal material-icons">arrow_back</a>
<span class="apptitle">Electron-App</span>
</div>
<div class="window">
<a class="window-button normal material-icons">remove</a>
<a *ngIf="showMaximizeButton ; else showRestore" class="window-button normal material-icons">crop_square</a>
<!-- <ng-template #showRestore>
<a class="window-button normal material-icons" id="restore">flip_to_front</a>
</ng-template> -->
<a class="window-button danger material-icons">clear</a>
</div>
</div>
My question is how to fill these <a> tag entirely to their parent div element height so that on hovering these link the background area filled fully to the .titlebar height.
Set their height to full and make them flex too to allow vertical positioning of their content (they are already set to inline-block:
html, body{
margin: 0 ;
padding: 0 ;
width: 100% ;
height: 100% ;
}
.titlebar {
display: flex;
position: relative;
border: 1px solid black ; /* for reference*/
top: 0;
left: 0;
justify-content: space-between;
height: 3rem;
flex-direction: row;
}
.window-button,
.back-button {
font-size: 12pt;
font-weight: lighter;
-webkit-app-region: no-drag;
-webkit-font-smoothing: antialiased;
text-rendering: geometricPrecision;
height: 100%;
display: inline-flex !important;
align-items: center;
}
.window-button {
padding-left: 15px;
padding-right: 15px;
}
.back-button {
padding-left: 17px;
padding-right: 17px;
}
#restore {
transform: rotate(180deg);
}
.window,
.navigation {
display: flex;
align-items: center;
}
.normal:hover {
background-color: rgba(0,0,0,0.2);
}
.danger:hover {
background-color: red;
color: white;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="titlebar">
<div class="navigation">
<a class="back-button normal material-icons">arrow_back</a>
<span class="apptitle">Electron-App</span>
</div>
<div class="window">
<a class="window-button normal material-icons">remove</a>
<a *ngIf="showMaximizeButton ; else showRestore" class="window-button normal material-icons">crop_square</a>
<!-- <ng-template #showRestore>
<a class="window-button normal material-icons" id="restore">flip_to_front</a>
</ng-template> -->
<a class="window-button danger material-icons">clear</a>
</div>
</div>
You could make the anchor tags use display: flex:
.titlebar a,
.window a {
height: 100%;
display: flex;
align-items: center;
}
Here's the working snippet:
html, body{
margin: 0 ;
padding: 0 ;
width: 100% ;
height: 100% ;
}
.titlebar {
display: flex;
position: relative;
border: 1px solid black ; /* for reference*/
top: 0;
left: 0;
justify-content: space-between;
height: 3rem;
flex-direction: row;
}
.titlebar a,
.window a {
height: 100%;
display: flex;
align-items: center;
}
.window-button,
.back-button {
font-size: 12pt;
font-weight: lighter;
-webkit-app-region: no-drag;
-webkit-font-smoothing: antialiased;
text-rendering: geometricPrecision;
}
.window-button {
padding-left: 15px;
padding-right: 15px;
}
.back-button {
padding-left: 17px;
padding-right: 17px;
}
#restore {
transform: rotate(180deg);
}
.window,
.navigation {
display: flex;
align-items: center;
}
.normal:hover {
background-color: rgba(0,0,0,0.2);
}
.danger:hover {
background-color: red;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="titlebar">
<div class="navigation">
<a class="back-button normal material-icons">arrow_back</a>
<span class="apptitle">Electron-App</span>
</div>
<div class="window">
<a class="window-button normal material-icons">remove</a>
<a *ngIf="showMaximizeButton ; else showRestore" class="window-button normal material-icons">crop_square</a>
<!-- <ng-template #showRestore>
<a class="window-button normal material-icons" id="restore">flip_to_front</a>
</ng-template> -->
<a class="window-button danger material-icons">clear</a>
</div>
</div>