CSS issue with background color in ::after - html

I use the following HTML/CSS code to make a chat bubble:
body {background-color: red}
.message-sent {
position:relative;
padding:10px 20px;
color:white;
background:#0B93F6;
border-radius:25px;
float: right;
margin-bottom: 5px;
margin-right: 30px;
}
.message-sent-last::before {
content:"";
position:absolute;
z-index:-1;
bottom:-2px;
right:-7px;
height:20px;
border-right:20px solid #0B93F6;
border-bottom-left-radius: 16px 14px;
-webkit-transform:translate(0, -2px);
}
.message-sent-last::after {
content:"";
position:absolute;
z-index:1;
bottom:-2px;
right:-56px;
width:26px;
height:20px;
border-bottom-left-radius: 10px;
-webkit-transform:translate(-30px, -2px);
background: red;
}
<div class="message-sent message-sent-last">
Hey there! What's up?
</div>
But the problem is in the last line of the CSS in which I am forced to repeat the background color, otherwise, the bubble will break. Please, check this out:
body {background-color: red}
.message-sent {
position:relative;
padding:10px 20px;
color:white;
background:#0B93F6;
border-radius:25px;
float: right;
margin-bottom: 5px;
margin-right: 30px;
}
.message-sent-last::before {
content:"";
position:absolute;
z-index:-1;
bottom:-2px;
right:-7px;
height:20px;
border-right:20px solid #0B93F6;
border-bottom-left-radius: 16px 14px;
-webkit-transform:translate(0, -2px);
}
.message-sent-last::after {
content:"";
position:absolute;
z-index:1;
bottom:-2px;
right:-56px;
width:26px;
height:20px;
border-bottom-left-radius: 10px;
-webkit-transform:translate(-30px, -2px);
background: transparent;
}
<div class="message-sent message-sent-last">
Hey there! What's up?
</div>
I would like to not repeat the background color of the page since the snippet will be used in several places with different background colors. I've tried with transparent and inherit but none worked out.
This is how the second snipped looks like:
I've tested in Chrome and FF under Ubuntu.
What do you think?

In your case, since it is fundamental for the creation of the bubble to assign the same color of the background to the div I would suggest to use a variable, so when the color of the body changes even the color of the div::after will change:
add at the top of your css file:
:root {
--main-bg-color: red;
}
in your body element:
body {background-color: var(--main-bg-color);}
and div:
.message-sent-last::after {
content:"";
position:absolute;
z-index:1;
bottom:-2px;
right:-40px;
width:10px;
height:20px;
border-bottom-left-radius: 10px;
-webkit-transform:translate(-30px, -2px);
background: var(--main-bg-color);
}
This allows you to change it on root and making the change effective on both elements.
Please note that it will not work on IE though.

Related

How to close hover dropdown menu on outside click?

I really do not want to lose the hover capability, I need a way without losing the hover capability.
In pure CSS (no JavaScript), how do I get the dropdown menu to close on clicks outside of the dropdown menu, without losing the hover capability?
Here is an example of someone who did a JavaScript dropdown menu with the feature of closing on outside clicks.
https://koen.kivits.com/articles/pure-css-menu/
Here is my dropdown menu CSS with hover and onClick:
.acn-menu {
text-align: center;
background-color: rgba(0, 0, 0, 0.9);
}
.label_openclose {
display: none;
}
.menu-tabs {
height: 100%;
padding-left: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
}
/* This CSS makes the Solutions dropdown menu push
down the other two items when in mobile view. */
#media (min-width: 320px) {
.menu-tabs {
position: absolute;
}
}
.menu-tabs .elem {
box-sizing: border-box;
padding: 0 20px;
float: left;
height: 100%;
line-height: 70px;
background-color: rgb(30, 30, 30);
color: white;
}
.menu-check {
display: none;
}
label {
margin-bottom: 0;
}
.label_openclose {
display: inline-block;
width: 60px;
min-height: 50px;
background-color: transparent;
cursor: pointer;
overflow:hidden;
display:block;
}
.menu-tabs .elem {
line-height: initial;
float: initial;
height: 0px;
cursor: pointer;
border-top: 0px solid #000;
overflow: hidden;
}
.menu-check:checked~.menu-tabs .elem {
height: 25px;
color: white;
border-top: 2px solid rgba(255, 255, 255, 0.2);
}
.label_openclose:hover~.menu-tabs .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
.label_openclose~.menu-tabs:hover .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
Is it possible for me to get the close-on-click without using JS? Here is a fiddle: https://jsfiddle.net/Ld5L2tnf/
I reviewed your code and posted an example of what you want. This is a more simple way of achieving your goal. This is an example you will have to apply it to your code. This is a pure css and html solution using checkboxes and labels. Below is detailed information on how it works. Hope it helps. Enjoy.
<html>
<head>
<title></title>
<style>
.buttoncomtainer1{ /*A wrapper for your hover dropdown List*/
width:100px;
height:2em;
float:left;
position:absolute;
z-index:20;
}
.mycheckButton{ /*Your Label acts as a Button Triggering the checkbox*/
width:100px;
height:2em;
float:left;
display:block;
background-color:blue;
text-align:center;
color:#ffffff;
position:fixed;
z-index:20;
}
.mycheckDrop{ /*Your Dropdown*/
width:100px;
float:left;
display:none;
padding:1%;
background-color:green;
position:fixed;
z-index:20;
margin-top:2em;
}
.gone{ /*Make your checkbox disappear*/
border:0px;
outline:none;
line-height:0;
display:none;
margin:0px;
padding:0px;
width:0px;
height:0px;
}
.blackout{ /*This Div covers the page with the labelBlackout Label in it. nothing can be clicked unless The Label inside clicked first triggering the checkbox. */
width:100%;
height:100%;
float:left;
position:fixed;
z-index:15;
background-color:transparent; /* You can add a background color like this. background-color:black; opacity:0.7;*/
display:none;
}
.labelBlackout{ /*the Label inside the blackout div that covers the page*/
width:100%;
height:100%;
float:left;
}
.lnkCon{ /* Container that holds your dropdown links.*/
width:100%;
height:2em;
float:left;
margin-top:5px;
}
input[type=checkbox].gone:checked ~ div.blackout{display:block;}
input[type=checkbox].gone:checked ~ label.mycheckDrop{display:block;}
.buttoncomtainer1:hover > .mycheckDrop{display:block;}
</style>
</head>
<body>
<div class="buttoncomtainer1">
<input class="gone" id="myCheck" type="checkbox" >
<div class="blackout" ><label class="labelBlackout" for="myCheck"></label></div>
<label class="mycheckButton" for="myCheck">DropDown</label>
<label class="mycheckDrop" for="myCheck">
<span class="lnkCon">Button 1</span>
<span class="lnkCon">Button 2</span>
<span class="lnkCon">button 3</span>
</label></div>
</body>
</html>

How can I place this div next to the other one?

I was wanting to make a website, just to see if I like doing it and how it would turn out, but I can't seem to get this part done. I want the "informatie" div to be next to the "vertmenu" div and make it fill up the white part and I want the "vertmenu" div to extend till the "voetregel" div. I have no idea how to get this done and I have already tried changing the width and height to percentages, changing the positions to absolute/relative and adding a float property, but I couldn't make it how I wanted it to be. So my question in short, how can I make the "informatie" div next to the "vertmenu" div and make it fill up the white part and get the "vertmenu" div to extend till the "voetregel" div.
body {
margin:0;
padding:0;
background-color:#ffffff;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
#hormenu {
background-color: rgba(0, 0, 0, 0.5);
position:relative;
text-align: center;
width:100%;
height:15%;
line-height:50px;
font-size:100%;
}
#vertmenu {
background-color: rgba(255,0,0, 0.3);
position:relative;
height:100px;
top:15%;
width:15%;
margin:0px 0px 0px 0px;
padding:3px;
overflow:hidden;
}
#informatie {
background-color: rgba(0,0,255, 0.3);
position:relative;
float:left;
height:100%;
width:85%;
left: calc(15% + 6px);
margin:0px 0px 0px 0px;
padding:3px;
overflow:hidden;
}
#voetregel {
background-color: rgba(0,255,0, 0.3);
position:fixed;
width:100%;
height:100px;
top:auto;
right:0;
bottom:0;
margin-left:10px
}
a.hormenu_item {
margin: 10px;
transition: color 0.3s, text-shadow 0.3s, text-decoration-line 0.3s, font 0.3s ease-in-out;
}
a:link.hormenu_item {
color: white;
text-decoration: none;
}
a:visited.hormenu_item {
color: white;
text-decoration: none;
}
a:hover.hormenu_item {
color: gold;
text-decoration:none;
text-shadow: 0px 0px 7px gold;
font-size: 30px;
}
#informatie h1, #vertmenu h1, #voetregel h2 {
color:#FF0000;
font-size:20px;
}
<body>
<div id="hormenu">
Home
Biografie
Features
Contact
</div>
<div id="vertmenu">
<h1>vertmenu</h1>
</div>
<div id="informatie">
<h1>informatie</h1>
</div>
<div id="voetregel">
<h2>voetregel</h2>
</div>
</body>
apply float:left; css in #vertmenu and #informatie
and dont use position:fixed; in #voetregel use clear:both; it will clear the float effect of above 2 div tags
position:fixed; is used for creating menubar in web site so that even with the scrolling that menubar stays at same place
You can add display: inline-block to make them next to each other. Remove position:fixed from #voetregel too.
#vertmenu {
background-color: rgba(255,0,0, 0.3);
width:15%;
margin:0px 0px 0px 0px;
}
#informatie {
background-color: rgba(0,0,255, 0.3);
width:85%;
margin:0px 0px 0px 0px;
}
#voetregel {
background-color: rgba(0,255,0, 0.3);
width:100%;
height:200px;
}
#vertmenu,
#informatie {
display: inline-block;
float: left;
}
#informatie h1,
#vertmenu h1,
#voetregel h2 {
color:#FF0000;
font-size:20px;
}
<div id="vertmenu">
<h1>vertmenu</h1>
</div>
<div id="informatie">
<h1>informatie</h1>
</div>
<div id="voetregel">
<h2>voetregel</h2>
</div>

CSS triangle has no point

Here is what is happening:
CSS:
.speech-box {
height:76px;
width:220px;
padding:6px 10px;
background-image: linear-gradient(#4f4f4f,#000);
}
.speech-box:before {
content:'';
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right:5px solid #4f4f4f;
position:relative;
left:-15px;
top:-3px;
}
And my HTML:
<div class="speech-box">
<span class="speech"></span>
</div>
And here is a fiddle: http://jsfiddle.net/xqy4dLbc/
I'm guessing the problem is with my HTML?
You need to add
display:block;
or
display:inline-block;
to .speech-box:before :
DEMO
The default display property of pseudo-element is inline (see MDN) and you can't set height on inline elements. Therefore the height:0; you set doesn't apply.

How to create a css hoverover box with two section

I have used the following How to create a box when mouse over text in pure CSS?
and switch the position of the cursor and the placement
span{
background:#F8F8F8;
border: 5px solid #DFDFDF;
color: #717171;
font-size: 13px;
height: 150px;
letter-spacing: 1px;
line-height: 30px;
position: relative;
text-align: center;
top: -10px;
left:60px;
display:none;
padding:0 20px;
}
span:after{
content:'';
position:absolute;
top:40px;
right: 135px;
width:10px;
height:10px;
border-bottom:5px solid #dfdfdf;
border-right:5px solid #dfdfdf;
background:#f8f8f8;
margin-left:-10px;
-moz-transform:rotate(135deg);
-webkit-transform:rotate(135deg);
transform:rotate(135deg);
}
p{
margin:100px;
float:left;
position:relative;
cursor:pointer;
}
p:hover span{
display:block;
}
<p>Hover here<span>some text here ?</span></p>
Here is the [fiddle] (http://jsfiddle.net/beerbuddha/4kjnb4e5/)
I need a split 25%(header) with different background color and the rest (75%) to be a different color and to hold text and an image.
I tried the approach and what happens is that the display:none doesnt work anymore at all and the hover box it self break.
Im slightly lost.
Very simple. You change html:
<div class="div-hover">Hover here
<div class="div-tooltip">
<div class="tooltip-header">some text here ?</div>
<div class="tooltip-body">some text body some text body</div>
</div>
</div>
Full code is here

text under a hover fading button

UPDATE: I am wanting the text to be shown beneath the button, so when it fades away, it will be revealed where the button was.
How can i place text under (in the z axis) a button made with a a element so that when i hover over the button
it fades away and shows the text under?
I have tried using positioning to and position:absolute to make it so both text can be in one spot, but it wont seem to work
My button: http://jsfiddle.net/27bCK/
<div id="pricebar">
<a class="see" href="#">PRICING</a>
</div>
#pricebar {
width:100%;
height:175px;
background-color:#EAE5E5;
text-align:center;
}
#pricebar .see {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#2ecc71;
border:5px solid #2ecc71;
border-radius:5px;
border-left:17px solid #2ecc71;
border-right:17px solid #2ecc71;
transition-duration: .3s;
transition-property: background-color, border, border-left, border-right, opacity;
}
#pricebar .see:hover {
opacity:0;
background-color:#27ae60;
border:5px solid #27ae60;
border-left:17px solid #27ae60;
border-right:17px solid #27ae60;
}
#pricebar .show {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#000;
margin-right:20px;
}
try this:
<div id="pricebar">
<a class="see" href="#">PRICING</a>
<div id="hidden">hidden text</div>
</div>
css:
#hidden{
text-align:center;
position:relative;
bottom:100px;
z-index:0;
border:0px solid red;
}
#pricebar {
width:100%;
height:175px;
background-color:#EAE5E5;
text-align:center;
z-index:1;
}
#pricebar .see {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#2ecc71;
border:5px solid #2ecc71;
border-radius:5px;
border-left:17px solid #2ecc71;
border-right:17px solid #2ecc71;
transition-duration: .3s;
transition-property: background-color, border, border-left, border-right, opacity;
position:relative;
z-index:3;
}
#pricebar .see:hover {
opacity:0;
background-color:#27ae60;
border:5px solid #27ae60;
border-left:17px solid #27ae60;
border-right:17px solid #27ae60;
}
#pricebar .show {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#000;
margin-right:20px;
}
You could always try using jQuery to accomplish this. There may be an easier way but my mind is currently focused on jQuery. There is a class that allows you to add or remove something specific. Let's take a look at the jQuery added with this.
jQuery:
$('a').hover(
function() {
var $this = $(this); // caching $(this)
$this.data('initialText', $this.text());
$this.text("I'm replaced!");
},
function() {
var $this = $(this); // caching $(this)
$this.text($this.data('initialText'));
}
);
EDIT: I replaced the add/remove of the classes to using a way where you cache the data you originally had into a variable and as you hover over it, it actually changes to the data you put inside of jQuery function and as you hover out, it will change it back. To be honest, I cannot take credit for this, because it was originally found in this Stack question, meaning, you should just go up vote that answer instead. But this should work with what you want to do.
The JSFIDDLE
If you want to do it with pure css, there are some changes to make. Get rid of the line height, set position on both .see and .show to absolute, set position of pricebar to relative, give the see and show a height and width, put the content for .show above the .see element in your html, and fiddle with a negative margin to line them up.
#pricebar {
width:100%;
height:175px;
background-color:#EAE5E5;
text-align:center;
position:relative;
}
#pricebar .see {
color:#fff;
font-size:50px;
margin-left:-15%;
background-color:#2ecc71;
border:5px solid #2ecc71;
border-radius:5px;
border-left:17px solid #2ecc71;
border-right:17px solid #2ecc71;
transition-duration: .3s;
transition-property: background-color, border, border-left, border-right, opacity;
position:absolute;
height:60px;
width:234px;
top:60px;
}
#pricebar .see:hover {
opacity:0;
background-color:#27ae60;
border:5px solid #27ae60;
border-left:17px solid #27ae60;
border-right:17px solid #27ae60;
}
#pricebar .show {
color:#fff;
font-size:50px;
background-color:#000;
height:60px;
top:60px;
margin-left:-40px;
position:absolute;
}
You can see it in this fiddle