Image after text using absolute position in :before class - html

I have a button which has a static and hover state.
Now there is a small down arrow image which sits after text using :before class. I had to use :before instead :after as there is a hover effect. Due to hover effect the :after class was not displaying the small arrow image so I had to use :before and absolute positioning to position that image after text.
The problem is that the text length can vary and as it is absolute position so sometimes the image sits inside the text not after the text.
Here is the code
<button type="submit" class="button uppercase btn-1b">home</button>
<br>
<br>
<button type="submit" class="button uppercase btn-1b">development</button>
Demo: Example of short and long text with image(small down arrow)
Any help is highly appreciated. Thanks in advance.

interchanged with :before :after
remove position: absolute; for arrow
.uppercase {
text-transform: uppercase;
}
.button {
color: white;
position: relative;
z-index: 1;
background: #000;
border: 1px solid #9d9368;
font-size: 17px;
padding: 0.5rem 2rem;
width: 220px;
display: inline-block;
cursor:pointer;
}
.button:after {
background-image: url("http://s12.postimg.org/63ise2fkp/button_arrow.png?noCache=1431762044");
background-repeat: no-repeat;
content:"";
height: 5px;
width: 8px;
margin-left: 5px;
display: inline-block;
vertical-align: middle;
}
.button:before {
content:"";
position: absolute;
top: 1.1rem;
right: 4.1rem;
transition: all 0.3s ease 0s;
z-index: -1;
}
.btn-1b:before {
width: 100%;
height: 0;
top: 0;
left: 0;
background: #b0a479;
}
.btn-1b:hover, .btn-1b:active {
color: #000000;
}
.btn-1b:hover:before, .btn-1b:active:before {
height: 100%;
}
.button:hover:after {
background-image: url("http://s8.postimg.org/419zt4xk1/button_arrow_hover.png?noCache=1431844698");
}
<button type="submit" class="button uppercase btn-1b">home</button>
<br>
<br>
<button type="submit" class="button uppercase btn-1b">development</button>

I'd suggest taking advantage of the fact that the <button> element can contain child elements, and wrapping the text with a <span>, then using the - more appropriate ::after pseudo-element:
<button type="submit" class="button uppercase btn-1b"><span>home</span>
</button>
<br>
<br>
<button type="submit" class="button uppercase btn-1b"><span>development</span>
</button>
And using the following CSS for the un-hovered and hovered states:
.button span:after {
background-image: url("http://s12.postimg.org/63ise2fkp/button_arrow.png?noCache=1431762044");
background-repeat: no-repeat;
content:"";
display: inline-block;
height: 5px;
width: 8px;
margin-left: 0.5em;
}
.button:hover span:after {
background-image: url("http://s8.postimg.org/419zt4xk1/button_arrow_hover.png?noCache=1431844698");
}
.button span:after {
background-image: url("http://s12.postimg.org/63ise2fkp/button_arrow.png?noCache=1431762044");
background-repeat: no-repeat;
content: "";
display: inline-block;
height: 5px;
width: 8px;
margin-left: 0.5em;
}
.button:after {
content: "";
position: absolute;
top: 1.1rem;
right: 4.1rem;
transition: all 0.3s ease 0s;
z-index: -1;
}
.uppercase {
text-transform: uppercase;
}
.button {
color: white;
position: relative;
z-index: 1;
background: #000;
border: 1px solid #9d9368;
font-size: 17px;
padding: 0.5rem 2rem;
width: 220px;
display: inline-block;
cursor: pointer;
}
.btn-1b:after {
width: 100%;
height: 0;
top: 0;
left: 0;
background: #b0a479;
}
.btn-1b:hover,
.btn-1b:active {
color: #000000;
}
.btn-1b:hover:after,
.btn-1b:active:after {
height: 100%;
}
.button:hover span:after {
background-image: url("http://s8.postimg.org/419zt4xk1/button_arrow_hover.png?noCache=1431844698");
}
<button type="submit" class="button uppercase btn-1b"><span>home</span>
</button>
<br>
<br>
<button type="submit" class="button uppercase btn-1b"><span>development</span>
</button>
JS Fiddle demo.

Related

Element behaving like block despite being inline-block

I want my priority-menu (the one with 2 dots) to have the 3 dots displayed horizontally. Since each individual dot is inline-block I don't understand why they are stacked on top of one another. The menu is rendered by clicking on the blue circle on the right of the "save task" button, which changes its display to inline instead of none. I tried changing that to inline-block and nothing seems to have changed.
/* The popup menu - hidden by default */
#priority-menu {
display: none;
position: absolute;
top: 150%;
border: 3px solid #f1f1f1;
z-index: 9;
max-width: 300px;
padding: 10px;
background-color: white;
}
#priority-dot-open-menu {
position: relative;
height: 25px;
width: 25px;
background-color: blue;
border-radius: 50%;
display: inline-block;
opacity: 0.8;
cursor: pointer;
}
#priority-dot-open-menu:hover {
opacity: 1;
}
#priority-dot-blue {
height: 25px;
width: 25px;
background-color: blue;
border-radius: 50%;
display: inline-block;
opacity: 0.8;
}
#priority-dot-yellow {
height: 25px;
width: 25px;
background-color: yellow;
border-radius: 50%;
display: inline-block;
opacity: 0.8;
}
#priority-dot-red {
height: 25px;
width: 25px;
background-color: red;
border-radius: 50%;
display: inline-block;
opacity: 0.8;
}
.modal-footer {
padding: 0;
}
#priority-menu::after {
content: " ";
position: absolute;
bottom: 100%; /* At the top of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent black transparent;
}
<div class="modal-footer d-flex flex-row justify-content-start pl-0 mt-4 border-0">
<button type="button" class="btn btn-primary btn-sm" id="add-task-modal-save">Save task</button>
<span id="priority-dot-open-menu">
<span id="priority-menu">
<span class="tooltip-top"></span>
<span id="priority-dot-blue"></span>
<span id="priority-dot-yellow"></span>
<span id="priority-dot-red"></span>
</span>
</span>
</div>
Your priority-menu is contained within an element which you’ve set to 25px width. Try removing this and changing to 300px, like your priority-menu.
#priority-dot-open-menu {
position: relative;
height: 25px
width: 300px;
background-color: blue;
border-radius: 50%;
display: inline-block;
opacity: 0.8;
cursor: pointer;
}
You can also try adding a declared width to your menu instead of just a max-width.
#priority-menu {
width:300px;
}

css style whole element when hovering on its "after"

I have this button/speech bubble:
Code:
<div value="GO" id="go-div" class="bubble">
<input type="submit" value="GO" id="go-button" style=" position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;" data-target="#search-results-page">
</div>
I have this styling, to change the little arrow colour, when hovering on the button:
#go-div.bubble:hover:after {
border-color: transparent #ffffff;
}
Which gives this effect when hovering over the bubble:
However, when I hover over the little arrow it doesn't cause the whole button to change color:
What is the css that selects the little arrow (.bubble:after) hover and effects the whole button (.button) to turn it white?
Here is the jsfiddle
You can apply your :hover style to the parent element and since :after is a child when you hover on the arrow it will trigger hover on parent.
#go-div:hover #go-button{
background: white;
}
.bubble
{
position: relative;
width: 250px;
height: 65px;
padding: 0px;
background: #ff8282;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 15px 0 15px 24px;
border-color: transparent #ff8282;
display: block;
width: 0;
z-index: 1;
margin-top: -15px;
right: -24px;
top: 50%;
}
#go-div.bubble:hover:after {
border-color: transparent #ffffff;
}
#go-button:hover {
text-decoration: none;
background-color:white;
color: brand-red
}
#go-button,
#go-div{
font: 200 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
border-radius: 6px;
height: 64px;
text-decoration: none;
width: 100%;
background-color: #ff8282;
padding: 12px;
border: 0px solid #fff;
color: #fff;
cursor: pointer;
}
#go-div:hover #go-button{
background: white;
}
<div value="GO" id="go-div" class="bubble">
<input type="submit" value="GO" id="go-button" style=" position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;" data-target="#search-results-page">
</div>
You can't use .bubble:hover:after to select the entire bubble as shown below:
.bubble:hover:after .bubble {
background-color: #ffffff;
}
So, your only choice is to put the :hover on the parent element. This way both elements will be affected and no further action will be needed:
.bubble:hover > #go-button {
background: #ffffff;
}
You can check out an updated, working version of your jsFiddle here.

CSS Touch Ripple Effect, Not Working Properly

My CSS touch ripple is not working properly. It is just seen like a bubble in the center when i click on the button. Please help in finding where am i doing the mistake. i am not much known to CSS animations. i would like to do this using just CSS only.
.ripple-con,
.button {
display: inline-block;
position: relative;
overflow: hidden;
}
.button::after,
.ripple {
content: ' ';
background: rgba(0, 0, 0, 0.3);
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
display: inline-block;
border-radius: 100%;
}
.button:active::after,
.ripple:active,
.button:active+.ripple {
animation: ripple 2s;
}
#keyframes ripple {
to {
opacity: 0;
margin: -250px;
width: 500px;
height: 500px;
}
}
.button {
line-height: 39px;
border: 0;
height: 42px;
box-sizing: border-box;
padding: 0 20px;
background: #888;
border-radius: 5px;
cursor: default;
vertical-align: top;
}
html {
text-align: center
}
body {
display: inline-block
}
<div class="ripple-con">
<input class="button" type="submit" value="Submit Button : Button">
<span class="ripple"></span>
</div>
<div class="ripple-con">
<input class="button" type="button" value="Input Button : Button">
<span class="ripple"></span>
</div>
<div class="button">Div : Button</div>
<button class="button">Button : Button</button>
Just place animation: ripple inside .button::after, .ripple style definition and place animation: none where it goes active as follows
.ripple-con,
.button {
display: inline-block;
position: relative;
overflow: hidden;
}
.button::after,
.ripple {
content: ' ';
background: rgba(0, 0, 0, 0.3);
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
display: inline-block;
border-radius: 100%;
animation: ripple 2s;
}
.button:active::after,
.ripple:active,
.button:active + .ripple {
animation: none;
}
#keyframes ripple {
to {
opacity: 0;
margin: -250px;
width: 500px;
height: 500px;
}
}
.button {
line-height: 39px;
border: 0;
height: 42px;
box-sizing: border-box;
padding: 0 20px;
background: #888;
border-radius: 5px;
cursor: default;
vertical-align: top;
}
html {
text-align: center
}
body {
display: inline-block
}
<div class="ripple-con">
<input class="button" type="submit" value="Submit Button : Button">
<span class="ripple"></span>
</div>
<div class="ripple-con">
<input class="button" type="button" value="Input Button : Button">
<span class="ripple"></span>
</div>
<div class="button">Div : Button</div>
<button class="button">Button : Button</button>
Here is the fiddle

Image missing in ::after Pseudo-element

I have a button with hover effect.
When I am applying the hover class then the image(down arrow) is missing. If I remove hover class then I can see the image.
Html code with hover class
<button type="submit" class="button uppercase btn-1b">home</button>
Html code without hover class
<button type="submit" class="button uppercase">home</button>
Demo - With Image but without hover effect
Demo -- With hover effect but missing the image.
Any help is highly appreciated. Thanks in advance.
You can define arrow image in .button::before pseudo-element and transitioning background in .btn-1b:after:
.button::before {
background-image: url("http://s12.postimg.org/63ise2fkp/button_arrow.png?noCache=1431762044");
background-repeat: no-repeat;
content: "";
height: 5px;
position: absolute;
right: 4.1rem;
top: 1.1rem;
width: 8px;
}
.uppercase {
text-transform: uppercase;
}
.button {
color: white;
position: relative;
z-index: 1;
background: #000;
border: 1px solid #9d9368;
font-size: 17px;
padding: 0.5rem 2rem;
width: 220px;
display: inline-block;
cursor:pointer;
}
.btn-1b:after {
content: '';
position: absolute;
transition: all 0.3s ease 0s;
width: 100%;
height: 0;
top: 0;
left: 0;
background: #ffffff;
z-index: -1;
}
.btn-1b:hover, .btn-1b:active {
color: #0e83cd;
}
.btn-1b:hover:after, .btn-1b:active:after {
height: 100%;
}
<button type="submit" class="button uppercase btn-1b">home</button>

How can I float dynamic div's next to each other?

I'm creating my own version of Twitter Bootstrap radio buttons purely based on CSS. The visual feedback for selected radio button is based on input[type="radio"]:checked + span.
As the content of my "buttons" can vary, the width is dynamic. This causes problem aligning the button next to each other.
In my JSfiddle I've set fixed width of 50px. Removing this and the buttons are on top of each other.
Can anyone point me in the right direction of how I can accomplish this?
Here is my code:
//HTML
<div class="button-group binary" data-toggle="buttons-radio">
<div class="radio-wrapper">
<input type="radio" class="active" name="status" value="1" />
<span class="background">Yes</span>
</div>
<div class="radio-wrapper">
<input type="radio" class="inactive" name="status" value="0" checked="checked" />
<span class="background">No</span>
</div>
</div>
//CSS
.button-group{
/*display: table;*/
display: block;
}
.radio-wrapper {
/*display: table-cell; */
display: inline-block;
position: relative;
height: 28px;
margin: 0;
width: 50px; /* I want this to be dynamic */
}
.radio-wrapper:first-child .background{
border-right: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.radio-wrapper:last-child .background{
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
input[type="radio"]{
position: absolute;
display: block;
height: 28px;
width: 100%;
z-index: 200;
cursor: pointer;
opacity: 0;
}
input[type="radio"]:checked + span {
background-color: #63B1DE;
color: #fff;
}
.background {
position: absolute;
z-index: 100;
height: 100%;
padding: 0 5px;
border: solid 1px #87A2B2;
background-color: #fff;
text-align: center;
line-height: 28px;
text-transform: uppercase;
}
If you remove position: absolute from you background class, you will no longer need the width style:
jsFiddle
.button-group{
/*display: table;*/
display: block;
}
.radio-wrapper {
/*display: table-cell; */
display: inline-block;
position: relative;
height: 28px;
margin: 0;
/*width: 50px; not needed*/
}
.radio-wrapper:first-child .background{
border-right: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.radio-wrapper:last-child .background{
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
input[type="radio"]{
position: absolute;
display: block;
height: 28px;
width: 100%;
z-index: 200;
cursor: pointer;
opacity: 0;
}
input[type="radio"]:checked + span {
background-color: #63B1DE;
color: #fff;
}
.background {
z-index: 100;
height: 100%;
padding: 0 5px;
border: solid 1px #87A2B2;
background-color: #fff;
text-align: center;
line-height: 28px;
text-transform: uppercase;
}
Having a look at your CSS, I think the issue you are having is because you are making the .background position: absolute it is not taking up any space in its parent, so the parent doesn't really have any width, this is why you have to manually set it. Stripping out the absolute positioning for the .background and actually making it an element that takes up space will give the parent a width (which will be based on its content). Now as far as correcting the on top of each other issue, I would think some floating here would work. CSS is here (I also removed some unnecessary rules)
.radio-wrapper {
position: relative;
float:left;
}
.radio-wrapper:first-child .background{
border-right: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.radio-wrapper:last-child .background{
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
input[type="radio"]{
position: absolute;
display: block;
height: 28px;
width: 100%;
z-index: 200;
cursor: pointer;
opacity: 0;
}
input[type="radio"]:checked + span {
background-color: #63B1DE;
color: #fff;
}
.background {
height: 100%;
padding: .5em;
border: solid 1px #87A2B2;
background-color: #fff;
text-align: center;
line-height: 28px;
text-transform: uppercase;
}
As per example fiddle.
I did add a bit more padding that you had though so please feel free to adjust as required. I also like padding in ems so if your font changes in size the padding is always relative.