I'm creating a dropdown menu with CSS, it different options depending on the page it could be 1 or 2 options, I will share the css code. My issue is why the position of the tooltip dialog changed depending on how many options do we have:
This is how it looks like with two options:
This is how it looks like with 1 option:
As you can see the position change according with the number of options, here is the code:
.container {
display: flex;
width: auto;
height: auto;
position: relative;
justify-content: center;
}
.tooltip {
min-width: 10rem;
width: auto;
min-height: 2rem;
height: auto;
background-color: var(--app-secondary-color);
text-align: center;
position: absolute;
z-index: 1;
font-size: 1.2rem;
display: flex;
justify-content: flex-start;
padding: 1rem;
flex-direction: column;
box-shadow: 0 0.3rem 1.2rem #CCC;
transform: translate(-25%, calc(40%));
border-radius: 3px;
top: 0;
}
.tooltip:before {
content: "";
position: absolute;
width: 0;
height: 0;
top: -10px;
left: calc(75% - 10px);
border-bottom: solid 5px var(--app-secondary-color);
border-left: solid 10px transparent;
border-right: solid 10px transparent;
border-top: solid 5px transparent;
}
<div class="container">
<i>Icon picture</i>
<div id="tooltipTop" class="tooltip">
<span>Option 1</span>
<span>Option 2</span>
</div>
</div>
What do you think should I changed on my css or do am I missing something?
remove calc(40%) and instead try using margin-top to fix the dropdown.
.tooltip {
margin-top: 2em;
min-width: 10rem;
width: auto;
min-height: 2rem;
height: auto;
background-color: var(--app-secondary-color);
text-align: center;
position: absolute;
z-index: 1;
font-size: 1.2rem;
display: flex;
justify-content: flex-start;
padding: 1rem;
flex-direction: column;
box-shadow: 0 0.3rem 1.2rem #CCC;
transform: translate(-25%);
border-radius: 3px;
top: 0;
}
Related
In a css/html element on a webpage I've made, if a user zooms in or out on their browser, artifacts emerge showing a line. Here is a code pen of the issue. Zoom in or out on your browser to see the red line at top emerge like below:
I've read that these problems can emerge because a browser can set the zoom to 1.5x, thus creating rounding issues for pixels. See slack post here. But I'm not sure what the appropriate fix should be. In my case I want the triangles at each end of my rectangle element which I create via css styling. Besides recreating the graphic via svg, is there any good tricks?
Here is the html/css in codepen:
#root {
display: block;
width: 100%;
height: 100%;
background-color: lightgrey;
padding: 24px;
max-width: 400px;
float: center;
position: relative;
}
#gridRoot {
display: flex;
flex-flow: column wrap;
top: 50%;
left: 50%;
align-content: center;
}
#LegendContainer {
box-sizing: border-box;
display: flex;
flex-flow: row nowrap;
width: 100%;
align-items: center;
justify-content: space-between;
}
#container {
background-color: grey;
postion: relative;
height: 120px;
justify-content: center;
left: calc(50% - 60px);
text-align: center;
top: calc(50% - 60px);
}
#circle {
transform: rotate(7.39deg);
}
#jss {
display: flex;
position: absolute;
background: red;
top: 40px;
width: 110px;
opacity: 80%;
height: 20px;
}
#jss::before {
left: 0;
width: 0;
bottom: 0;
height: 0;
content: '';
position: absolute;
transform: rotate(180deg);
border-top: 10px solid white;
border-left: 10px solid #00007f;
border-bottom: 10px solid white;
}
#jss::after {
right: 0;
width: 0;
bottom: 0;
height: 0;
content: '';
position: absolute;
border-top: 10px solid white;
border-left: 10px solid #7f0000;
border-bottom: 10px solid white;
}
<div id="root">
<div id="gridRoot">
<div id="LegendContainer">
<div id="container">
<div id="circle">
</div>
<div id="jss">
</div>
</div>
</div>
</div>
</div>
The ::before and ::after elements seemed to be causing the issue. Solution;
body {
margin: 0;
}
#container {
background-color: grey;
position: relative;
display: flex;
height: 120px;
justify-content: center;
text-align: center;
}
#jss {
display: flex;
position: absolute;
top: 40px;
width: 110px;
opacity: 80%;
height: 20px;
}
#jss-internal {
background: red;
width: 100%;
}
#jss-before {
content: '';
transform: rotate(180deg);
border-top: 10px solid white;
border-left: 10px solid #00007f;
border-bottom: 10px solid white;
}
#jss-after {
border-top: 10px solid white;
border-left: 10px solid #7f0000;
border-bottom: 10px solid white;
}
<div id="root">
<div id="LegendContainer">
<div id="container">
<div id="circle">
</div>
<div id="jss">
<div id="jss-before">
</div>
<div id="jss-internal">
</div>
<div id="jss-after">
</div>
</div>
</div>
</div>
</div>
I am building a drawer with a tag.
When the tag is clicked, the div#mySidenav will be shown.
Here is my code:
.container {
background-color: #ff0000;
/* red*/
display: flex;
flex-direction: row;
flex-grow: 1;
height: 100%;
/* 100% Full-height */
position: fixed;
/* Stay in place */
top: 0;
/* Stay at the top */
left: 0;
width: 100%;
}
.sidenav {
background-color: green;
height: 100%;
margin: 0px;
overflow-x: hidden;
/* Disable horizontal scroll */
width: 1px;
}
.sideNavTag {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
margin: 0px;
padding: 0px;
width: 20px;
}
div#tag {
align-content: center;
border: 1px solid yellow;
border-left: none;
border-radius: 0px 5px 5px 0px;
box-sizing: border-box;
cursor: pointer;
display: flex;
font-size: 20px;
justify-content: center;
left: 4.5px;
margin: 0px;
padding: 0px;
position: relative;
width: 20px;
}
div#a {
border-bottom: 1px solid yellow;
border-left: 1px solid yellow;
border-radius: 0px 0px 0px 5px;
box-sizing: border-box;
display: flex;
height: calc(50% - 10px);
margin: 0px;
position: relative;
top: 1px;
width: 20px;
}
div#c {
border-top: 1px solid yellow;
border-left: 1px solid yellow;
border-radius: 5px 0px 0px 0px;
height: calc(50% - 10px);
margin: 0px;
position: relative;
top: -1px;
width: 20px;
}
<div class="container">
<div id="mySidenav" class="sidenav">1</div>
<div class="sideNavTag">
<div id="a"></div>
<div id="tag">
▶
</div>
<div id="c"></div>
</div>
<div>3</div>
</div>
The div#a, div#tag and div#c are used to build the following layout:
How can I align center (both vertical and horizontal) the triangle in the yellow block (i.e. div#tag)?
I have used the display: flex; , align-items: center; and justify-content: center; CSS to align the triangle centre in the yellow block(i.e. div#tag). Unfortunately, it does not work.
How can I fix the problem?
I had an icon img and was trying to center it inside a card div but is somehow not working. I already tried text-align: center; and display:flex; justify-content: center; and both did not help. I attached my code below. Any help is appreciated. Thanks in advance.
* {
box-sizing: border-box;
}
.card {
background-color: #fff;
border-radius: 4px;
max-width: 0px;
height: 0px;
position: absolute;
padding: 20px;
color: #444;
cursor: pointer;
top: 3%;
right: 0.5%;
}
.card:before {
content: '';
display: block;
position: absolute;
background-color: #ccc;
left: 20px;
right: 20px;
bottom: 0;
top: 50%;
z-index: -1;
box-shadow: 0 0 40px lighten(#000, 60%);
transition: box-shadow .2s ease-in-out;
}
.card.level-1:hover:before {
box-shadow: 0 0 80px lighten(#000, 60%);
}
.card level-1 img {
display: flex;
justify-content: center;
}
<div class="card level-1">
<img src="https://img.icons8.com/windows/32/000000/microphone--v2.png" />
</div>
You should put flex on the container of the image like this:
.card {
display: flex;
justify-content: center;
align-items: center;
}
I have a parent element that is relatively positioned. I also have two absolutely positioned child elements that I want in respective corners (top left and top right). However, both of these elements won't show up in the DOM. I have explicit heights and width on both of these elements. I also tried changing the z-index of both elements to no avail.
Here is the markup and css:
.first_customer, .all_customer {
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner {
text-transform: uppercase;
width: 100%;
}
.inner > * {
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4 {
font-size: 10px;
}
.inner > h6 {
font-size: 10px;
}
.inner > p {
font-size: 10px;
}
.topleftcorner, .toprightcorner {
position: absolute;
min-width: 100px;
min-height: 100px;
}
.topleftcorner {
top: 0;
left: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>
it's working already. I just added background color and position right div.
.first_customer,.all_customer{
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner{
text-transform: uppercase;
width: 100%;
}
.inner > *{
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4{
font-size: 10px;
}
.inner > h6{
font-size: 10px;
}
.inner > p{
font-size: 10px;
}
.topleftcorner,.toprightcorner{
position: absolute;
width: 100px;
height: 100px;
background-color: #000;
}
.topleftcorner{
top: 0;
left: 0;
z-index: 2;
}
.toprightcorner {
top: 0;
right: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>
Almost there , need some changes for right corner.
.first_customer,.all_customer{
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner{
text-transform: uppercase;
width: 100%;
}
.inner > *{
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4{
font-size: 10px;
}
.inner > h6{
font-size: 10px;
}
.inner > p{
font-size: 10px;
}
.topleftcorner,.toprightcorner{
position: absolute;
min-width: 100px;
min-height: 100px;
background: red;
top: 0;
}
.topleftcorner{
left: 0;
z-index: 2;
}
.toprightcorner{
right: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>
I'm trying to create a UI element that remains centered and the image scales to the size of the container. I have additional caption and text over the image. But the image seems to scale proportionally over only some of the range when I adjust the height or width. Preferably using only CSS and HTML. The top-level div does need to be absolutely positioned. I'm indifferent to the use of flexbox. That was just one tact I've tried.
Here it is as a codepen.
And the full code is below, though it is easier to play with it in the codepen as you can adjust the results pane easily. (open up the console so you can also adjust height.)
.block {
/* this needs to remain an absolute positioned block with size and location expressed in percent */
position: absolute;
height: 80%;
width: 80%;
top: 10%;
left: 10%;
background-color: #777777;
/* Don't care if using flexbox */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
align-content: center;
text-align: center;
}
.imagecontain {
position: relative;
padding: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
align-content: center;
}
.image {
max-height: inherit;
max-width: calc(100% - 8px);
padding: 0 !important;
border: 4px solid #123456 !important;
}
.button {
border-color: #b2b2b2;
background-color: #f8f8f8;
color: #444;
position: relative;
display: inline-block;
margin: 0;
padding: 0 12px;
min-width: 52px;
min-height: 47px;
border-width: 1px;
border-style: solid;
border-radius: 2px;
vertical-align: top;
text-align: center;
text-overflow: ellipsis;
font-size: 16px;
line-height: 42px;
cursor: pointer;
box-shadow: 0px 0px 3px #888888 !important;
}
.overimage {
vertical-align: bottom;
position: absolute;
bottom: 10%;
left: 50%;
max-width: 80%;
min-width: 60%;
padding: 5px;
opacity: .7;
transform: translateX(-50%);
background-color: black;
color: white;
border-radius: 10px;
z-index: 2;
}
.name {
text-align: bottom;
background-color: white;
padding: 5px;
border: 1px solid black;
}
<div class="block">
<div class="imagecontain">
<div class="overimage">this is a test of the emergency broadcast</div>
<img class="button image" src="https://scontent-dfw1-1.xx.fbcdn.net/hphotos-xfa1/v/t1.0-9/582520_10151526852434301_1015227082_n.jpg?oh=6537667094d5a160b8fbab0728dc2f5a&oe=57971FCB">
</div>
<div class="name">Mountains</div>
</div>
Use the background-size properties in CSS. Change your image from an tag to the background of the div. The specific property you're looking for is probably
background-size: cover;
http://www.w3schools.com/cssref/css3_pr_background-size.asp
Add:
.imagecontain {
max-width: 100%;
width: 100%
}
Remove:
.block {
height: 80%;
}