Slightly off center using flexbox - css

I have a navigation bar which has 5 links on it (including the title) and I have an image below it. The navigation bar and image below are completely separate and are both centered using flexbox. The issue I am having is that the image appears to be slightly off center (although it could possibly be the navigation bar is slightly off center) and I can;t figure out why?
Here is the Image view html:
<div class="image-container">
<img class="image-full-view" [ngStyle]="{'height': selectedImage.heightSize , 'width': selectedImage.widthSize}" [src]="selectedImage.imagePath" alt="Man Praying">
</div>
The image view CSS:
.image-full-view {
padding: 0px;
margin-top: 0px;
-webkit-transform: scale(1.5);
-moz-transform: scale(1.5);
-ms-transform: scale(1.5);
-o-transform: scale(1.5);
transform: scale(1.5);
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.9999619230641713, M12=-0.008726535498373935, M21=0.008726535498373935, M22=0.9999619230641713,SizingMethod='auto expand');
}
.image-container {
display: flex;
align-items: center;
justify-content: center;
height: 90vh;
margin-top: 15px;
}
.image-name-container {
position: relative;
text-align: center;
top: 85px;
}
This is the nav bar html:
<header>
<nav>
<ul class="nav-links">
<li><a routerLink="gallery-list" class="twoSec">Gallery</a></li>
<li><a routerLink="albums" class="oneSec">Albums</a></li>
<li><a routerLink="gallery-list" class="navbar-title">BAILEY PHOTOGRAPHY</a></li>
<li><a routerLink="favourites" class="oneSec">Favourites</a></li>
<li><a routerLink="cart" class="twoSec">Cart</a></li>
</ul>
</nav>
</header>
The nav bar CSS:
* {
margin: 0px;
padding: 0px;
padding-bottom: 30px;
font-size: 22px;
color: black;
font-family: 'Lato', sans-serif;
}
.navbar-title {
font-size: 140%;
text-decoration: none !important;
display: flex;
justify-content: center;
border: black solid 2px;
width: 405px;
margin-top: 25px;
color: black;
font-weight: 500;
transition: transform 0.2s, background-color 0.5s, color 0.5s;
}
.navbar-title:hover {
background-color: black;
color: white;
transform: scale(1.1);
}
.nav-links {
display: flex;
justify-content: space-around;
align-items: center;
list-style: none;
padding-bottom: 30px;
}
.nav-links a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
}
nav {
overflow: hidden;
background-color: white;
position: fixed;
top: 0;
width: 100%;
}

Related

How to Center a Row of 3 Icons in the Middle of a Popup Modal?

I am having trouble centering a row of 3 social media icons in the middle of my popup modal and have it actually be responsive.
My failed method is adjusting the icons' "left" property by individual percentages..
Every time I think I have it centered, I test it out on a different screen size and it's too much to the right or too much to the left.
<section class="popup-modal">
<div class="popup-box">
<div class="popup-image-container">
<div class="popup-img">
</div>
</div>
<div class="popup-content">
<div class="popup-close">×</div>
<h1>FOLLOW US ON SOCIAL MEDIA</h1>
<p>#gravitasdesign</p>
<h3>Learn about our current and upcoming projects.</h3>
<i id="popup-facebook" class="bi bi-facebook"></i>
<i id="popup-instagram" class="bi bi-instagram"></i>
<i id="popup-linkedin" class="bi bi-linkedin"></i>
</div>
</div>
</section>
.popup-modal{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1099;
background-color: rgba(0, 0, 0, 0.8);
visibility: hidden;
opacity: 0;
transition: all 0.5s ease;
}
.popup-modal.show {
visibility: visible;
opacity: 1;
}
.popup-box {
background-color: #fff;
width: 750px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
border-radius: 2.5px;
}
.popup-image-container{
flex: 0 0 50%;
max-width: 50%;
position: relative;
overflow: hidden;
}
.popup-img {
position: absolute;
width: 100%;
height: 100%;
background-image: url(images/popupmodal.jpg);
background-size: cover;
background-position: left;
animation: zoomInOut 50s linear infinite;
}
#keyframes zoomInOut{
0%,100%{
transform: scale(1);
}
50%{
transform: scale(1.2);
}
}
.popup-content {
flex: 0 0 50%;
max-width: 50%;
padding: 30px;
}
.popup-content h1{
font-family: interstate, sans-serif;
font-weight: 700;
font-style: normal;
font-size: 36px;
text-align: center;
line-height: 55px;
word-spacing: 4px;
color: #300600;
}
.popup-content h3{
font-family: interstate, sans-serif;
font-weight: 500;
font-style: normal;
font-size: 24px;
text-align: center;
line-height: 40px;
color: #300600;
padding-bottom: 35px;
}
.popup-content p {
font-family: 'interstate', sans-serif;
font-weight: 700;
padding-top: 30px;
padding-bottom: 35px;
text-align: center;
font-size: 28px;
line-height: 42.5px;
color: #300600;
}
#popup-facebook, #popup-instagram, #popup-linkedin{
position: relative;
left: 9.5%;
font-size: 32px;
margin-right: 24px;
margin-left: 24px;
transition: 0.2s ease-in-out;
}
#popup-facebook{
color: #4267B2;
}
#popup-linkedin{
color: #0077b5;
}
#popup-instagram {
color: #0077b5;
}
.popup-close {
font-size: 32px;
position: absolute;
left: 96%;
top: 1%;
cursor: pointer;
transition: 0.2s ease-in-out;
color: #300600;
}
Here you can try this logic
#popup-facebook,
#popup-instagram,
#popup-linkedin {
position: relative;
left: 9.5%;
font-size: 32px;
margin-right: 24px;
margin-left: 24px;
transition: 0.2s ease-in-out;
}
#popup-facebook {
color: #4267b2;
}
#popup-linkedin {
color: #0077b5;
}
#popup-instagram {
color: #0077b5;
}
.popup-close {
font-size: 32px;
position: absolute;
left: 96%;
top: 1%;
cursor: pointer;
transition: 0.2s ease-in-out;
color: #300600;
}
.popup-content {
display: flex;
flex-direction: column;
}
.icons-box {
display: flex;
justify-content: center;
}
<section class="popup-modal">
<div class="popup-box">
<div class="popup-image-container">
<div class="popup-img"></div>
</div>
<div class="popup-content">
<div class="popup-close">×</div>
<h1>FOLLOW US ON SOCIAL MEDIA</h1>
<p>#gravitasdesign</p>
<h3>Learn about our current and upcoming projects.</h3>
<div class="icons-box">
<i id="popup-facebook" class="bi bi-facebook"></i>
<a href="#">
<i id="popup-instagram" class="bi bi-instagram"></i
></a>
<i id="popup-linkedin" class="bi bi-linkedin"></i>
</div>
</div>
</div>
</section>
:
Any particular reason why you are not using display: flex to center the icons? I would create a div container to hold the icons and set that to display: flex; with justify-content: center; (or you can play around other justify-content values to match your expected output).

Vertical line below rotated text

I wanted to have a vertical line below a rotated text, but the behaviour I am attaining with my code is that the line starts at the center of the text.
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
}
.email::after {
content: "";
width: 1px;
height: 5rem;
background: red;
}
<div class="email">
test#mail.com
</div>
Following is an image of my actual output:
How can I have the line below the rotated text?
You can add transform: rotate(90deg); also to the pseudo-element (and maybe also add some margin to create a bit of a distance to the text.
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
}
.email::after {
content: "";
width: 1px;
height: 5rem;
background: red;
transform: rotate(90deg);
margin-top: 0.5rem;
}
<div class="email">
test#mail.com
</div>
(Note: Use full page mode to view the example, otherwise you won't see the text.)
writing-mode: vertical-rl; you can achieve this. for more information visit this.
:root {
--height-for-line: 60px;
}
.email {
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}
.email a {
color: white;
text-transform: none;
writing-mode: vertical-rl;
background-color: blue;
padding: 12px;
position: relative;
}
.email a::after {
content: "";
position: absolute;
height: calc(var(--height-for-line) - 15px);
width: 2px;
bottom: 5px;
right: 50%;
transform: translateX(-50%);
background-color: red;
}
<div class="email">
test#mail.com
</div>
Border as pseudo element. (the one you tried in question post)
(I would suggest using the text-decoration or border-bottom solution under this code snippet.)
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
}
.email::after {
content: "";
width: 1px;
height: 6.2rem;
background: red;
transform: translateY(-60%);
margin-right: 15px;
}
<div class="email">
test#mail.com
</div>
Solution with text-decoration: underline;
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
text-decoration: underline;
-webkit-text-decoration-color: red; /* Safari */
text-decoration-color: red;
}
<div class="email">
<u>test#mail.com</u>
</div>
Solution using border-bottom
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
border-bottom: 1px solid red;
}
<div class="email">
<u>test#mail.com</u>
</div>
I wanted to have a vertical line below a rotated text
I've shifted things around for you a little:
I've applied the ::after pseudo-element to the <a> element
I've swapped dimensions of the ::after pseudo-element so that it represents a horizontal (rather than a vertical) line
I've applied transform: rotate(90deg); to .email (rather than .email a)
Working Example
.email {
position: fixed;
top: 0;
left: 3em;
transform: rotate(90deg);
transform-origin: 0 0;
}
.email a {
font-weight: 300;
font-size: 1rem;
}
.email a::after {
content: '';
display: inline-block;
width: 5rem;
height: 1px;
background: red;
}
<div class="email">
test#mail.com
</div>
Instead of a pseudo, you could use box-shadow
(inset to work better with transform)
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
box-shadow: inset 0 -1px 0 0 red;
padding-bottom: 1rem;
}
<div class="email">
test#mail.com
</div>

Getting SVG plus symbol to appear to the right of tab, not the right of the containing div

So I've got a problem where I've got two tabs (https://codepen.io/databell/pen/LYjxvyx) where the first tab opens up content and the second opens up a modal.
Now to be clear, those functions work. That's not the issue. So for those purposes, I deleted those out of my example. Focusing on CSS here.
My problem is I want plus + symbols to appear to the right side of each tab (really a div) and instead one tab has the symbol to the far right of the container, even though the tab is set to width 100%. So I'm stumped as to what the problem is.
This is meant to go into a Shopify store using the Dawn theme, so I'm using their elements here to create this interface.
Here's the code.
<div id="info-additions" class="product__accordion accordion info-additions-content" >
<details>
<summary>
<div class="summary__title info-additions-tab g-flex">
<h2 class="h4 accordion__title t-body benefits">
Tab One
<span></span>
</h2>
</div>
<div class="summary__title info-additions-tab g-flex">
<modal-opener class="product-popup-modal__opener no-js-hidden" data-modal="#PopupModal-ingr">
<button id="ProductPopup-ingr" class="summary__title t-body ingredients" type="button" aria-haspopup="dialog" data-additions-tab="ingredients">
<h2 class="h4 accordion__title">
Tab Two
<span></span>
</h2>
</button>
</modal-opener>
</div>
</summary>
<div class="accordion__content rte">
<p>Content</p>
</div>
</details>
</div>
CSS:
body {
font-size: 1.6rem;
}
*, ::before, ::after {
box-sizing: inherit;
}
.h0, .h1, .h2, .h3, .h4, .h5, h1, h2, h3, h4, h5 {
letter-spacing: .06rem;
line-height: 1.3;
}
.h4, h4 {
font-size: 1.6rem;
}
.grid {
list-style: none;
}
.g-flex {
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
}
.accordion summary {
cursor: pointer;
display: flex;
position: relative;
list-style: none;
line-height: 1;
padding: 1.5rem 0;
}
.accordion__title {
display: inline-block;
max-width: calc(100% - 6rem);
min-height: 1.6rem;
margin: 0;
word-break: break-word;
}
details > * {
box-sizing: border-box;
}
.accordion__title {
word-break: break-word;
}
.accordion .summary__title {
display: flex;
flex: 1;
}
#info-additions {
clear: both;
height: auto;
margin: 15px 0 0;
border-top: 2px solid;
border-bottom: 2px solid;
width: 100%;
}
.info-additions-content {
position: relative;
height: 0;
transition: .6s var(--a-cubic-1);
}
.info-additions-tab {
justify-content: space-between;
}
.info-additions-tab span {
display: block;
position: absolute;
width: 18px;
height: 18px;
top: 13px;
right: 2rem;
}
.info-additions-tab button {
position: relative;
padding: 16px 0!important;
line-height: 1;
font-weight: 500;
text-align: left;
}
.info-additions-tab button.benefits {
width: 50%;
}
.info-additions-tab .product-popup-modal__opener {
width: 100% !important;
}
.info-additions-tab button.ingredients {
width: 100%;
}
.info-additions-tab span {
display: block;
position: absolute;
width: 18px;
height: 18px;
top: 13px;
right: 2rem;
}
.info-additions-tab span:before,
.info-additions-tab span:after {
content: '';
display: block;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%) rotate(90deg);
transform: translate(-50%, -50%) rotate(90deg);
width: 2px;
height: 18px;
background-color: black;
transition: 0.3s;
}
.info-additions-tab button:not(.active) span:after {
-webkit-transform: translate(-50%, -50%) rotate(180deg);
transform: translate(-50%, -50%) rotate(180deg);
}
.info-additions-content {
position: relative;
height: 0;
transition: 0.6s var(--a-cubic-1);
}
.info-additions-content [data-additions-content] {
position: absolute;
width: 100%;
top: 0;
left: 0;
padding: 5px 0 20px;
opacity: 0;
pointer-events: none;
transition: 0.3s 0s;
}
.info-additions-content [data-additions-content].active {
opacity: 1;
pointer-events: auto;
transition-delay: 0.4s;
}
#info-additions button {
padding: 0;
background: transparent;
color: inherit;
cursor: pointer;
border: 0;
border-radius: 0;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
transition: 0.2s;
}
if you want an absolute element like + to stay in the parent element you have to set the position of the parent to "relative".
you have two problems. summary__title doesn't have a position so + doesn't stay in it .
for the second tab, your modal button has a relative position that makes the + stay inside of it instead of the summary__title.
.accordion .summary__title {
...
position: relative; // add position
}
#info-additions button {
...
position: unset; // unset the position of the button
}

Z-index not rendering properly in Safari - works in all other browsers

I have a nav menu that slides into view from the right side of the screen once the hamburger icon is clicked. It works correctly in Chrome and Firefox - basically when triggered it takes up 50vw and fills the screen vertically. However in Safari it seems as if the z-index is not behaving correctly because the menu appears to be buried underneath the other elements of the page and ultimately not visible at all.
I've tried adjusting the z-index of a variety of elements to see if that was the simple fix and it has proven to be something more complicated. I have read a few forums that suggested including "-webkit-transform: translate3d(0, 0, 0);" but unfortunately that doesnt seem to work either. If you inspect the sidebarMenu element in Safari you can see that it is in the correct position, it is just not rendering correctly.
Below is a link to a codepen - I am missing some styles on this so the positioning isnt quite right but it effectively shows the general functionality that I am looking for. When opening this link in Safari you can see that the sidebarMenu does not appear to be rendering at all.
https://codepen.io/rmann20/pen/EzbeaV
sample code:
<div class="header">
<hr class="nav-rule">
<div class="nav-container">
<div class="nav-logo-container">
<img class="nav-logo" src="images/nav_logo.png">
<input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
<div class="spinner diagonal part-1"></div>
<div class="spinner horizontal"></div>
<div class="spinner diagonal part-2"></div>
</label>
<div id="sidebarMenu">
<ul class="sidebarMenuInner">
<li>Rooms & Suites</li>
<li>Packages</li>
<li>Eat & Drink</li>
<li>Meetings & Events</li>
<li>Weddings</li>
<li>Experiences</li>
<li>Neighborhood</li>
</ul>
<ul class="sidebarMenuInnerSecondary">
<li>ABOUT</li>
<li>HISTORY</li>
<li>GALLERY</li>
<li>PRESS</li>
<li>CONTACT</li>
<li>CAREERS</li>
</ul>
</div>
</div>
<img class="nav-tagline" src="images/nav_tagline.png">
<a class="nav-reservation-button" href="" target="_blank">RESERVE NOW</a>
</div>
<hr class="nav-rule">
</div>
.header {
display: flex!important;
flex-wrap: wrap;
margin: 0;
padding: 10px 0 10px 0;
width: 100%;
max-width: 100%;
box-shadow: none;
background-color: #f5f4f0;
position: fixed;
height: 110px!important;
overflow: hidden;
z-index: 10;
justify-content: space-between!important;
}
.nav-container {
display: flex;
height: 79px;
width: 100%;
align-items: center;
justify-content: space-between;
}
.main {
margin: 0 auto;
display: block;
height: 100%;
margin-top: 60px;
}
.mainInner{
display: table;
height: 100%;
width: 100%;
text-align: center;
}
.mainInner div{
display:table-cell;
vertical-align: middle;
font-size: 3em;
font-weight: bold;
letter-spacing: 1.25px;
}
#sidebarMenu {
min-height: 100%;
position: fixed;
right: 0;
width: 50vw;
margin-top: 42px;
transform: translateX(50vw);
transition: transform 250ms ease-in-out;
background-color: #f5f4f0;
overflow: scroll;
padding: 60px 60px 60px 60px;
z-index: 10000!important;
}
.sidebarMenuInner{
margin:8px;
padding:0;
border-top: 1px solid rgba(255, 255, 255, 0.10);
list-style: none;
}
.sidebarMenuInner li a{
color: #3d3936;
font-family: 'QuincyCF-ExtraBold', Helvetica, Arial, Sans-Serif;
font-weight: normal;
font-style: normal;
cursor: pointer;
text-decoration: none;
font-size: 3.2em;
}
.sidebarMenuInnerSecondary {
margin-top: 60px;
list-style: none;
}
.sidebarMenuInnerSecondary li {
margin-top: 14px;
margin-bottom: 14px;
}
input[type="checkbox"]:checked ~ #sidebarMenu {
transform: translateX(0);
}
input[type=checkbox] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
.sidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 48px;
right: 40px;
height: 28px;
width: 28px;
}
.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3px;
width: 100%;
background-color: #3d3936;
}
.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.diagonal.part-1 {
position: relative;
transition: all 0.3s;
box-sizing: border-box;
float: left;
}
.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -9px;
}
.nav-logo-container {
width: 260px;
margin-left: 40px;
}
I dont get any errors and everything else seems to be working correctly, can't figure out why it's not showing at this point. Any help would be greatly appreciated!

css background-color in custom shape

I want to make background like in photo, but without image. I want with only "background-color" like background in "About us" link
You can achieve that using CSS transform: with value skew();
* {
margin: 0 auto;
padding: 0;
}
ul {
display: block;
width: auto;
margin-top: 60px;
background-color: blue;
height: 45px;
font-family: calibri;
font-weight: bold;
text-align: center;
}
li {
display: inline-block;
line-height: 45px;
padding: 0 25px 0 25px;
background-color: orange;
font-size: 24px;
transform: skew(20deg); /* To Achieve the Slanted border */
margin-right: -3px;
}
li a {
color: white;
display: block;
transform: skew(-20deg); /* To straighten up the text */
}
<ul>
<li><a href"#">About</a></li>
</ul>
Click here for a full tutorial on how you can do that.
It looks like you are looking for a parallellogram or rhombus. To do this you can use transform: skew
#about {
width: 120px;
height: 20px;
-webkit-transform: skew(20deg);
-moz-transform: skew(20deg);
-o-transform: skew(20deg);
background: blue;
color: white;
font-size: 20px;
padding-bottom: 5px;
text-align: center;
margin-left: 20px;
}
<div id="about">About us</div>

Resources