Problem with flex-box vertical align middle (align-items: center) - css

I'd like the navigation arrows to align vertically middle.
On the live site they are off-center.
There is compromising CSS I can't change which sets a top: 40% for the arrows (.owl-nav button).
I've tried unseting their top, but this pushes them to underneath the image.
I've tried setting top: calc(50% - 37.5px); (minus half the button's height of 75px) but this is off-center. Is my math right here?
I've been able to get it working below by using a fixed height for .owl-nav.pp-carousel-nav but on the live page the .owl-items are not of fixed width and height, they are responsive.
.owl-carousel .owl-stage {
position: relative;
}
.pp-content-post-carousel {
position: relative;
}
.landscape-carousel-container {
width: 100%;
}
.landscape-carousel-content {
width: 100%;
}
.landscape-carousel-overlay {
position: absolute;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 100%;
height: 236px;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
opacity: 0;
transition: .4s ease !important;
border-radius: 15px;
background-color: #22a1d9;
}
.landscape-carousel-img {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
height: 236px;
margin-bottom: 10px;
padding-bottom: 0px;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: rgba(14,34,129,0);
background-image: url("https://cdn-ehbod.nitrocdn.com/MnwLQZiWrxfKgQoPapfeSJHycGHMrPjW/assets/static/optimized/rev-315e7f6/img/background-image.svg");
background-position: 50% 50%;
background-size: cover;
background-repeat: no-repeat;
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
cursor: pointer;
border-radius: 15px;
border: 3px solid #dfefef;
}
.owl-nav.pp-carousel-nav {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
height: 242px;
width: 370px;
position: absolute;
top: 10px;
}
.owl-nav button {
position: absolute;
line-height: 1;
margin: 0;
font-size: 20px;
background: none !important;
z-index: 1;
border: none;
background-color: transparent;
}
.owl-nav button.owl-prev {
left: -15px;
}
.owl-nav button.owl-next {
right: -15px;
}
.owl-nav button svg {
width: 51px;
height: 51px;
color: white;
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
}
.sr-only {display: none;}
<div class="owl-item cloned" style="width: 370px;">
<div class="pp-content-post pp-content-carousel-post pp-grid-custom post-6474 templates type-templates status-publish hentry templatecategory-hospitality templatecategory-landscape-liquor-hospitality-2 templatecategory-liquor" itemscope="" itemtype="https://schema.org/CreativeWork" data-id="6474" style="visibility: visible; height: 269.2px;">
<div class="landscape-carousel-container">
<div class="landscape-carousel-content">
<div class="landscape-carousel-overlay">
Edit this Template </div>
<div style="background-image: url("https://cdn-ehbod.nitrocdn.com/MnwLQZiWrxfKgQoPapfeSJHycGHMrPjW/assets/static/optimized/rev-315e7f6/wp-content/uploads/2021/06/landscape_Hospitality_Liquor_001.jpg");" class="landscape-carousel-img lazyloaded" nitro-lazy-bg="https://cdn-ehbod.nitrocdn.com/MnwLQZiWrxfKgQoPapfeSJHycGHMrPjW/assets/static/optimized/rev-315e7f6/wp-content/uploads/2021/06/landscape_Hospitality_Liquor_001.jpg"></div>
<div>Liquor Store - Many Bottles</div>
</div>
</div>
</div>
</div>
<div class="owl-nav pp-carousel-nav">
<button type="button" role="presentation" class="owl-prev">
<svg aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512">
<path fill="currentColor" d="M25.1 247.5l117.8-116c4.7-4.7 12.3-4.7 17 0l7.1 7.1c4.7 4.7 4.7 12.3 0 17L64.7 256l102.2 100.4c4.7 4.7 4.7 12.3 0 17l-7.1 7.1c-4.7 4.7-12.3 4.7-17 0L25 264.5c-4.6-4.7-4.6-12.3.1-17z" class=""></path>
</svg>
<span class="sr-only">Previous</span>
</button>
<button type="button" role="presentation" class="owl-next">
<svg aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512">
<path fill="currentColor" d="M166.9 264.5l-117.8 116c-4.7 4.7-12.3 4.7-17 0l-7.1-7.1c-4.7-4.7-4.7-12.3 0-17L127.3 256 25.1 155.6c-4.7-4.7-4.7-12.3 0-17l7.1-7.1c4.7-4.7 12.3-4.7 17 0l117.8 116c4.6 4.7 4.6 12.3-.1 17z" class=""></path>
</svg>
<span class="sr-only">Next</span>
</button>
</div>

Here the answer as stated in the comment:
The problem is caused by the navigation elements parent box. It also includes the text below - therefore, you don't center it relative to the image, but to the image & its descriptive text. As you probably cannot change the html structure here I suggest you simply change the css calculation by to something like
top: calc(50% - 45px);

The height of the button is 66px and positions in relation to the div with class="pp-content-post-carousel pp-equal-height clearfix" which is 33.19px taller than the images.

Related

css not working when trying to center self

I'm trying to make an item center,but somehow it not work
Here is html part:
<div>
<div className={styles.unanswerQuestionContainer}>
<div className={styles.headerContainer}>
<div>Unanswered Questions</div>
<div>Answered Questions</div>
</div>
</div>
</div>
Here is css part:
.unanswerQuestionContainer {
height: 60vh;
width: 60vw;
border: 1px solid;
display: flex;
margin: 20px 0 0 0;
align-self: center;
}
.headerContainer {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
But it show something like this:
It do not center the div, how can i center this ??
Edit: When i try to inspect then it show all of this is margin:
You need to add following style to outer div(parent) unanswerQuestionContainer
display: flex;
justify-content: center;
align-items: center;
height: 100%;
body{
height: 100vh;
margin: 0;
}
.unanswerQuestionContainer {
height: 60vh;
width: 60vw;
border: 1px solid;
display: flex;
margin: 20px 0 0 0;
align-self: center;
}
.headerContainer {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
.outer{
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
<div class="outer">
<div class="unanswerQuestionContainer">
<div class="headerContainer">
<div>Unanswered Questions</div>
<div>Answered Questions</div>
</div>
</div>
</div>
You will have to adjust which css properties you will use in order to prevent the two h1 from overlapping.
<div className={styles.unanswerQuestionContainer}>
<div class="Questions">
<p id="question-type">Answered Question</p>
<p id="question-type">Unanswered Question</p>
</div>
</div>
.questions h1 {
width: 100px;
height: 100px;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}

Problems with css menu styles

I am really new to working on this, the problem I have is two
What I am trying to do is give it to show the menu as shown in the following image:
I can not put the option that was selected underlined, and so that the displayed menu is horizontal, what I have is this:
Searching the web I have not found anything to solve it or something to take an example to solve my problem, I am working with CSS and Vue.Js, if someone can tell me how to solve this
Underline the selected menu and see the menu displayed horizontally
My Code:
<div class="panel-group" id="accordion-mbl-menu">
<div class="panel">
<b-navbar-toggle target="collapse-cat-lvl1-469">
Accesorios
<img src="#/assets/images/layout/menu/chevron.svg" class="icon">
</b-navbar-toggle>
<div style="background-color:white;">
<b-collapse id="collapse-cat-lvl1-469">
<div data-cat-acc="473" class="grid-item parent-lvl-2">
<a class="link -1 grid-sty-1" href="#" target="_self" data-menu-item-id="473">
<span class="text">GTI</span>
</a>
</div>
...
(other menu options)
...
</b-collapse>
</div>
</div>
<div class="panel">
<button type="button" class="navbar-toggler collapsed"> ¿Necesitas ayuda? </button>
</div>
</div>
My code CSS
#media (max-width: 828px) {
#menu-header.show {
-webkit-transform: translateX(0);
-ms-transform: translateX(0);
transform: translateX(0);
}
#menu-header {
display: block ;
position: fixed;
z-index: 1;
background-color: #FFF;
left: 0;
top: 100px;
height: -webkit-calc(100% - 50px);
height: -moz-calc(100% - 50px);
height: calc(100% - 50px);
width: 90%;
padding: 20px 20px;
max-width: 87.5%;
transform: translateX(-100%);
transition: transform 650ms ease;
.grid-sty-1 {
height: 55px;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: -moz-box;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
-moz-box-align: center;
align-items: center;
height: 40px;
font-size: 16px;
font-family: "VWHead-Bold", sans-serif;
position: relative;
a{
text-decoration: none;
outline: none !important;
padding-right: 15px;
position: relative;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
}
> .text {
padding-left: 15px;
color: #001E50;
}
}
.navbar-greetings{
font-family: 'VWHead-Regular';
font-size: 24px;
line-height: 29px;
display: flex;
align-items: center;
color: #001E50;
}
#accordion-mbl-menu {
margin: 0;
.panel {
box-shadow: none !important;
background-color: transparent;
border-radius: 0;
border: 0;
margin-bottom: 0;
> button.collapsed {
color: #001e50;
> .icon{
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
}
> button.not-collapsed > .icon {
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
> button {
margin: 0px;
padding: 0px;
width: 100%;
height: 55px;
font-size: 20px;
font-family: "VWHead-Bold";
font-weight: normal;
color: #2f3538;
text-decoration: none;
outline: none !important;
border-bottom: 1px solid #dee1e3;
padding-right: 15px;
position: relative;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
> .icon {
width: 20px;
height: 20px;
fill: currentColor;
-webkit-transition: all 350ms ease;
transition: all 350ms ease;
position: absolute;
right: 15px;
top: auto;
}
.collapse.in {
display: block;
}
}
}
}
}
}
Any way to style this?
To show underline on hover
.class:hover {
text-decoration: underline;
}
To display horizontal
.container {
display: flex;
flex-direction: row;
}

CSS unable to align vert/horz an img positioned in absolute

I have the following issue, where I want to move the logo to the position shown in the picture
Im able to move the image around using properties like:
.img-logo{
display:flex;
position: absolute;
text-align: center;
align-items: center;
justify-content: center;
left: 50%
}
But the point is, those are not exact values, I dont know how to do it with exact values
Because if I use
.img-logo{
display:flex;
position: relative;
text-align: center;
align-items: center;
justify-content: center;
}
The image wont even move
The htlm is like this
<div class="main">
<form class='login-form' onSubmit={this.handleSubmit}>
<img alt="image" src={brand} width="60" height="60" class="img-logo"/>
<p class='lf--upper-text' >Welcome to app</p>
<div class="flex-row">
<label class="lf--label" htmlFor="email">
<svg x="0px" y="0px" width="12px" height="13px">
where .main
.main { height: 100%; }
.main {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: relative;
and .login-form
.login-form {
width: 100%;
padding: 2em;
position: relative;
background: white;
border-radius: 30px;
#media screen and (min-width: 600px) {
width: 50vw;
max-width: 15em;
}
}
Fixed it
<div class="flex-row img-logo">
<img src={brand} width="60" height="60" class="img-logo-in" />
</div>
css
.img-logo{
display:flex;
position: relative;
text-align: center;
align-items: center;
justify-content: center;
bottom: 20%
}
.img-logo-in{
position:absolute;
left:50%;
transform:translate(-50%); }

Caption centered and at the bottom of a background

I'm a React beginnerCan you explain me how to place a .herogroup (composed by h1, p and a button) in the middle and 20px far away from the bottom of a background (belonging to .Hero)?
<div>
<div className="Hero">
<div className="HeroGroup">
<h1>ABC</h1>
<p>ABC</p>
<Link to="ABC">ABC</Link>
</div>
</div>
CSS
.Hero {
height: 1920px;
background-image: url('../images/abc.jpg');
background-size: cover;}
.HeroGroup{
max-width: 500px;
margin: 0 auto;
padding: 150px 50px;
text-align: center;}
I have used css flex. Which is more convenient to achieve your case than using position absolute.
.Hero {
height: 1920px;
background-image: url('../images/abc.jpg');
background-size: cover;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.HeroGroup{
max-width: 500px;
margin: 0 auto;
padding: 20px 0px;
display: flex;
/* flex-wrap: wrap; */
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
<div>
<div class="Hero">
<div class="HeroGroup">
<h1>ABC</h1>
<p>ABC</p>
<Link to="ABC">ABC</Link>
</div>
</div>
In your .HeroGroup class do this
.HeroGroup {
max-width: 500px;
padding: 150px 50px;
margin: 0 auto;
text-align: center;
position: absolute;
bottom: -20px;
}

Firefox CSS position unpredictable behaviour

I have same HTML/CSS code working different in Chrome or Safari versus Firefox.
But Firefox also works sometimes.
For instance, if you resize the codepen window, inspect or make a change to the label of the input in Firefox, it behaves correct and then incorrect again.
Codepen Example
body {
overflow: hidden;
padding: 20px;
}
div, input {
box-sizing: border-box;
}
form {
display: flex;
flex-flow: column nowrap;
justify-content: space-around;
width: 100%;
padding: 40px 0px;
z-index: 10;
flex: 1 1 0%;
font-size: 16px;
}
.my-field {
display: flex;
flex-flow: column nowrap;
width: 100%;
font-size: 18px;
align-items: flex-start;
margin: 15px 0px;
}
.label-wrap {
display: flex;
align-items: center;
position: relative;
font-size: 0.85em;
margin-bottom: 5px;
width: 100%;
}
.label {
flex: 1;
}
.input-wrap {
display: flex;
position: relative;
width: 100%;
align-items: center;
}
.icon-wrap {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
z-index: 10;
padding: 6px;
position: absolute;
left: 0px;
margin-left: 2px;
}
.my-input {
display: flex;
position: relative;
width: 100%;
border-radius: 5px;
}
input {
width: 100%;
height: 48px;
line-height: 38px;
padding-left: 40px;
padding-right: 44px;
font-size: 1em;
text-align: inherit;
font-family: inherit;
border: 1px solid rgb(204, 204, 204);
resize: none;
}
<form>
<div class="my-field">
<div class="label-wrap">
<div class="label">
<span>Change this labe</span>
</div>
</div>
<div class="input-wrap">
<div class="icon-wrap">
<svg viewBox="0 0 24 24" width="100%" height="100%">
<g>
<path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"></path>
</g>
</svg>
</div>
<div class="my-input">
<input name="name" placeholder="Or resize codepen layout" autocomplete="off" spellcheck="false" type="text">
</div>
</div>
</div>
</form>
Inside Stack Overflow Chrome vs Firefox comparison
In Chrome:
In Firefox:
In Safari:
Any tip on how manage this in a safe way is welcome, thanks.
To make it work on every browser, you can remove
display: flex;
align-items: center;
justify-content: center;
on the icon-wrap div and add
top: 50%;
transform: translateY(-50%);
So you will vertically align the icon only with the absolute position.
This solution should work on Chrome, Safari & Firefox :)
body {
overflow: hidden;
padding: 20px;
}
div, input {
box-sizing: border-box;
}
form {
display: flex;
flex-flow: column nowrap;
justify-content: space-around;
width: 100%;
padding: 40px 0px;
z-index: 10;
flex: 1 1 0%;
font-size: 16px;
}
.my-field {
display: flex;
flex-flow: column nowrap;
width: 100%;
font-size: 18px;
align-items: flex-start;
margin: 15px 0px;
}
.label-wrap {
display: flex;
align-items: center;
position: relative;
font-size: 0.85em;
margin-bottom: 5px;
width: 100%;
}
.label {
flex: 1;
}
.input-wrap {
display: flex;
position: relative;
width: 100%;
align-items: center;
}
.icon-wrap {
/* Remove this */
/* display: flex; */
/* align-items: center; */
/* justify-content: center; */
width: 40px;
height: 40px;
z-index: 10;
padding: 6px;
position: absolute;
left: 0px;
margin-left: 2px;
/* Add this */
top: 50%;
transform: translateY(-50%);
}
.my-input {
display: flex;
position: relative;
width: 100%;
border-radius: 5px;
}
input {
width: 100%;
height: 48px;
line-height: 38px;
padding-left: 40px;
padding-right: 44px;
font-size: 1em;
text-align: inherit;
font-family: inherit;
border: 1px solid rgb(204, 204, 204);
resize: none;
}
<form>
<div class="my-field">
<div class="label-wrap">
<div class="label">
<span>Change this labe</span>
</div>
</div>
<div class="input-wrap">
<div class="icon-wrap">
<svg viewBox="0 0 24 24" width="100%" height="100%">
<g>
<path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"></path>
</g>
</svg>
</div>
<div class="my-input">
<input name="name" placeholder="Or resize codepen layout" autocomplete="off" spellcheck="false" type="text">
</div>
</div>
</div>
</form>

Resources