CSS: Adding Divs to a Div (rounded corner discussion) - html

I'm currently using a combination of CSS and Div tags to achieve rounded corners on a text element. This is the CSS I'm using:
div#installerSearch {
float: left;
position: relative;
color: #000055;
width: 154px;
border: 1px solid #2A5390;
padding: 8px;
background-image: url('images/background.png');
}
div.roundAllGreen {
position: absolute;
width: 8px;
height: 8px;
background-image: url('images/roundgreenthingy.png');
}
div.roundTopLeft {
left: -1px;
top: -1px;
background-position: 0px 0px;
}
div.roundTopRight {
right: -1px;
top: -1px;
background-position: -7px 0px;
}
div.roundBottomLeft {
left: -1px;
bottom: -1px;
background-position: 0px -7px;
}
div.roundBottomRight {
right: -1px;
bottom: -1px;
background-position: -7px -7px;
}
and this is the resulting HTML:
<div id="installerSearch">
<div class="roundAll roundTopLeft"></div>
<div class="roundAll roundTopRight"></div>
<div class="roundAll roundBottomLeft"></div>
<div class="roundAll roundBottomRight"></div>
<p> ... </p>
</div>
Can anyone else spot the issue? I've resorted (for lack of a better method) to including presentation in the form of markup, which makes this a little difficult to re-theme, as I'm trying to do.
What I'd really like would be the ability to have CSS add div tags inside a container div for me. I realize that this breaks the "no content in CSS" rule on a code level, but considering that my rounded corners hardly qualify as content it doesn't break it in my book.
So I guess what I'm asking is, is there a good way to accomplish the same effect (rounded corners using images) without needing to introduce extra tags into my content using CSS? The idea here is to end up with a CSS sheet that I can swap out completely without needing to make modifications to my template HTML page, but if that's not possible I'd accept that as an answer. It just seems that google is utterly failing on me this time. ^_^

Short answer: there is not currently a well-supported CSS-only way to do this.
If you can't wait around for CSS3 support, you may want to look in to JavaScript alternatives. Nifty Corners Cube will add rounded corners, and claims to even anti-alias. There are also many jQuery corner plugins, and this one does many different corner effects.
Is there a particular reason you want to use images for the corners? If all you need is a round corner, you may be able to get by using the aforementioned JavaScript solutions. I would really recommend looking at the Nifty Corners Cube examples.
Edit: If you are concerned about extra markup harming your search engine efficiency, then a JavaScript solution would make even more sense (although a CSS-only solution would be best in my opinion) because the extra markup would be added client-side. I have worked with a few search engines and they purposely strip out script tags before indexing the content.

Can anyone else spot the issue?
The difference in className between roundAll and roundAllGreen?
I've resorted (for lack of a better method) to including presentation in the form of markup, which makes this a little difficult to re-theme, as I'm trying to do.
Some sort of interference with the markup is unavoidable until such time as (a) IE supports border-radius, or (b) multiple background images on a single element become possible.
Another possibility with somewhat less interference is background nesting:
<div class="box"><div><div><div>
Hello
</div></div></div></div>
.box { background: url(topleft.png) top left no-repeat; }
.box div { background: url(topright.png) top right no-repeat; }
.box div div { background: url(bottomleft.png) bottom left no-repeat; }
.box div div div { background: url(bottomright.png) bottom right no-repeat; }
In your current page the width of the box is fixed, so you can get away with only two nested divs, one for the top edge and one for the bottom.

You can write JavaScript that will add those divs for you. But it's a huge problem in CSS, it does depend on the content anyway whatever others might say.

Another jquery plugin that works very nice: Anti-aliased Rounded corners with JQuery

one mod to bobinces's solution:
<div class="box"><div><div><div>
Hello
</div></div></div></div>
.box { background: url(topleft.png) top left no-repeat; }
.box>div { background: url(topright.png) top right no-repeat; }
.box>div>div { background: url(bottomleft.png) bottom left no-repeat; }
.box>div>div>div { background: url(bottomright.png) bottom right no-repeat; }

Related

Drawing a wind turbine generator with css & html or canvas?

I am looking for an advice. I have to draw a wind turbine generator. I'm guessing its possible with html, css or canvas but maybe it would take ages.
I have in mind to do it with just images, have the main image for the generator and then have other images over the main one. I think it's the easiest solution to achieve it.
It has to have responsive as well.
The small pieces change the color depending on the data. So I am thinking to replace the images depending on it.
Any recommendation?.
Thanks in advance.
You could skin this cat in several ways, but if you're sure that these are all the components you need (and you won't need to keep expanding it), I agree that canvas is overkill.
Probably all you need is some markup like this:
<div id="turbine">
<div id="injector"></div>
<div id="motor"></div>
<div id="block"></div>
<div id="battery"></div>
</div>
And some CSS that looks something like this:
#turbine {
background: url("turbine-main.png");
position: relative;
}
#injector {
background: url("injector-green.png");
position: absolute;
left: 160px;
top: 130px;
width: 40px;
height: 30px;
}
#injector.failing {
background: url("injector-red.png");
}
#motor {
background: url("motor-green.png");
position: absolute;
left: 220px;
top: 140px;
}
#motor.failing {
background: url("motor-red.png");
}
Rinse and repeat for each part (adjusting image names, coordinates, and size as necessary, so that your pieces fit nicely over the main image). Add and remove the failing class from your individual pieces to toggle the red/green for each part, probably using javascript. (Or just do it in the HTML, if this is a statically rendered page.)
If you should be able to click these engine parts and jump to additional information, replace my <div>'s with <a>'s.

Fixed placement of element, but considering pseudo before element

I have an annoying issue with the html layout of a form. I cannot really change the general setup, since it is part of a huge framework. But I have to "move" a button to a more suitable location. I am close, but not happy with the solution so far. Maybe you can give me some idea in this. Here is a dramatically simplified version to demonstrate my approach:
I have two container divs, top and bottom.
The top container shows a button on the left side. That button is fixed, but can have a different width due to the translation of its label.
The bottom container holds lots of stuff. Amongst that a second button at its top which works fine, but looks wrong. I want to optically move it into the top container, since there is a logical connection to the button in there. Sure, really placing it in there would be the correct solution, but I currently cannot do that. Instead I use a fixed position which works fine, except for the horizontal placement. I have to decide how far pushed from the left to place the button, so that it certainly does not overlap the first button in the container. I obviously have to consider all translations, the result works, but depending on the first buttons label I have an annoying horizontal gap between the two buttons.
I tried to use a pseudo element (::before) on the second button to help with the layout. Since when rendering the view I obviously have the translated label of the first button I can copy that into some property of the second button and use that property in my css to fill a before pseudo element of the second button which has exactly the same length as the first button. That is what is shown in the code example posted below.
What I completely fail to do is to place that pseudo element such that is it left in the top container (so exactly below the first button). The idea is to indirectly place the second button that way. Looks like this is not possible, obviously. But since I am a bloody beginner in markup and styling I thought it might be worth asking here...
Below is some drastically stripped down code to demonstrate my approach.
I create a jsfiddle for you to play around with. Here is the code:
HTML:
<div id="top-container">
<button>multilingual button text</button>
</div>
<div id="bottom-container">
<h2>
Some title opening the bottom container
<span class="into-top-container">
<button id="place-me" reference-text="multilingual button text">button to be placed</button>
</span>
</h2>
<p>Some content</p>
<p>Some content</p>
<p>Some content</p>
</div>
CSS:
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
div {
margin: 0;
padding: 5px;
}
button {
margin: 0;
padding: 5px;
white-space: nowrap;
}
div#top-container {
width: 100%;
border: 1px solid green;
}
div#bottom-container {
width: 100%;
border: 1px solid blue;
}
#place-me {
position: fixed;
top: 0;
left: 400px;
margin: 5px;
background: yellow;
}
#place-me::before {
z-index: 0;
/*visibility: hidden;*/
position: absolute;
content: attr(reference-text);
margin: 0 5px;
padding: 0;
background: gold;
right: 100%;
}
Notes:
that in the above code the second button is placed with left: 400px;. That is more or less what I want to change. But obviously left: 0 is not correct...
the visibility css rule for the pseudo element is currently commented out for demonstration purpose
keep in mind that the second button is *not* contained inside the top container, but actually logically below the title of the bottom container. The goal is to move it optically up into the top container which already is where close to what I want. Except for the horizontal alignment...
Upon request here is a screenshot:
It is taken from the fiddle I posted above. I added the red ellipse which shows what element pair I want to move and the left pointing arrow indicating where I want to move that too. I want to move it exactly that far, that the two tests "multilingual button text" are exactly placed on top of each other, but without specifying an explicit left placement obviously. That is why the pseudo element exists: as a dummy placeholder. I would then hide that pseudo element and have the second button placed exactly right of the first button, regardless of how long the translated text in there is.
So the final result should like like that:
OK, I invested some more time, since this issue popped up again after a regression in our code and I found, as often after allowing some time to pass, a logical and relatively clean solution:
I use the same stripped down code to for demonstration purposes.
The jsfiddle is based on the one provided in the question itself.
HTML: no real change, except for the reference-text having moved from button to container, for the why see below:
CSS:
* {
font-size: 12px;
font-weight: normal;
font-family: Arial;
}
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-size: 12px;
font-weight: normal;
}
span,
div {
margin: 0;
padding: 5px;
}
button {
margin: 0;
padding: 5px;
white-space: nowrap;
}
div#top-container {
width: 100%;
border: 1px solid green;
}
div#bottom-container {
width: 100%;
border: 1px solid blue;
}
span.into-top-container {
position: fixed;
top: 0;
left: 0;
pointer-events: none;
border: 1px solid transparent;
}
span.into-top-container::before {
visibility: hidden;
content: attr(reference-text);
position: relative;
margin-right: 5px;
padding: 5px;
border: 2px solid;
background: gold;
}
#place-me {
background: yellow;
pointer-events: all;
}
The basic change in strategy: it is the container holding the button to be placed that has to be positioned in a fixed manner, not that button itself (so the <span class="into-top-container">)! That allows to use the pseudo before element, now also anchored to that container, not the button, to take the space as required without actually getting part of the button itself.
Since that container is now place over the original multilingual button that one is not clickable any more. That issue is fixed by a css pointer-events set to none for the container and set to all for the placed button again. That makes the container itself simply ignore all events (clicks) and have them passed to the original button beneath.
I had to make sure that the font used inside the pseudo element is style exactly like the original multilingual button. That actually makes sense, since the font styling defines the actual width used by that button, so the actual width used by the pseudo element should be defined in exactly the same manner. In the example above I forced that by simply setting all elements font style rules to some fixed values (the initial * {...} in the CSS code). That can obviously also be done right inside the css rules for the pseudo element itself. I chose the more simple and brute variant here to keep the code clean.

2 background images in one div/table?

I am trying to design a layout for my forum that has 2 background images on a div or a table. I got the idea after looking at this forum's design (http://s4.zetaboards.com/APTSecretServices/index/) If you see on the main category labeled "Category" it contains 2 background images. From exploring the CSS (http://s4.zetaboards.com/c/35079/404/css.css) I found out it was labeled h2left and h2right.
Code:
.h2left {
background: url(http://z4.ifrm.com/30294/164/0/p1083155/h2left.png) no-repeat;
}
.h2right {
background: url(http://z4.ifrm.com/30294/164/0/p1083156/h2right.png) no-repeat right
top;
height: 40px;
}
After seeing this I realized they used the h2, and then on the forum they combine it all together somehow It appears to be done by this code
<table class="cat_head"><tr><td>
<h2>
Category
</h2>
</td></tr></table>
Which is very confusing considering I can't find any proof on how they combined the two.
If you don'y have to support IE<8 than the clean solution is to use pseudo-selectors :before and :after. They really contain unleashed power!
Check the browser support: http://caniuse.com/css-gencontent
In the case of IE6, IE7 the user get only background declared on 'real' DOM element.
Remember that pseudo elements :before and :after cannot be used on empty elements (like images) - because there are 'injected' into element before first (:before) and last (:after) node. Remember that you have to include 'content' declaration inside :after and :before to display the declared styles, too.
On more complicated layouts you can get very nice effects by using "position: absolute" and "z-index" (1.stacking context will prevent layers overlapping by complicated layouts, 2. for IE8 z-index by pseudo-elements don't work, so layers are displayed in the same order as rendered in DOM)
More about pseudo element is nice explained there:
http://www.hongkiat.com/blog/pseudo-element-before-after/
So, conclusion:
<tr>
<td>
<h2 class="table-header">Some text</h2>
</td>
</tr>
.table-header {
/* EDITED: didn't put position on affected element, first that makes the coordinates of :after elements to be calculated from the right element. Sorry! */
position: relative;
/* if element is h2 than we got already "display: block" => width: 100%, height:auto */
font-size:1.5em;
line-height:2.5em; /* that centers the text if it is only one line long. For multi-lined text that method is not reasonable. I took arbitrary height bigger than font-size */
background: url(img-main.jpg);
}
.table-header:after {
content: '';
position: absolute;
top:0; right: 0; bottom: 0; left:0;
background: url(img-additional.jpg);
background-repeat: no-repeat;
background-position: center right;
}
Hope that helps
The markup on that website is
<div class="h2wrap">
<div class="h2left">
<div class="h2right">
<div class="h2center">
</div>
</div>
</div>
</div>
so its a div within a div
You can use this css for multiple background images
#bg_table {
background: url(http://z4.ifrm.com/30294/164/0/p1083155/h2left.png), url(http://z4.ifrm.com/30294/164/0/p1083156/h2right.png);
background-position: left center, right center;
background-repeat: no-repeat;
}
Source: http://www.css3.info/preview/multiple-backgrounds/

CSS z-index mystery

I have some problems with CSS and z-index. Let me show you an example
Suppose that on a first moment it only appears the tag pointers. Then, when I click one of this pointers appears a tag globe. I want that the tag pointers appears always under the tag globes, and I want too that every time I open a tag globe it appears over all other tag globes opened.
My div structure is:
<div id="t01" class="tag">
<div class="small">
<div class="globe">
<div class="in-globe">
<!--tag globe content-->
</div>
</div>
<div class="globe-arrow"></div>
</div>
</div>
And the related CSS code is this:
.tag {
z-index: 3;
position: absolute;
left: 0; /*JavaScript modified*/
top: 0; /*JavaScript modified*/
width: 19px;
height: 26px;
padding: 0 11px 10px 15px;
background: url('../../images/zoom/tag.png') no-repeat center;
}
.small {
cursor: pointer;
width: 19px;
height: 26px;
}
.globe-arrow {
position: absolute;
left: 23px;
bottom: 30px;
width: 8px;
height: 6px;
background: url(../../images/zoom/tag_arrow_UR.gif) no-repeat;
z-index: 5;
}
.globe {
position: absolute;
left: 23px;
bottom: 30px;
z-index: 4;
}
.in-globe {
font-size: 11px;
margin: 0 0 3px 3px;
padding: 3px;
background: #FFF;
border: 1px solid #000;
}
The 'tag' is all the conglomerate, and its background is the tag pointer image. However, this image has some shadows and I only want that a certain zone can be clicked. Then, the 'small' div has this function. The 'globe' and 'in-globe' divs are where the content of the globe is written (it could be an only div, there are two for historical reasons), and the 'globe-arrow' div is basically a little image to show this small arrow over the globe.
With this structure it doesn't work. In a same conglomerate, a globe is always over a tag, but an entire conglomerate defined before in the html code appears entirely under a newer one. In the same way, although a globe is inserted by JavaScript always after an older one (logically) the tag conglomerate is inserted when the page is loaded and then the overlapping works like I said.
Can you propose an smart way to reach my objective? Think that I'm interested on positioning the globe respective to the tag, because when I drag a pointer with a globe opened I want that the globe moves with it by CSS, not by JavaScript.
give .globe-arrow a z-index of 3
I solved the problem. There's no magic way to do it. I had to change the way I structure tags. It seems that z-index inherits from the container div, then like the parent has less z-index, a son of another parent with the same z-index appears under the first although this son has a bigger z-index. It's very confusing, yes.
In few words, I define a tag-container (to positionate the tag), into it I define a pointer and a tag globe. The first with less z-index than the second. Now, as all the divs with z-index has the same level all tag globes appear over all tag pointers.
I want that every time I open a new tag globe it appears over the opened globes. Against my desires, I had to use JavaScript for this because with a same z-index the browser show over the last defined div. This is ugly. I build a stack of z-index's that increases with more globes and decreases when I close them. Then I simply edit the css dinamicaly to put this new z-index to the new globe.
Thank you for your attention and help :) I hope this could be useful for somebody.

Doesn’t the following design just complicate the logical structure?

I’m reading some Html code for a web page, where author essentially wanted to create a page with header, footer and content area. The content area would be divided into three columns with center column having the right and left margins set to 200px, and these two margins are to be filled by two other DIVs docked on the page border with absolute positioning.
Here is author’s code for content area ( for the sake of clarity I’ve omitted the header and footer code ):
<div id="container">
<div id="container2">
<div id="centercol">
</div>
<div id="rightcol">
</div>
</div>
<div id="leftcol">
</div>
</div>
CSS file:
body
{
margin: 0px;
font-family: Verdana, Arial, Serif;
font-size: 12px;
}
#container
{
background-color: #818689;
}
#container2
{
background-color: #bcbfc0;
margin-right: 200px;
}
#leftcol
{
position: absolute;
top: 184px;
left: 0px;
width: 200px;
background-color: #bcbfc0;
font-size: 10px;
}
#centercol
{
position: relative;
margin-left: 200px;
padding: 0px;
background-color: white;
}
#rightcol
{
position: absolute;
top: 184px;
right: 0px;
width: 198px;
color: White;
background-color: #818689;
font-size: 10px;
}
Any idea why author decided to put both the center column and the right column inside container2? I see no advantages in doing that and in fact it just complicates the logical structure of the page?!
thanx
It looks like this was so he could have position effectively determined by the width and position of the centercol while allowing for a particular source order for the content. There are a few different ways to do this. Id guess he did it this way to avoid using floats (and the various "fixes" for IE6 compat that entails).
Not the way i would have done it i dont think but i assume it worked well for this site in the grand scheme of things.
Overall though sometimes you have to do some interesting things to match a comp with markup/css. Depending on what the designer has thrown at you and the level of abstraction needed within the system (assuming its built on some sort of dynamic content) you can end up doing something that cant possibly be construed as straight-forward. Nature of the beast until CSS and the browser implementations of it catch up to graphic designers :-)
Usually people adjust their markup due to having their layout and design in mind. That's probably what the author in that article was doing when he put those two sections together. It's not what I would have done, but at the same time you don't want to get yourself worked up about semantic debates on the internet :)
I would rather see someone author web-pages for the content and then design them in CSS (How To: Pure CSS Design)
If the author wants for search-engine purposes the main content to come first then that would be a reason. I'm not sure why he'd use absolutes though as you can't clear them and that would cause problems for a footer.