I'm trying to make a tooltip for a button that can have a variable offset. I thought I had found a good solution, but something strange happens when tested in another browser. The code below (and in this fiddle) will render differently between Chromium 72.0.3626.81 and Firefox 66.0b3 (both on Arch Linux). On Chromium it displays as expected, but on Firefox the tooltip is not offset correctly. On Firefox, the margin of the actual tooltip is off by half of what it should be.
Why does this happen, and how can I keep the intended behaviour consistent between browsers?
:root {
font-size: 62.5%;
font-family: 'sans-serif';
--tooltip-offset: 50px;
}
.container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.link {
border-radius: 4px;
height: 4rem;
font-size: 1.6rem;
border: 1px solid hsl(215, 36%, 78%);
padding: 0 1.5rem;
justify-content: center;
align-items: center;
display: inline-flex;
}
.tooltip {
font-size: 1.4rem;
z-index: 2;
width: 225px;
position: absolute;
text-align: center;
padding: 0.7rem 3rem;
border-radius: 4px;
pointer-events: none;
top: 100%;
margin-top: 12px;
border: 1px solid black;
margin-left: calc(0px - var(--tooltip-offset));
}
.tooltip:before {
z-index: 1;
content: ' ';
position: absolute;
bottom: 100%;
border-color: transparent transparent black transparent;
margin-left: var(--tooltip-offset);
left: calc(50% - 12px);
border-width: 12px;
border-style: solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet"/>
<div class="container">
<a class="link" href="example.com">
Go to example.com
</a>
<span class="tooltip">
Click here to go to example.com
</span>
</div>
I'm not sure if Firefox and Chrome handle negative margins differently, so a more reliable way might be to use transform:
:root {
font-size: 62.5%;
font-family: 'sans-serif';
--tooltip-offset: 50px;
}
.container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.link {
border-radius: 4px;
height: 4rem;
font-size: 1.6rem;
border: 1px solid hsl(215, 36%, 78%);
padding: 0 1.5rem;
justify-content: center;
align-items: center;
display: inline-flex;
}
.tooltip {
font-size: 1.4rem;
z-index: 2;
width: 225px;
position: absolute;
text-align: center;
padding: 0.7rem 3rem;
border-radius: 4px;
pointer-events: none;
top: 100%;
margin-top: 12px;
border: 1px solid black;
transform: translateX(calc(0px - var(--tooltip-offset)));
}
.tooltip:before {
z-index: 1;
content: ' ';
position: absolute;
bottom: 100%;
border-color: transparent transparent black transparent;
margin-left: var(--tooltip-offset);
left: calc(50% - 12px);
border-width: 12px;
border-style: solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet"/>
<div class="container">
<a class="link" href="example.com">
Go to example.com
</a>
<span class="tooltip">
Click here to go to example.com
</span>
</div>
That looks like it works correctly in both browsers on my end!
Related
I have a popup window (within the same page) which I'm attempting to put a container which scrolls horizontally into, yet it distorts the popup window and does not display anything other than the scrollbar. I'm honestly at a loss, can anyone help me here? I've looked around for solutions but I can't find anything that I can see applies to my problem.
If anyone can help, or point me in the right direction, I'd be really grateful. The scrollbar works perfectly fine when isolated, but inside the window shows like this:
Standalone:
My HTML (popup window with scrollbar inside)
<div id="formula-popup" class="popup-window">
<div>
<a onclick="closeFormulaWindow()" title="Close" class="close">X</a>
<span id="ftitle" class="title1"></span>
<form method="post" id="formulaform" name="edit">
<span>Current Formula</span>
<p id="current-formula" class="formula">Existing formula</p>
<input id="id-passer" type="hidden" name="formula-id" value="">
<!--sort out horizontal scrollbar from bookmarks here later-->
<input onclick="refreshWindow()" name="edit-formula" type="submit" value="Confirm">
</form>
<div class="h-scrollbar">
<section class="h-scrollbar-container">
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
</div>
</div>
<div class="pseudo-track"></div>
</section>
</div>
</div>
My CSS:
.scrollbar-container {
display: flex;
flex-direction: row;
}
.h-scrollbar {
display: flex;
max-width: 30vw;
padding: 0px 10px;
height: 20vh;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.h-scrollbar-container {
width: 100%;
}
.outer-wrapper {
max-width: 100vw;
overflow-x: scroll;
position: relative;
scrollbar-color: #d5ac68 #f1db9d;
scrollbar-width: thin;
-ms-overflow-style: none;
}
.pseudo-track {
background-color: #f1db9d;
height: 2px;
width: 100%;
position: relative;
top: -3px;
z-index: -10;
}
.outer-wrapper::-webkit-scrollbar {
height: 5px;
}
.outer-wrapper::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 0px rgba(0, 0, 0, 0);
}
.outer-wrapper::-webkit-scrollbar-thumb {
height: 5px;
background-color: #d5ac68;
}
.outer-wrapper::-webkit-scrollbar-thumb:hover {
background-color: #f1db9d;
}
.outer-wrapper::-webkit-scrollbar:vertical {
display: none;
}
.inner-wrapper {
display: flex;
padding-bottom: 10px;
}
.pseudo-item {
height: 30px;
width: 80px;
margin-right: 15px;
flex-shrink: 0;
background-color: gray;
}
.pseudo-item:nth-of-type(2n) {
background-color: lightgray;
}
.popup-window {
position: fixed;
font-family: Arial, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
}
.popup-window div {
width: 40vw;
height: 30vw;
position: relative;
margin: 10% auto 30%;
border-radius: 10px;
background: #213B54;
padding-top: 2vh;
padding-left: 1vw;
padding-right: 1vw;
padding-bottom: 2vh;
display: flex;
flex-direction: column;
}
.close {
font: Arial, sans-serif;
background: #067A9F;
color: #B5E5E7;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
border-radius: 12px;
box-shadow: 1px 1px 3px #000;
cursor: pointer;
}
.popup-window div .title1 {
font-family: Arial, sans-serif;
font-weight: normal;
font-size: 36px;
color: #EE6802;
align-self: center;
}
.popup-window form input[type=submit]:hover {
opacity: 0.8;
}
.popup-window form span {
color: #EE6802;
font-size: 22px;
}
.popup-window form {
display: flex;
flex-direction: column;
font-family: Arial, sans-serif;
}
.popup-window form span, input {
width: 100%;
}
.popup-window form input[type=submit] {
width: 20%;
background-color: #067A9F;
color: #213B54;
padding: 14px 0;
cursor: pointer;
border: none;
}
I found the solution, it was that I forgot to select an element inside the window properly and instead it was selecting all divs and so overriding the CSS properties.
If you open the Codepen on a desktop it works fine, even when you change the browser width. If you open it on mobile, the text disappears. No clue what's happening here, thanks in advance for help!
Codepen for reference: https://codepen.io/hanwhite/pen/JjpWZqG
<div class="enter_button_docked">
<div class="enter_button_bg">
<div class="enter_button_bg2">
<button class="enter_button" >This is a button</button>
</div>
</div>
</div>
<style>
.enter_button_docked {
display: block;
position: fixed;
width: 100%;
bottom: 50px;
left: 0;
display: flex;
height: 90px;
justify-content: center;
align-items: center;
z-index: 10;
}
.enter_button_bg {
width: 90%;
padding: 3px;
border-radius: 8px;
background: linear-gradient(to bottom, #e82ea9, #0afff0);
}
.enter_button_bg2 {
background-color: white;
border-radius: 8px;
}
.enter_button {
position: relative;
text-transform: uppercase;
font-weight: 900;
font-size: 30px;
width: 100%;
margin: 8px 0px;
letter-spacing: 2px;
border: none;
background: -webkit-linear-gradient(#e82ea9, #0afff0);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>
This question already has answers here:
Text in Border CSS HTML
(10 answers)
Closed 3 years ago.
im trying to turn a design into code with html and css, but im stumped at a part in the hero section. What's the best way to position this logo with the border that stops around it.
attached is an image of the design i am trying to re-create
you can use before and after classes as
::before and ::after then add border and position it on the top of the corner left and right.
*{
margin: 0; padding: 0; box-sizing: border-box;
}
body{
font-family: Arial , Helvetica;
}
.banner-container{
min-height: 600px; height: 100vh; background-image: linear-gradient(to bottom, rgba(60, 53, 39, 0.6), rgba(60, 53, 39, 0.7)), url("https://images.pexels.com/photos/2015972/pexels-photo-2015972.jpeg?cs=srgb&dl=affection-baby-child-2015972.jpg&fm=jpg"); background-position: center; background-size: cover; background-repeat: no-repeat;
}
.banner-wrap{
margin: 0 auto; max-width: 960px; height: 100%; display: flex; align-items: center; justify-content: center;
}
.banner-box{
border-bottom: solid #A58758 4px; border-left: solid #A58758 4px; border-right: solid #A58758 4px; width: 500px; display: flex; flex-direction: column; align-items: center; position: relative; padding: 50px; margin-top: 100px;
}
.banner-box::before{
content: "";
width: 127px;
border: solid #A58758 2px;
position: absolute;
top: -4px;
left: -4px;
}
.banner-box::after{
content: "";
width: 127px;
border: solid #A58758 2px;
position: absolute;
top: -4px;
right: -4px;
}
.banner-box img{
position: absolute; top: -135px; padding: 5px;
}
.banner-box h2{
color: #fff; font-size: 2.5rem;
}
.banner-box h1{
color: #fff; margin: 5px 0; text-transform: uppercase; font-weight: 400; font-size: 3.8rem; letter-spacing: .4rem;
}
.banner-box h3{
color: #A58758; text-transform: uppercase; font-size: 2.3rem; font-weight: 400; letter-spacing: .6rem;
}
a{
background: #A58758; color: #fff; text-decoration: none; text-transform: uppercase; padding: 15px 25px; position: absolute; bottom: -25px; letter-spacing: .1rem;
}
<div class="banner-container">
<div class="banner-wrap">
<div class="banner-box">
<img src="https://www.thorndalemanors.com/wp-content/uploads/2019/01/thorndale-footer.svg">
<h2>Refined Luxury</h2>
<h1>Singles</h1>
<h3>In Brampton</h3>
Learn More
</div>
</div>
</div>
check its working properly
This is what I would do:
Wrapper element (.box-border) with two children: .box-border__top & .box-border__img
Put a border on .box-border but no top border
For the top border, use .box-border__top consisting of three elements:
.box-border__top:before: a line
.box-border__img: the logo, aligned in the center
.box-border__top:after: a line
To add spacing around the image, use .box-border__content with padding: 5em
body {
background: url(https://www.goodfreephotos.com/albums/vector-images/farm-landscape-illustration-vector-graphics.png);
background-size: cover;
}
.box-border { /* All side borders by the top */
border: .5em solid brown;
border-top: 0;
text-align: center;
}
.box-border__top { /* Align the image & borders */
display: flex;
}
.box-border__top:before,
.box-border__top:after {
content: '';
display: block;
width: 100%;
border-top: .5em solid brown; /* Sections of the top image */
}
.box-border__img { /* Center Image */
transform: translateY(-50%);
margin: 0 0 -99%;
}
/* Add some padding on the bottom */
.box-border__content { padding: 5em; }
<div class="box-border">
<div class="box-border__top">
<img class="box-border__img" src="https://upload.wikimedia.org/wikipedia/commons/6/66/Android_robot.png" width="100" height="90" />
</div>
<div class="box-border__content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Robogarden_img.png/800px-Robogarden_img.png" width="300" />
</div>
</div>
Any clue about how to create below kind of dashboard? I use angular fontawesome.
I can create simple play button like so:
<a class="btn btn-success" (click)="onPlay()">
<fa-icon [icon]="faPlayCircle" size="4x"></fa-icon>
</a>
But How to do this? I would like to know about how to give the depth on the background like so on the image?
I think you can reach great results only with CSS. Here is a small sample only using HTML and CSS.
.panel {
display: flex;
align-items: center;
padding-left: 20px;
width: 300px;
height: 90px;
background: #3D3D3D;
}
.container-play {
position: relative;
width: 1px;
height: 1px;
background: #f0f;
}
.holder-play {
position: absolute;
top: calc(50% - 37px);
width: 74px;
height: 74px;
border-radius: 50%;
background: linear-gradient(#333333, #686868);
box-shadow: inset 0px 0px 12px rgba(0,0,0,.4);
}
.play {
position: absolute;
top: calc(50% - 30px);
left: 7px;
display: flex;
justify-content: center;
align-items: center;
width: 60px;
height: 60px;
border-radius: 50%;
background: linear-gradient(#41825C, #1B4F2C);
box-shadow: 0px 3px 12px rgba(0,0,0,.6);
cursor: pointer;
}
.play i {
font-size: 26px;
color: #fff;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="panel">
<div class="container-play">
<div class="holder-play">
<div class="play"><i class="fa fa-play"></i></div>
</div>
</div>
</div>
Does anyone know of CSS property that I can use to achieve the same result as clip-path to make rounded shapes around a div? My site needs to be compatible with the latest version of IE, but I checked on www.caniuse.com and clip-path is not supported on IE 11.
This is what I am trying to do:
My current code works as you can see in this codepen: https://codepen.io/CodingGilbert/pen/BqwoGm?editors=1100
The problem is, that this code won’t work in IE, how can I solve this? Surely there must be another CSS property which does the same.
.card {
width: 80%;
height: 16.5rem;
border-radius: 5px;
background-color: #fff;
text-align: center;
padding: 0 1.5rem;
margin:10rem auto;
}
.card__inner-wrapper {
height: 55%;
position: relative;
margin: 0 auto;
display: flex;
justify-content: center; }
.card__img {
height: 100%;
position: absolute;
bottom: 50%;
clip-path: circle(50% at 50% 50%);
background-color: #fff;
border: 0.8rem solid #fff; }
.card__text-content {
position: absolute;
top: 6rem; }
.card__heading {
font-size: 1.8rem;
font-weight: 500;
color: #5fc0c3;
margin-bottom: 1.5rem; }
In this case, border-radius: 50%; on the .card__img will give you the same result, and it's compatible with IE9 and above.
Demo:
body {
background-color: gray;
}
.card {
width: 80%;
height: 16.5rem;
border-radius: 5px;
background-color: #fff;
text-align: center;
padding: 0 1.5rem;
margin: 10rem auto;
}
.card__inner-wrapper {
height: 55%;
position: relative;
margin: 0 auto;
display: flex;
justify-content: center;
}
.card__img {
height: 100%;
position: absolute;
bottom: 50%;
border-radius: 50%; /* instead of clip-path */
background-color: #fff;
border: 0.8rem solid #fff;
}
.card__text-content {
position: absolute;
top: 6rem;
}
.card__heading {
font-size: 1.8rem;
font-weight: 500;
color: #5fc0c3;
margin-bottom: 1.5rem;
}
<div class="card">
<div class="card__inner-wrapper">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Light_bulb_icon_red.svg/2000px-Light_bulb_icon_red.svg.png" alt="Bulb icon" class="card__img">
<div class="card__text-content">
<h4 class="card__heading">We help charities</h4>
<p>Share knowledge and working practice to make the best technology choices.</p>
</div>
</div>
</div>
you could use inline SVG to clip an image as it has great browser support - http://caniuse.com/#search=inline%20svg