CSS - inline not working with position absolute - css

Here is an image of what I'm trying to achieve.
HTML:
<h2>Some text<br /> even more text</h2>
CSS
Works
display: inline;
line-height: 1.7em;
font-size: 65px;
color: #333;
background-color: #FFF;
box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
Doesn't work
display: inline;
line-height: 1.7em;
position: absolute;
top: 80px;
z-index: 2;
font-size: 65px;
color: #333;
background-color: #FFF;
box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
Any idea on how to fix this?

inline implicitly becomes block when you absolutely position an element, see
Css 2.1, 9.7 Relationships between 'display', 'position', and 'float'
You will need to use an additional inline element inside this heading, if you want to achieve this effect.

Three steps:
Wrap each part of the <h2> heading in a <span>
Give each span a display of inline-block
Apply the box-shadow to each span
Working Example:
h2:nth-of-type(1) {
display: inline;
line-height: 1.7em;
font-size: 18px;
color: #333;
background-color: #FFF;
box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
}
h2:nth-of-type(2) {
display: inline-block;
position: absolute;
top: 80px;
z-index: 2;
color: #333;
background-color: #FFF;
}
h2:nth-of-type(2) span {
display: inline-block;
font-size: 18px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
<h2>Some text<br />even more text</h2>
<h2><span>Some text</span><br /><span>even more text</span></h2>

Related

How to stop :before element to push label text to the right

In my project we needed to style the checkbox element. I have seen that a common aproach is to style the :before element of the associated label instead.
So far I have managed to implement most of it, but I am having an issue with the :before element pushing the first line of the label text to the right.
I am trying to align all the text in the label to the right of the :before element, but so far the second line always starts at the same place than the :before element.
I am not a frontend dev, but I have tried changing padding, margin, left, position, etc. But I am at a loss.
This is how it looks:
I want all the text of the label ot start at the red line.
You can see what I have so far in this Fiddle.
.container-box{
display:block;
max-width:200px;
}
.neat-checkbox {
display: inline;
width:40px;
}
.neat-checkbox input[type=checkbox] {
position: absolute;
top: 0;
left: 0;
margin-left: 0;
cursor: pointer;
opacity: 0;
z-index: 1;
font-size: 10px !important;
display: none;
}
.neat-checkbox label {
margin-left: 0px;
margin-top: 2px;
line-height: 17px !important;
}
.neat-checkbox label:before {
font-family: "FontAwesome";
content: "\f00c";
color: white;
position: relative;
left: -5px;
top: 0px;
outline: none;
cursor: pointer;
display: inline-block;
width: 17px;
height: 17px;
border: 1px solid #ced4da;
border-radius: 3px;
background-color: #fff;
transition: border 0.15s ease-in-out, color 0.15s ease-in-out;
box-sizing: border-box;
font-size: 11px;
padding-left: 2px;
line-height: 17px;
}
.neat-checkbox input[type=checkbox]:checked + label:before {
background-color: #2bb19e;
border-color: #2bb19e;
color: #fff;
font-family: "FontAwesome";
content: "\f00c";
font-size: 11px;
padding-left: 2px;
line-height: 17px;
}
.neat-checkbox input[type="checkbox"]:focus + label::before {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
<div class="container-box">
<div>
<label>Some other stuff</label>
</div>
<div class="neat-checkbox">
<input type="checkbox" class="checkbox-list" id="checkboxId_25600" name="name_25600" value="25600">
<label for="checkboxId_25600">Label For Checkbox MOre more more</label>
</div>
</div>
Give the label some left padding and position the :before element absolutely within it. EG:
.container-box {
display: block;
max-width: 200px;
}
.neat-checkbox {
display: inline;
width: 40px;
}
.neat-checkbox input[type=checkbox] {
position: absolute;
top: 0;
left: 0;
margin-left: 0;
cursor: pointer;
opacity: 0;
z-index: 1;
font-size: 10px !important;
display: none;
}
.neat-checkbox label {
margin-left: 0px;
margin-top: 2px;
line-height: 17px !important;
display: inline-block; /* make it block-level */
position: relative; /* so that child elements can be positioned relative to it */
padding-left: 25px; /* allow some space for the pseudo checkbox */
}
.neat-checkbox label:before {
font-family: "FontAwesome";
content: "\f00c";
color: white;
left: 0px;
top: 0px;
outline: none;
cursor: pointer;
display: block; /* make it block-level */
position: absolute; /* give an absolute position (defaults to 0,0) */
width: 17px;
height: 17px;
border: 1px solid #ced4da;
border-radius: 3px;
background-color: #fff;
transition: border 0.15s ease-in-out, color 0.15s ease-in-out;
box-sizing: border-box;
font-size: 11px;
padding-left: 2px;
line-height: 17px;
}
.neat-checkbox input[type=checkbox]:checked+label:before {
background-color: #2bb19e;
border-color: #2bb19e;
color: #fff;
font-family: "FontAwesome";
content: "\f00c";
font-size: 11px;
padding-left: 2px;
line-height: 17px;
}
.neat-checkbox input[type="checkbox"]:focus+label::before {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
<div class="container-box">
<div>
<label>Some other stuff</label>
</div>
<div class="neat-checkbox">
<input type="checkbox" class="checkbox-list" id="checkboxId_25600" name="name_25600" value="25600">
<label for="checkboxId_25600">Label For Checkbox MOre more more</label>
</div>
</div>
The problem is that you are moving the checkbox using position relative, so the original space is preserved but you just move the visual 5px to the left.
You can add a margin-right: -5px if you use left: -5px or remove the left property and just use margin-left: -5px instead.

Hover on a table-cell css displayed on all row

I'm struggling to understand why my container (table-cell) don't behave how I wish I want :)
Situation : I created a div container (bouton) with 2 div inside (image and text).
What I want : hover anywhere on the container will apply a background-color.
Problem : I added a background-color hover to the div container (bouton) but instead of just applying it to all the div "bouton" it applies it to the all row.
Here is the Fiddle : https://jsfiddle.net/gicspy/qotv4yz0/3/
HTML :
<div id="bouton">
<a href="/test/" title="test">
<div class="bouton-image">
<img class="clear-btn-devis" src="http://via.placeholder.com/100x120" width="100" height="120">
</div>
<div class="bouton-texte">
THIS IS CONTENT FOR THE BUTTON
<br /><span style="font-size:90% !important;"><p style="line-height: 1 !important;">(with more information even)</p></span>
</div>
</a>
</div>
CSS :
#bouton div {
display: table-cell;
cursor: pointer;
background-color: #1ac658;
color: #ffffff !important;
padding: 5px;
border: 0px;
margin: 4px 2px;
margin-top: 20px;
margin-bottom: 20px;
text-align: center;
vertical-align: middle;
max-width: 300px;
}
.bouton-image {
display: table;
border-radius: 3px 0px 0px 3px;
min-width: 70px !important;
margin: auto;
text-align: center;
overflow: hidden;
}
.bouton-texte {
border-radius: 0px 3px 3px 0px;
font-size: 130%;
text-decoration: none;
font-weight: bold;
}
#bouton:hover,
#bouton:active {
-webkit-transition-duration: 0.4s;
background-color: #f6416c !important;
box-shadow: 0 6px 13px 0 rgba(0, 0, 0, 0.2), 0 4px 16px 0 rgba(0, 0, 0, 0.19);
}
I've been looking but I'm missing something on how the table-cell behaves.
Any one can help ?
Thanks a lot,
You applied the background and shadow to #bouton. You need to apply it to the divs inside it:
#bouton div:hover,
#bouton div:active
This will give you what you want, but you have several other issues:
You cannot place div inside a.
You're trying to display table inside cell, which doesn't make sense.
You don't even need these display types. The div is capable of doing what you want without changing its display type.
Here is some code that gets you close to what you want. You can tweak it to your liking, but it will get you started:
#bouton a {
display: block;
border-radius: 3px;
background-color: #1ac658;
padding: 5px;
margin: 4px 2px;
text-align: center;
vertical-align: middle;
width: 400px;
}
.bouton-image {
display: inline-block;
min-width: 70px;
text-align: center;
overflow: hidden;
float: left;
}
.bouton-texte {
display: inline-block;
font-size: 130%;
color: #ffffff;
text-decoration: none;
font-weight: bold;
text-align: center;
vertical-align: middle;
max-width: 300px;
}
#bouton a:hover,
#bouton a:active {
-webkit-transition-duration: 0.4s;
background-color: #f6416c !important;
box-shadow: 0 6px 13px 0 rgba(0, 0, 0, 0.2), 0 4px 16px 0 rgba(0, 0, 0, 0.19);
}
<div id="bouton">
<a href="/test/" title="test">
<span class="bouton-image">
<img class="clear-btn-devis" src="http://via.placeholder.com/100x120" width="100" height="120">
</span>
<span class="bouton-texte">
THIS IS CONTENT FOR THE BUTTON
<br /><span style="font-size:90% !important;"><p style="line-height: 1 !important;">(with more information even)</p></span>
</span>
<br style="clear: both;" />
</a>
</div>

Using pseudoelements for box-shadow, z-index behavior

I use a :before and :after pseudoelements to create a custom-shaped shadow on my text card. I use css like this (jsFiddle):
.card {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
float: left;
width: 310px;
height: 310px;
text-align: center;
color: black;
padding-top: 35px;
border: 1px solid black;
}
.card h1 {
font-size: 15px;
font-weight: bold;
line-height: 17px;
font-style: italic;
margin: 0;
}
.card .text {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
margin: 8px auto;
padding: 15px 10px;
font-size: 13px;
text-align: left;
line-height: 14px;
height: 170px;
width: 280px;
background: white;
border-radius: 5px;
position: relative;
color: #222222;
}
.card .text:before,
.card .text:after {
-webkit-box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
-moz-box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
content: "";
display: block;
position: absolute;
z-index: -1;
top: 50%;
bottom: 0;
left: 40px;
right: 40px;
border-radius: 100px/10px;
}
.card .text:after {
-webkit-transform: skew(8deg) rotate(3deg);
-moz-transform: skew(8deg) rotate(3deg);
transform: skew(8deg) rotate(3deg);
right: 10px; left: auto;
}
So far so good. Problems start, when i add some background to my .card element, for example background: #0aabff (jsFiddle #2). Notice, pseudo-elements shadow around .text disappeared.
I tried solving this by adding z-index to my .text element, but then, instead of being behind my .text element, my :before, :after are displayed before it, despite having a z-index: -1; property (jsFiddle #3).
This makes little sense to me, and i still don't know how to solve this kind of problem. Perhaps, there is some kind of workaround, or another way to get the kind of shadow i need (original idea is the courtesy of css-tricks.com);
You can add a z-index lower than -1 to your card class.
.card {
z-index:-2;
position:relative;
}
This is because your z-index of your pseudo-elements is lower than the default z-index value of card. By default is the background transparent and you may see the shadow. When you add a background-color then this is positioned above your pseudo-elements.
See http://jsfiddle.net/71thws1a/3/
The problem lies in the stacking of css as mentioned by #Doodlebunch

Align number beside glyphicon

I cannot seem to get this number to align inline to the glyphicon. I want the number 3 to be pushed up more so that it lines up.
CSS
body {
background-image: url("bg1.png");
}
.icons {
margin: 0px 0px 0px 10px;
}
.well {
min-height: 20px;
padding: 20px;
margin-bottom: 20px;
background-color: #ecf0f1;
border: 1px solid transparent;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
}
.well blockquote {
border-color: #ddd;
border-color: rgba(0, 0, 0, 0.15);
}
.well-lg {
padding: 10px;
border-radius: 6px;
}
.well-sm {
padding: 9px;
border-radius: 3px;
}
#alertbox {
padding: 2px 2px 2px 2px;
text-align: center;
}
#topicon {
font-size: 50px;
}
#stats {
font-size: 50px;
display: inline-block;
float: right;
}
HTML
<div class="col-md-3">
<div class="well well-lg">
<div id="alertbox" class="alert alert-info">Total APIs</div>
<span id="topicon" class="glyphicon glyphicon-tasks"></span>
<span id="stats">3</span>
</div>
</div>
Screenshot
using the positioning doesnt work when scaling since the number 3 would go into the center when on a mobile phone. I need it to auto-scale i guess for smaller browsers.
If you remove the float from #stats, you could do something like this:
.well {text-align: justify;}
.well:after{content:""; width: 100%; display: inline-block; height: 0;}
span {display: inline-block; vertical-align: middle;}

CSS tooltip on image problem

I've got a problem with a CSS tooltip over an image. Using it on text works fine, however when I use an image instead of text, it seems to be having issues, the issues are a bit hard to explain so I'll just give you a link:
http://zorps.dk/css-tooltips/tooltip.html
CSS code:
.tooltip {
border-bottom: 1px dotted #000000; color: #000000; outline: none;
cursor: help; text-decoration: none;
position: relative;
}
.tooltip span {
margin-left: -999em;
position: absolute;
}
.tooltip:hover span {
border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
font-family: Calibri, Tahoma, Geneva, sans-serif;
position: absolute; left: 1em; top: 2em; z-index: 99;
margin-left: 0; width: 250px;
}
.tooltip:hover img {
border: 0; margin: -10px 0 0 -55px;
float: left; position: absolute;
}
.tooltip:hover em {
font-family: Candara, Tahoma, Geneva, sans-serif; font-size: 1.2em; font-weight: bold;
display: block; padding: 0.2em 0 0.6em 0;
}
.classic { padding: 0.8em 1em; }
* html a:hover { background: transparent; }
.classic {background: #FFFFAA; border: 1px solid #FFAD33; }
html code:
<p> <a class="tooltip" href="#"> <img src="icon_question.png" /> <span class="classic">The tooltip text goes here!</span></a></p>
Anyone know what the issue is?
Thanks!
Note: the code is taken from: http://sixrevisions.com/css/css-only-tooltips/
It's the code within the .tooltip:hover img class - If you remove it, it works well:
http://jsfiddle.net/RyRRM/
it's probably because the event is triggered by the tooltip's non-text-node parent. When you hover over the image, it detects a mouseout event for the parent. You could try making the image a css background and setting the width of the element instead of embedding the <img>
Your markup could then be
<a class="tooltip image" href="#"><span class="classic">The tooltip text goes here!</span></a>
and your css would be
.tooltip.image {
width: 12px;
height: 14px;
background-image: url("./icon_question.png");
display: block;
background-repeat: no-repeat;
}

Resources