Floated ::after interacting with block-level sibling - html

I'm having an interaction that I don't quite understand. I'm building a progress bar (seriously, can we have the entire standard implemented yet?) that displays info based off of data-* attributes, so I'm using :before and :after to display the labels.
I've got it in a fiddle: http://jsfiddle.net/WtrfL/
HTML:
<div class="wrap">
<div class="inner">
</div>
</div>
Styles:
.wrap {
width:500px;
height:2em;
border:1px solid black;
}
.wrap:before {
content:"1";
float:left;
border:1px solid black;
}
.wrap:after {
content:"2";
float:right;
border:1px solid black;
}
.inner {
width:30%;
height:100%;
background-color:#DDD;
border:1px solid #888;
}
Unfortunately, I'm having this happen:
I'd expect the [2] to be inside of the main bar, not underneath it.
I'm seeing the same behavior in IE9 and Chrome 27 on Windows, so I'm pretty sure this is me misunderstanding the way these things are supposed to work, not a bug in a rendering engine.
So... what's up? Any ideas? I'm good with a hack, this is just a prototype for the present.

I never use floats on pseudo elements. I would position them absolute. Something like this:
.wrap {
width:500px;
height:2em;
border:1px solid black;
position: relative;
}
.wrap:before {
content:"1";
position: absolute;
left: 0;
top: 0;
border:1px solid black;
}
.wrap:after {
content:"2";
position: absolute;
right: 0;
top: 0;
border:1px solid black;
}
I tested it in your fiddle and looks fine! http://jsfiddle.net/WtrfL/1/

Related

How to make a CSS3 chart with position:absolute; work in a box that has a display:inline-block;

Please, no javascript.
Imagine this if you will. A page that has hundreds of boxes with each box containing a joke, cite, image... (all boxes with a display:inline-block;).
Now I'm trying to place A chart with a few components with position:absolute; and left: in one of the display:inline-block; boxes with no luck. The chart shows at the left side of the page with the next joke box underneath it.
How do I control it?
Cheers, All.
Part 2 (my box code):
.boxDarth{
border-radius:5px;
border:1px solid #663810;
box-shadow:-3px 5px 4px #000000;
margin:6px 3px;
padding:6px;
display:inline-block;
line-height:1.5;
text-align:left;
text-decoration:none;
font-weight:lighter;
letter-spacing:1.4;
text-shadow:-1px 1px 1px #37363b;
word-wrap:break-word;
vertical-align:top;
position:relative;
}
The chart ccs is quite long. If what I provide here is not enough, and since I've never asked a question here; should I paste it here? upload a file?
.pie{
position:absolute;
width:100px;
height:200px;
overflow:hidden;
left:150px;
-moz-transform-origin:left center;
-o-transform-origin:left center;
-webkit-transform-origin:left center;
transform-origin:left center;
}
The container should have position: relative as a CSS attribute
The chart has to be a child of the inline block box, and the box needs to have position: relative; on it.
.inline-box {
display: inline-block;
background: violet;
width: 300px;
height: 300px;
position: relative;
}
.chart {
position: absolute;
left: 0;
top: 0;
width: 150px;
height: 150px;
background: cornsilk;
}
<div class="inline-box">
<div class="chart">
hi, I'm an absolutely positioned chart inside of a relatively positioned inline box
</div>
</div>

Boxes with angled bottom and top

I would like to know how can I make in CSS3 angled boxes. Like this site:
http://themeluxe.com/themes/glissando/ (the whites ones)
And how can I make the borders look better, smooth.
Looking on their code, I found this css:
.container:before, .container:after {
border-bottom: 80px solid transparent;
border-left: 110vw solid transparent;
content: "";
display: none;
height: 0;
margin-top: -80px;
position: relative;
width: 0;
}
But is not working for me.
In the website you link to they use the "border technique" to create the oblique boxes on pseudo elements you may understand this technique in this SO question.
Here is a simple fiddle using this technique to create the oblique bottom and top. It should help you understand how it works :
DEMO
HTML :
<div></div>
<div class="second"></div>
CSS :
body{
margin:0;
padding:0;
}
div{
height:200px;
background:teal;
position:relative;
}
.second{
background:gold;
}
.second:before{
content:'';
position:absolute;
bottom:100%;
border-left:100vw solid transparent;
border-bottom: 80px solid gold;
}
You should also be aware that in the website you link to, they are using vw units. They are not supported by IE8-

Having an arrow on the left side of my colored div

Let's say I have the following rectangle box (this is a div) and I would like to represent an arrow on the left side. I was searching for a really simple way of doing but every solution I found is a little tricky for my purpose.
<div class="redbox">
<b>Hello world</b>
</div>
.redbox {
display: inline-block;
padding: 5px;
background-color: red;
}
http://jsfiddle.net/3N6yP/
How to transform this simple div to show an arrow on the left side?
Something like it:
Here am using a CSS triangle which is positioned absolute to the element, and than and using :before pseudo, so that, it creates virtual element for you. This will just save you few characters in the DOM. Just make sure you use position: relative; for the element having class .redbox, so that the absolute positioned virtual element doesn't fly away in the wild.
Demo
.redbox:before {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right:15px solid #f00;
top: 0;
left: -15px;
}
You can use this cross-browser generator: http://cssarrowplease.com/
I've found that the "border trick" sometimes has unpredictable margin offsets across different browsers (and of course depending on your markup) and prefer other methods.
I'd personally use a proven method and use an image. Depending on your situation you can just have one sprite image or you can wrap your arrow and content.
http://jsfiddle.net/3N6yP/5/
HTML:
<div class="redbox">
<span></span><div>Hello World</div>
</div>
CSS:
.redbox {
display: inline-block;
padding: 5px;
background-color: red;
}
.redbox div{
height:30px;
background:#ff0000;
display:inline-block;
line-height:30px;
}
.redbox span{
float:left;
display:block;
height:30px;
width:20px;
background:#333333 url(http://i.stack.imgur.com/cUsjz.png) center left no-repeat;
}

Trailing Line Decoration Headers in CSS

I am trying to create header tags with a bit of fancy decoration.
Eventually, I want to arrive at this:
I am having trouble adding the trailing line decoration after the text though.
My original thoughts were to have a container, then in that container would be the h1 and a span tag that would contain the line. But I can't quite seem to get the line to be centered with the text sitting over it.
I tried:
.container {
width: 100%;
}
h1 {
display: inline;
position: relative;
z-index: 2;
}
span {
display: inline-block;
height: 50%;
width: 100%;
border-bottom: 1px solid red;
}
and the HTML
<div class="container">
<h1>Test</h1>
<span></span>
</div>
But had no luck. Anyone know any tricks that might help me accomplish this? The main thing is that the length and height of the text is variable, so I am trying to get the line to take up the remainder of the box and sit right in the middle.
I also tried display: table-cell with no luck...
You need something like this
html - <h2>Test</h2>
css
h2{
position:relative;
overflow:hidden;
}
h2:after {
content:"";
top:48%;
width:100%;
margin-left:10px;
height:5px;
position:absolute;
background:orange;
}
How about using css pseudo elements like :after?
HTML
<div class="foo">INSIGHT</div>
CSS
.foo {
position: relative;
color: orange;
overflow: hidden;
}
.foo:after {
content: "";
position: absolute;
width: 90%;
top: 50%;
margin-left: 10%;
border-top: 3px solid orange;
}
DEMO

Centering 2 Divs in a wrapper CSS IE trouble

I am trying to place two divs on the same line (preferably centered) inside a wrapper div. The code I have written works great in FF and IE10. Almost every version of IE <10 doesn't like it. Can anybody help, thanks!
html:
<div id="home_wrapper">
<div id="links_location" class="shadow">content</div>
<div id="iframe_location" class="shadow">content</div>
</div>
css:
#home_wrapper {
width: 100%;
text-align: center;
border: 1px solid blue;
float:left;
}
#links_location, #iframe_location {
display: inline-block;
background-color:White;
!important
}
#links_location {
width:20%;
height:400px;
text-align:left;
border: 1px solid red;
}
#iframe_location {
height:400px;
width:70%;
border: 1px solid black;
}
jsfiddle JSFiddle
How about:
#links_location, #iframe_location
{
background-color:White;
float: left;
}
Is it what you wanted? Updated jsfiddle
*Update*
Everything works fine for me in all IE versions if you place !important after white, like this background-color: White !important;. You screw up your css by placing it after semicolon :)