Position span to hang over the relative parent - html

I'm trying to position a span so that it will be above it's sibling and "hang over" or be positioned on top of it's parent. The parent is relatively positioned.
Please view my fiddle to get the whole picture
What it currently looks like...
This is what I want it to look like...
The span (tooltip):
.grid-window span.validation-message:after {
border-color: #F2DEDE transparent transparent;
border-style: solid;
border-width: 8px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 40px;
width: 0;
}
.grid-window span.validation-message {
background: none repeat scroll 0 0 #F2DEDE;
border: 1px solid #EED3D7;
border-radius: 3px 3px 3px 3px;
box-shadow: 1px 1px 2px 0 rgba(0, 0, 0, 0.098);
color: #B94A48;
font-size: 14px;
height: 20px;
left: 263px;
line-height: 20px;
padding: 10px;
position: absolute;
text-align: center;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.098);
top: -26px;
width: 100px;
}
The parent element:
element.style {
display: block;
height: auto;
left: 488px;
outline: 0 none;
top: 100px;
width: 400px;
z-index: 1002;
}
.ui-dialog {
overflow: visible;
padding: 0.2em;
position: absolute;
width: 300px;
}
UPDATE
As suggested by Rohrbs, if I explicitly set the width of the span (tooltip) then it will indeed hang over the form. But this isn't practical since each tooltip could potentially display a different message. So my question now becomes - How can I set the width to be dynamic and still have the span (tooltip) hang over the form?

Style your .grid-window .control-group .controls to be position: relative; then only your absolute positioned .grid-window span.validation-message will work as you want.
See This Fiddle
Update
You wanted to be your tool-tip width variable so I have replaced the position: absolute; to position: relative; in .grid-window span.validation-message and added left: 175px; top: -25px; float: left; and also min-width: 0; max-width: 500px; width: auto; also work. to make this work as you want. Note to float is a must else it won't work.
So, main changes (most important part) are float: left; position: relative; to .grid-window span.validation-message and also you need not to declare position: relative; to .grid-window .control-group .controls
See This Fiddle

If you manually set the width in the class .grid-window span.validation-message to say width: 50%; it will hang over the edge like you want. You will just have to keep the message short enough to ensure proper fitment.

On the .ui-dialog .ui-dialog-content DIV just change the overflow from auto to visible, and it will help

I managed to resolve your issue with only minor changes to your CSS and HTML(class names).
You can see the results via your updated fiddle: http://jsfiddle.net/aNkSw/16/
I added a different class for each span, and tweaked only this CSS bit to:
.grid-window span.validation-message-id:after, .grid-window span.validation-message-name:after {
border-color: #F2DEDE transparent transparent;
border-style: solid;
border-width: 8px;
content: "";
height: 0;
width: 0;
position: absolute;
bottom: -16px;
left: 10px;
}
.grid-window span.validation-message-id {
background: none repeat scroll 0 0 #F2DEDE;
border: 1px solid #EED3D7;
border-radius: 3px 3px 3px 3px;
box-shadow: 1px 1px 2px 0 rgba(0, 0, 0, 0.098);
color: #B94A48;
font-size: 14px;
line-height: 20px;
overflow: visible;
padding: 10px;
position: absolute;
margin: -81px 0 0 0;
left: 292px;
z-index: 99;
text-align: center;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.098);
width: 200px;
}
.grid-window span.validation-message-name {
background: none repeat scroll 0 0 #F2DEDE;
border: 1px solid #EED3D7;
border-radius: 3px 3px 3px 3px;
box-shadow: 1px 1px 2px 0 rgba(0, 0, 0, 0.098);
color: #B94A48;
font-size: 14px;
line-height: 20px;
overflow: visible;
padding: 10px;
position: absolute;
margin: -41px 0 0 0;
left: 292px;
z-index: 99;
text-align: center;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.098);
width: 200px;
}
I can't say I agree with how you coded the whole thing though.

If you could use an extra element here's a solution I use a lot for this kind of positioning:
HTML:
<div class="validation-message-wrapper">
<span class="validation-message" style="">Please enter a number</span>
</div>
CSS:
.validation-message-wrapper {
width:0;
position: absolute;
right: 70px;
top: 0;
height: 0;
}
The clue is to create a zero size reference point ( the .validation-message-wrapper ) position it where you want and then position your element in relation to it.
Here's a working demo: DEMO
I also did some other minor CSS changes just to tune it a bit:
.ui-dialog .ui-dialog-titlebar {
padding: 0.4em 1em;
position: relative;
}
.grid-window span.validation-message:after {
border-color: #F2DEDE transparent transparent;
border-style: solid;
border-width: 8px;
content:"";
height: 0;
left: 0;
bottom: -16px;
position: absolute;
width: 0;
}
.grid-window span.validation-message {
background: none repeat scroll 0 0 #F2DEDE;
border: 1px solid #EED3D7;
border-radius: 3px 3px 3px 3px;
box-shadow: 1px 1px 2px 0 rgba(0, 0, 0, 0.098);
color: #B94A48;
font-size: 14px;
height: auto;
left: 0px;
bottom: 0;
line-height: 20px;
padding: 10px;
position: absolute;
text-align: center;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.098);
margin-top: -40px;
width: 200px;
}
I hope that helps.
If you'd like something more generic I've made a jQuery tooltip plugin (tipy) which is pretty easy to use and implement.

Related

CSS - create a dynamic "tag" shape facing to the right

I'm trying to create a "price tag" shape using CSS, with the sharper edge facing to the right. When the edge of the tag is facing left, there's no problem adding text (be it short or long), since the triangle is static and only the rectangle is stretching.
I need to create the same thing but with "elastic" right facing triangle, to keep using only one class and not a dedicated class for each text length.
For both examples please see this fiddle.
.pricetag {
position: relative;
margin: 0 5px 0 10px;
displaY: inline-block;
height: 46px;
padding: 0 35px 0 15px;
background: #E8EDF0;
font-size: 20px;
line-height: 41px;
}
.pricetag:after {} .pricetag:before {
position: absolute;
content: "";
left: -15px;
width: 1px;
height: 0px;
border-right: 14px solid #E8EDF0;
border-top: 23px solid transparent;
border-bottom: 23px solid transparent;
}
/**********/
.pricetag-right {
position: relative;
margin: 0 5px 0 10px;
displaY: inline-block;
height: 46px;
padding: 0 35px 0 15px;
background: #E8EDF0;
font-size: 20px;
line-height: 41px;
}
.pricetag-right:after {} .pricetag-right:before {
position: absolute;
content: "";
left: 382px;
width: 1px;
height: 0px;
border-left: 14px solid #E8EDF0;
border-top: 23px solid transparent;
border-bottom: 23px solid transparent;
}
<span class="pricetag">no problem with long text</span>
<br>
<br/>
<span class="pricetag-right">need to create a new class for each length</span>
You just need to position the arrow according to the right side of the tag with the right property instead of the left property :
.pricetag {
position: relative;
margin: 0 5px 0 10px;
display: inline-block;
height: 46px;
padding: 0 35px 0 15px;
background: #E8EDF0;
font-size: 20px;
line-height: 41px;
}
.pricetag:before {
position: absolute;
content: "";
left: -15px;
width: 1px;
height: 0px;
border-right: 14px solid #E8EDF0;
border-top: 23px solid transparent;
border-bottom: 23px solid transparent;
}
/**********/
.pricetag-right {
position: relative;
margin: 0 5px 0 10px;
display: inline-block;
height: 46px;
padding: 0 35px 0 15px;
background: #E8EDF0;
font-size: 20px;
line-height: 41px;
}
.pricetag-right:before {
position: absolute;
content: "";
right: -15px;
width: 1px;
height: 0px;
border-left: 14px solid #E8EDF0;
border-top: 23px solid transparent;
border-bottom: 23px solid transparent;
}
<span class="pricetag">no problem with long or short text (length auto adjusts)</span>
<br>
<br/>
<span class="pricetag-right">need to create a new class for each length</span>
<br/>
<br/>
<span class="pricetag-right">need to create a nqsdqsdqsdqsdqsdqsdew class for each length</span>

How to create text stroke and triangle with pure CSS?

I am trying to create a css design like the image attached below. Actually I need to create this style only using CSS without using any images.
I tried get it to work but not sure How to create inner triangle.
This is my HTML -
body {
background: #cdc6e1;
}
.content-box {
background: #28166f;
width: 250px;
height: 100px;
}
.tag {
background: #f8c300;
width: 100px;
height: 0;
padding-left: 10%;
padding-bottom: 10%;
overflow: hidden;
}
.tag:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left: -500px;
border-left: 500px solid transparent;
border-right: 500px solid transparent;
border-bottom: 500px solid #f8c300;
}
<div class="content-box">
<div class="tag">
<h1>1<span>st</span></h1>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>
Hope somebody may help me out to achieve to this custom style.
Thank you.
A basic mockup would be to use some pseudo elements in order to generate this:
.outer {
height: 200px;
width: 400px;
background: purple;
border: 10px solid pink;
position: relative;
text-Align: right;
font-size: 50px;
line-height: 200px;
}
.outer:before,
.outer:after {
height: 0;
width: 0;
position: absolute;
content: "";
border-bottom: 100px solid yellow;
border-right: 70px solid transparent;
border-left: 70px solid transparent;
bottom: 0;
left: 20px;
z-index: 8;
}
.outer:after {
border-bottom: 130px solid blue;
border-right: 90px solid transparent;
border-left: 90px solid transparent;
z-index: 0;
}
.place {
position: absolute;
left: 50px;
color: red;
bottom: -20px;
font-size: 100px;
line-height: initial;
z-index: 10;
text-shadow:
3px 3px 0 white,
/* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
}
<div class="outer">First Place
<div class="place">1st</div>
</div>
Note. The text outline property is yet to be implemented in any of the major browsers yet, so it may require a 'larger white text' to be positioned behind to create this text outline in your mockup.
A workaround (as stateed in the comments) would be to 'hack' the text shadow:
text-shadow:
3px 3px 0 white, /* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
Text Stroke
Although only available in webkit broswers, you may possibly want to use text-stroke for your 'white border' to the text (unavailable in IE or Firefox)
div {
font-size: 50px;
position: relative;
height: 50px;
width: 50px;
color: black;
}
div:before {
content: "1st";
z-index: -1;
left: 0;
top: 0;
position: absolute;
-webkit-text-fill-color: black;
-webkit-text-stroke: 8px red;
}
html {
background: gray;
}
<div>
1st
</div>
<br/>
<strong>Note</strong> only available in webkit browsers
Create a duplicate triangle and place it behind. Code given below. JSBin: http://jsbin.com/totewinizu/2/
HTML:
.tag {
width: 100px;
display: block;
position: relative;
top: 20px;
border-color: transparent transparent red transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
height: 0px;
width: 0px;
z-index: 99;
}
.dupe {
position: absolute;
border-color: transparent transparent white transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
top: 40px;
left: 20px;
z-index: 9;
}
<div class="content-box">
<div class="tag">
<h1>1</h1><span>st</span>
</div>
<div class='tag dupe'>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>

create tag shape with css

I'm trying to create a tag shape with the css only so that it looks like:
I'm trying following but unable to use the border for the triangle area.
HTML:
Test
CSS:
a{
float: left;
height: 35px;
position:relative;
border: 1px solid red;
border-right: none;
width: 100px;
}
a:before{
content: "";
position: absolute;
top: -1px;
right: -18px;
width: 0;
height: 0;
border-color: white white white red;
border-style: solid;
border-width: 19px 0 18px 18px;
}
JSFiddle:
http://jsfiddle.net/Sac3m/
You could rotate a square instead, although i doubt the results will be great cross-browser
Modified code:
a {
float: left;
height: 35px;
position: relative;
border: 1px solid red;
border-right: none;
width: 100px;
}
a:after {
content: "";
position: absolute;
top: 4px;
right: -13px;
width: 25px;
height: 25px;
border: 1px solid red;
border-left: none;
border-bottom: none;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
}
<a></a>
(Latest IE, Firefox and Chrome seems OK with it)
Update
If you need IE8 support, you could try to put a white triangle on top of the (original) red triangle:
a {
float: left;
height: 36px;
position: relative;
border: 1px solid red;
border-right: none;
width: 100px;
}
a:before {
content: "";
position: absolute;
top: -1px;
right: -18px;
width: 0;
height: 0;
border-color: white white white red;
border-style: solid;
border-width: 19px 0 19px 19px;
}
a:after {
content: "";
position: absolute;
top: 0;
right: -17px;
width: 0;
height: 0;
border-color: transparent transparent transparent white;
border-style: solid;
border-width: 18px 0 18px 18px;
}
<a></a>
The below code helps to create a tag shape. It works in all major browsers.
#swc {
position: relative;
margin: 0 5px 0 10px;
display: inline-block;
height: 66px;
padding: 0 35px 0 20px;
font-size: 25px;
line-height: 65px;
cursor: pointer;
font-weight: 100;
margin: 20px 25px;
background: #f3f3f3;
transition: background 0.3s;
}
#swc:after {
position: absolute;
content: "";
right: -19px;
width: 1px;
height: 0px;
border-left: 18px solid #f3f3f3;
border-top: 33px solid transparent;
border-bottom: 33px solid transparent;
transition: border 0.3s;
}
#swc:hover {
background: green;
color: #ffffff;
}
#swc:hover:after {
border-left-color: green;
}
<span class="pricetag-right" id="swc">Tag Content!</span>
We had a slightly different implementation of this that produces rounded corners. This uses a rounded square that's turned 45°.
.tag {
display: inline-block;
border-width: 1px;
border-style: solid;
border-color: #c8d7f2 transparent #c8d7f2 #c8d7f2;
border-radius: .25em 0 0 .25em;
padding: 0.1em 0.6em 0.1em 0.3em;
background-color: #e5ecf9;
line-height: 1.2em;
}
.tag:after {
content: "\25CF";
position: absolute;
display: inline-block;
height: 1.2em;
width: 1.17em;
transform: rotate(45deg);
color: white;
text-indent: 0.3em;
line-height: 1em;
text-shadow: 0 0 1px #333;
background-color: #e5ecf9;
border-radius: 0.33em 0.33em 0.33em 1em;
border-width: 1px;
border-style: solid;
border-color: #c8d7f2 #c8d7f2 transparent transparent;
}
<h1 class="tag">my-tag</h1>
A couple things to note:
The square contains a circle punctuation mark. To adjust it you use line-height and text-indent.
The borders on the square need to be set to transparent color with a width of 1px. If you don't, the other borders (the visible ones) taper off where they go from 1px to 0px.
his works pretty well and it's nearly pixel-perfect, but it does render slightly differently across Chrome and Firefox. I tried to make it work with a transparent background, but you need some sort of color to cover up the funkiness where the square meets the tag. It's not quite perfect.
The nice thing about this is that it can be applied as a class and it can be used on H1-H6, or p tags.

How to make edgy corners with css

Does anyone know how to make edgy corners like in the following below? See how the edge wraps around the corner. I would like to know the term as well (if any). cross browser support (IE8 and up, bonus IE7) is a must. Thanks for any help.
Check out this tutorial. I don't know how crossbrowser compatible it is (as it is CSS3), but it achieves the effect you want.
HTML:
<div>
<h2></h2>
</div>
CSS:
div {
width: 200px;
padding: 50px;
margin: 0 auto;
border: 1px solid #333;
}
h2 {
position: relative;
width: 50%;
height: 50px;
margin: 30px 10px 10px -70px;
background-color: orange;
}
h2:after {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: 0px;
top: 100%;
border-width: 5px 10px;
border-style: solid;
border-color: #666 #666 transparent transparent;
}
JS Fiddle Example
.box{
background: #666;
border: 4px solid #fff;
box-shadow: 0px 0px 20px #000;
width: 200px;
height: 200px;
margin: 40px auto;
position: relative;
}
.ribbon{
background: #FFA500;
position: absolute;
width: 100%;
top: 20px;
left: -20px;
height: 20px;
padding-right: 20px;
}
.ribbon::before{
content: '';
position: absolute;
left: 0px;
top: 20px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 16px 10px 0;
border-color: transparent #FFA500 transparent transparent;
z-index: -5;
}
HTML:
<div class="box">
<div class="ribbon"></div>
</div>
(DEMO)
I don't think IE 7/8 support the ::before pseudo-element, so if you want IE compatibility add another element and put ::before styles on it :)
That edgy corner is only a div with a triangle actually, you only need ONE element to do it.
<div id="myCorner"></div>
myCorner will be the div, and myCorner:after will be the triangle.
Check it out : http://jsfiddle.net/Starx/Xp6E7/2/
#myCorner
{
width:100px;
height:70px;
background-color:orange;
-webkit-box-shadow: 0 4px 5px -3px black;
-moz-box-shadow: 0 4px 5px -3px black;
box-shadow: 0 4px 5px -3px black;
position:relative;
}
#myCorner:after
{
content:"";
position:absolute;
left: 0;
top:100%;
width: 0px;
height: 0px;
border-style:solid;
border-width: 5px 10px;
border-color: orange orange transparent transparent;
z-index: -1;
}

Going Over the Div Width?

I have a set width for my div in CSS, however, I need something inside of that div to go beyond that width, but can't find a solution. Here's my CSS:
#wrapper {
width: 845px;
margin: 0 auto;
}
#wrapper #content {
width: 630px;
float: left;
}
#wrapper #content .post {
background-image: url('images/black_linen_v2.png');
padding: 10px;
color: white; text-shadow: black 0.1em 0.1em 0.2em;
position: relative;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
#wrapper #primary {
color: white;
}
#wrapper #primary .widget-container {
color: white; text-shadow: black 0.1em 0.1em 0.2em;
padding: 10px;
background-image:url('images/black_linen_v2.png');
position: relative;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
And here's what I need to go beyond that area:
/* This is the ribbon effect */
.ribbon {
background: #36ff36;
background: -moz-linear-gradient(top, #36ff36, #21b521);
background: -webkit-gradient(linear, left top, left bottom, from(#36ff36), to(#21b521));
padding: 10px 10px;
margin-left: 50px;
margin-top: 0;
position: relative;
width: 100%;
-moz-box-shadow: 1px 1px 3px #292929;
-webkit-box-shadow: 1px 1px 3px #292929;
/*round the top corners */
-webkit-border-top-left-radius: 10px ;
-webkit-border-top-right-radius: 10px;
-moz-border-top-left-radius: 10px ;
-moz-border-top-right-radius: 10px ;
border-top-right-radius: 10px ;
border-top-left-radius: 10px ;
color: #454545;
text-shadow: 1px 1px 0 #36ff36;
text-align:center;
}
.arrowl {
width: 0; height: 0;
line-height: 0;
border-left: 20px solid transparent;
border-top: 10px solid #21b521;
top: 104%;
left: 0;
position: absolute;
}
.arrowr {
width: 0; height: 0;
line-height: 0;
border-right: 20px solid transparent;
border-top: 10px solid #21b521;
top: 104%;
right: 0;
position: absolute;
}
#footer {position: relative;
background-image:url('../images/footer.png');
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;}
/* End of ribbon effect*/
The set width conflicts with the ".ribbon", which I need to go beyond that set width.
Help is appreciated!
Please post your HTML it it will be a guessing game. However in if you want to create some items which is outside its container, you need to set overflow property on the container.
Set overflow:visible on #wrapper and use a width that is larger (110%) for .ribbon or padding.
You could set the object as fixed position. Then define the position and dimensions. Be sure your parent container has the property overflow:visible. your child element will look like this
position: fixed;
width:*;
height:*;