Font awesome icons element space have unwanted overlap - html

I am using font awesome icons and I want them position on top of each other. I also want to the user to be able to interact with them by clicking on them.
The problem is that the element of each icon is taking up more space than it needs and is overlapping. So when the user thinks they are clicking on the top one, they end up activating a listener for the bottom one.
Here is the html:
<div class="arrow-container">
<i class="fa fa-sort-asc comment-vote up-vote-comment" aria-hidden="true"></i>
<i class="fa fa-sort-desc comment-vote down-vote-comment" aria-hidden="true"></i>
</div>
and the css:
.black-arrow{
color: black;
}
.up-vote-comment{
width: 100%;
}
.down-vote-comment{
position: relative;
top: -15px;
}
.comment-vote{
font-size: 20px;
}
it is important for me that the two arrows line up exactly on the same line horizontally and be quite close vertically, as they are in this fiddle.
Anyone know how to make them not overlap in occupied element space? I tried setting the height of the bottom arrow but that just made the occupied space of the element be above the arrow itself.

You can use the following code:
EDIT
.comment-vote {
font-size: 20px;
position: initial;
width: 100%;
display: inline-block;
}
.arrow-container {
width: 30px;
position: absolute;
top: 0px;
left: 0px;
}
This way you can use the .arrow-container class to position the arrows.

Combination of containers and absolute positioning. You can even have a 2px space between arrows.
.comment-icon-wrapper {
height: 10px;
width: 12px;
overflow: hidden;
position: relative;
margin-bottom: 2px;
}
.comment-vote {
position: absolute;
display: block;
}
.comment-vote {
font-size: 20px;
line-height: 20px;
display: block;
background-color: red;
}
.comment-vote:hover {
cursor:pointer;
}
.down-vote-comment {
position: relative;
top: -9px;
background-color: blue;
}
https://jsfiddle.net/w6ybL3nb/5/ (backgrounds to highlight spaces)

If you add a height to the top arrow and some z-indexes so the top arrow stacks over the bottom arrow, you can achieve what you want:
.black-arrow {
color: black;
}
.up-vote-comment {
width: 100%;
height: 12px;
z-index: 2;
overflow: hidden;
}
.down-vote-comment {
top: -13px;
z-index: 1;
}
.comment-vote {
font-size: 20px;
display: inline-block;
position: relative;
}
Updated fiddle - I have added console logging to the click of the arrows so you can see which one is being pressed

Related

Is there a way to affect the position of an img but not the source in an anchor element?

Is there a way to position an img separately from the source (text) in an anchor element? For instance, in the picture, I want the word "dot" to be aligned further right than the arrow but stay on top of the arrow.
current
what I want
I know I could make them as separated anchors but I want the color of the word to change when you hover on the arrow as well and if they are separate, the a:hover doesn't work together.
I tried changing the position under .left img to be different but it moves the img and the source.
HTML code:
<span class="leftarrow">
dot<img src="images/leftarrow.png">
</span>
CSS code:
.leftarrow {
position: absolute;
left: 0;
top:0;
}
.leftarrow a{
position: absolute;
left: 0;
font-size: 1.5em;
color:gray;
text-decoration: none;
}
.leftarrow a:hover{
color: black;
}
.leftarrow img{
position: absolute;
left: 0;
top: 15px;
width: 50px;
}
Try this, using Pseudo-Elements. It could definitely be more optimized than this though.
a {
margin-left: 100px;
}
span:after {
content: "";
background-image:url('https://www.flaticon.com/svg/static/icons/svg/271/271218.svg');
display: inline-block;
background-size: 30px 30px;
height: 30px;
width: 30px;
position: absolute;
z-index: 1;
left:90px;
top: 15px;
}
a:hover {
color: red;
}
<a href="#">
<span>dot</span>
</a>
First: wrap the dot into a <span> or <div> for better control,
Second: use a more powerfull display mode (e.g: flex or grid)
here is a sample:
a {
vertical-align: middle;
text-decoration: none;
display: flex;
flex-direction: column;
align-items: flex-end;
color: black;
width: fit-content;
margin: 0 auto;
}
a:hover {
color: red;
}
div {
font-size: 32px;
}
img {
width: 100px;
}
<a href="#">
<div>dot</div>
<img src="https://www.flaticon.com/svg/static/icons/svg/271/271218.svg" />
</a>

CSS offset a tooltip

I am trying to attach a tooltip to a button.
.hangup_button {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
}
.contained_message {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.messageContain:hover .contained_message{
visibility: visible;
}
<div class="container_div">
<button class="hangup_button messageContain">
End Chat
<span class="contained_message">Terminate session. Charges stop accumulating.</span>
</button>
</div>
The problem I have is that the tooltip appears at the bottom of the button. I am trying to make it appear to the top of the button. So far, I tried to switch the <span class="contained_message"> to the top of the End Chat text. But the tooltip still exceeds the bottom of the button. I also tried to add position: relative; to .contained_message. That seems to mess up the whole button. What should I do in order for the tooltip to appear on top of the button, without exceeding the bottom of the button?
I added some changes to make it work:
Use position: relative on parent element.
Use transform: translate to get the desired placement, as well as top: -5px (can be 0, but -5 gives it a nice space)
I changed it to display: none / block instead of using visibility, as it may be more desirable (providad you are not looking to do transitions).
To center the tooltip horizontally, left: 50% with translate(-50%, ...) does the trick.
Working snippet:
.hangup_button {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
margin-top: 80px;
position: relative;
}
.contained_message {
display: none;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
transform: translate(-50%, -100%);
left: 50%;
top: -5px;
}
.messageContain:hover .contained_message{
display: block;
}
<div class="container_div">
<button class="hangup_button messageContain">
End Chat
<span class="contained_message">Terminate session. Charges stop accumulating.</span>
</button>
</div>

Pseudo element selector not working

I have a dynamic element which will be capable of scaling in size, its position could be placed anywhere on the screen. I'm basically trying to create an "elbow" section.
What this "elbow" needs is an extension arm at the top right... Funny thing is, while I have the position and size correct, for some reason, the pseudo element is not showing up in the grey I'm calling... (see attached image showing Element Inspector highlighting the element in the correct size and position, but not in the same grey)...
I have a JSFiddle here of the code: https://jsfiddle.net/eliseo_d/6p9z8xr3/
HTML:
<div class="elbow-1-toprt-wide0-grey1">elbow 1</div>
CSS:
html {
background-color: rgb(0,0,0);
}
body {
margin: 5px;
}
div[class$='-grey1'] {
background-color: rgb(102,102,102);
}
div[class^='elbow-'] {
/* default settings */
color: rgb(0,0,0);
font-size: 14pt;
height: 14px;
margin-bottom: 4px;
margin-right: 4px;
overflow: hidden;
padding-bottom: 7px;
padding-left: 10px;
padding-right: 10px;
text-align: right;
text-transform: uppercase;
width: 84px;
position: relative;
}
div[class^='elbow-1-'] {
padding-top: 46px;
}
/* Initial curve */
div[class^='elbow-'][class*='-toprt-'] {
border-top-left-radius: 42px;
}
/* elbow bar */
div[class^='elbow-'][class*='-toprt-']:after {
content: '';
height: 30px;
left: 104px;
top: 0;
position: absolute;
}
div[class^='elbow-'][class*='-wide0-']:after {
width: 21px;
}
div[class^='elbow-'][class*='-wide0-'][class$='-grey0']:after {
background-color: rgb(51,51,51);
}
div[class^='elbow-'][class*='-wide0-'][class$='-grey1']:after {
background-color: rgb(102,102,102);
}
I can't seem to figure out what I'm missing?
Anyone know what I'm missing? Thanks in advance.
The ::after element is being shown with the background, your problem is that div[class^='elbow-'] is set to overflow:hidden;, which is hiding the pseudo element.
Simply remove overflow:hidden;
JSFiddle Demo

Center aligning an element with firefox and 100% width

So Im trying to do a simple header where I have the text aligned central with a 2px border running underneath this.
The code I have works and should work perfectly on every other browser except firefox which is aligning the border right of the page as if the beginning of the border is aligned in the center. If I remove the text align center the border is placed perfectly but the text is aligned to the left obviously. Why is firefox doing this?
CSS:
.my-title {
position: relative;
margin-bottom: 70px;
padding-bottom: 15px;
}
.my-title:after {
position: absolute;
bottom: 0;
height: 2px;
background-color: #ffd500;
content: "";
width: 100%;
}
.align-center {
text-align: center;
}
Html:
<div class="row">
<div class="col-xs-12">
<hgroup class="my-title align-center">
<h1>Header</h1>
<h2>Sub-Header</h2>
</hgroup>
</div>
</div>
since your pseudo element is in position:absolute; it has no width in the flow of your content and follows text-align:center; set on parent.( as absolute it has, in the flow of content, 0 for heigh and width).
3 possibilities:
add the rule : left:0; no matter what text-align on parent will be, it will be drawn from left coordonates.
add the rule : display:block; so it behaves like a block element and ill ignore the text-align, it will do a break line and will be drawn from left or right (follows the direction/dir of document).
keep it in the flow:
.my-title {
position: relative;
margin-bottom: 70px;
padding-bottom: 15px;
}
.my-title:after {
height: 2px;
background-color: #ffd500;
content: "";
width:100%;
display:inline-block;
vertical-align:bottom;
}
.align-center {
text-align: center;
}
Using property left solved the problem:
.my-title:after {
left: 0;
}
Demo
Try this:
#-moz-document url-prefix()
{
.my-title
{
position: relative;
margin-bottom: 70px;
padding-bottom: 15px;
}
.my-title:after
{
position: absolute;
bottom: 0;
height: 2px;
background-color: #ffd500;
content: "";
width: 100%;
}
.align-center
{
text-align: center;
}
}

pixel difference between Chrome and FF

I'm trying to make a "step by step", but i'm heaving some problems with pixel difference between chrome and FF.
so, all steps are dynamic and should be in the middle, some times can appear only two, three our 5 options, thats why i'm making a sub-line for each side, to reach the end of the wrapper.
This lines are the problem, they are making 2 our 1 pixels difference.
i'm missing something or in this case, we should make a "workaround" ?
will be more simple if you see in action here: jsfiddle
for those who wants to see the code directly here:
html:
<article id="people-add">
<nav>
<div class="step-wrapper">
<div class="base-left-line"></div>
<div class="step first-step">
<div class="active-stepc step-circle"></div>
<span class="step-label">
Step 1
</span>
</div>
<div class="step">
<div class="step-line"></div>
<div class="step-circle"></div>
<span class="step-label">
Step 2
</span>
</div>
<div class="step">
<div class="step-line"></div>
<div class="step-circle"></div>
<span class="step-label">
Step 4
</span>
</div>
<div class="step">
<div class="step-line"></div>
<div class="step-circle"></div>
<span class="step-label">
Step 5
</span>
</div>
<div class="base-right-line"></div>
</div>
</nav>
</article>​
and css:
#people-add {
float: left;
width: 100%;
}
#people-add nav {
padding: 5px 0 60px 0;
}
.step-wrapper {
float: left;
width: 100%;
text-align: center;
position: relative;
}
.step {
display: inline-block;
position: relative;
width: 120px;
}
.first-step {
width: 0 !important;
}
.step .step-label {
position: absolute;
right: -35px;
bottom: -30px;
font-size: 12px;
width: 96px;
text-align: center;
font-weight: bold;
color: #818181;
}
.step .step-line {
border-bottom: solid #E5E5E5 2px;
position: absolute;
right: 5px;
top: -2px;
z-index: 12;
width: 120px;
}
.step .step-circle {
background-color: #B3B3B3;
border: solid 4px #E5E5E5;
width: 20px;
height: 20px;
border-radius: 50px;
position: absolute;
right: -1px;
top: -15px;
z-index: 13;
}
.base-left-line,
.base-right-line {
position: absolute;
width: 50%;
top: 12px;
z-index: 1;
}
.base-left-line {
border-bottom: 2px solid #9BBD5E;
left: 0;
}
.base-right-line {
border-bottom: 2px solid #9BBD5E;
right: 0;
} ​
print:
as you can see, the green line in FF are crossing all over the graylines in the middle of steps.
Okay, I (just like many others who commented) did not see the same difference you show between my Chrome and Firefox, and neither browser was behaving for me as you show you desired in your picture.
I did, however, note some odd behaviors of the lines when I zoomed in and out in the browsers. This lead me to look more carefully at your code, and I feel that the reason you are seeing some differences (and the inconsistencies for us all) is because of how you have positioned the lines. I recommend the following changes (I only note those, not all your code), as seen in this fiddle, which may fix your issues.
Explanation
The vertical-align is normally bottom by default on inline-block, and since you are positioning your .base-[left/right]-line elements by a top position, it is better to do so for the elements inside the .step that are intended to overlap those. So...
ADD
.step {
vertical-align: top; /* ADDED THIS so that dimensions come from the top */
}
CHANGE
.step .step-label {
bottom: -45px; /* CHANGED THIS for the vertical align top */
}
.step .step-line {
top: 12px; /* CHANGED THIS, which now matches offset of the baselines */
}
.step .step-circle {
top: 0; /* CHANGED THIS */
}