center align rotated text in a triangle - css

I have this following JSfiddle.
This is the HTML markup.
<div id="container">
<img id="rotate" height="80" width="80" src="http://i.imgur.com/dEM0KGG.png" />
<span id="text">Download</span>
</div>
Here is the CSS too.
#container {
position:absolute;
height:80px;
width:80px;
left:0px;
top:0px;
overflow:hidden;
z-index:2147483647;
}
#rotate {
position:absolute;
height:113px;
width:113px;
-webkit-transform:rotate(-45deg);
-webkit-transform-origin:100% 0%;
-moz-transform:rotate(-45deg);
-moz-transform-origin:100% 0%;
-ms-transform:rotate(-45deg);
-ms-transform-origin:100% 0%;
-o-transform:rotate(-45deg);
-o-transform-origin:100% 0%;
transform:rotate(-45deg);
transform-origin:100% 0%;
background:#3868D9;
right:0px;
z-index:9001;
}
#text {
position:absolute;
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
-o-transform:rotate(-45deg);
-ms-transform:rotate(-45deg);
transform:rotate(-45deg);
z-index:9001;
top:35px;
right:0px;
}
I want to place a text like how I have shown. The problem I am facing with is that the text can change dynamically and if I use the same position it doesn't display properly.
Is there any way I can position it dynamically based on the width of the text/container?
Also the width of the container can change. Right now its 80 x 80 but can be 50 x 50. How can I position it?

Try rotating the entire #container element, instead of the image and the text separately.

you can't resize the font dynamically, what you can do is to use a little js to solve your problem!
<script type="text/javascript">
setInterval(function(){
var cont=document.getElementById("container").style;
if(cont.width!="80px"){
document.getElementById("text").style.fontSize="9px";
document.getElementById("text").style.top="50%";
}
else{
document.getElementById("text").style.fontSize="16px";}
},1);
just add this code to the head tag

Related

CSS Position images in specific locations inside a background

I have a background (used style="background-image:url('')) and 2 images.
I need the images to be positioned this way:
First image:
30px from top of the background
15px from the right
Second image
15px from the bottom of the background
15px from the left
my CSS classse:
myItem1 - first image class
myItem2 - second image class
BgGrass - the background
What i've been trying:
.BgGrass {
background-image:url('images/bg/grass.png');
width:800px;
height:480px;
}
.myItem1 {
position:absolute;
bottom: 15px;
left:15px;
}
.myItem2 {
position:absolute;
top:40px;
right:20px;
}
What's wrong?
Update: The solution here provided that I need to add the position:absolute to my background. The problem now is that all the content below this background is moving up inside it and making a total mess.
<div class='BgGrass'>
<img class='myItem1' src='http://cdn.mysitemyway.com/icons-watermarks/simple-black/raphael/raphael_gear-small/raphael_gear-small_simple-black_128x128.png' />
<img class='myItem2' src='http://iconizer.net/files/Brightmix/orig/monotone_close_exit_delete_small.png' />
</div>
<div class="clearfix"></div>
All content here is inside the background
It would have been easier if we could see the original page you're working on (html specifically)
Anyway, assuming this is your html:
<div class='BgGrass'>
<img class='myItem1' src='http://cdn.mysitemyway.com/icons-watermarks/simple-black/raphael/raphael_gear-small/raphael_gear-small_simple-black_128x128.png' />
<img class='myItem2' src='http://iconizer.net/files/Brightmix/orig/monotone_close_exit_delete_small.png' />
</div>
Then the CSS should be:
.BgGrass {
background-image:url('http://www.planwallpaper.com/static/images/744081-background-wallpaper.jpg');
width:800px;
height:480px;
position:relative;
}
.myItem1 {
position:absolute;
top: 30px;
right:15px;
width: 100px;
}
.myItem2 {
position:absolute;
bottom:15px;
left:15px;
width: 100px;
}
CSSfiddle: https://jsfiddle.net/5ndbzg6h/
Issue: you need to add position relative to your parent div.
From definition here
position:absolute The element is positioned relative to its first positioned (not static) ancestor element
By default, BgGrass is static, so you must give him an other position like relative.
.BgGrass {
background-color:red;
position:relative
width:800px;
height:480px;
}
.myItem1 {
position:absolute;
bottom: 15px;
left:15px;
}
.myItem2 {
position:absolute;
top:40px;
right:20px;
}
<div class="BgGrass">
<div class="myItem1">ABC</div>
<div class="myItem2">DEF</div>
</div>

Hide one image and display another on hover

I have 2 images placed one on top of another, and what I'm trying to do is to change the opacity based on hover on parent.
Meaning that by default hovethumb's opacity is set to 0. But when I hover on index then hoverthumb's opacity should be changed to 1 and bdata's opacity should be changed to 0.5
But the styling doesn't work... The stylings I use are div.productindex:hover > div.hoverthumb & div.productindex:hover > div.bdata
Can someone help me figure out to target them correctly?
My php code :
<div class="index ">
<div class="bdata">
<div class="thumb"><?php the_post_thumbnail('')?></div>
</div>
<div class="hoverthumb clearfix"><img src="<?php echo get_template_directory_uri(); ?>/images/buy.png" width="50px" ;></div>
</div>
also how to align the image exactly in the centre of the box index
.index{
float: left;
height: auto;
padding-bottom:10px;
margin-bottom:20px;
}
.hoverthumb{
position:absolute;
opacity:0;
clear:both;
}
div.index:hover > div.bdata{
opacity:0.5;
border: thin outset #EC008C;
}
div.index:hover > div.hoverthumb{
opacity:1;
}
.thumb{
width:100%;
}
.thumb img{
width:100%;
height: auto;
}

CSS render image top of the background color

I've to follow below HTML structure.
<a class="abc" style: {background:"blue"}">
<img src="ImgPath" />
</a>
CSS
.abc{
width: 177px;
height: 177px;
display:inline-block;
}
abc img {
display:block;
z-index:9999;
width:50px;
height:50px
}
I want to display transparent image on top of the background color. I shouldn't use background-image/background: #c1c1c1 url('img.png') no-repeat; css property. I don't want use image as background-image. Image is hiding of background color.
Any help?
The image is probably not showing because you have unclosed quotes:
<a class="abc" style: {background:"blue"}">
You should have:
<a class="abc" style="background:blue">
Better to use CSS
.abc {
background: url("ImgPath") 0 0 no-repeat blue;
}
You can give an elment a background color and set a background image like this:
CSS
.abc{
background: #c1c1c1 url('path/img.jpg') no-repeat;
}
HTML
<a class="abc"></a>
This way the color is not hided.
Are you looking something this kind of effect?
Not sure you are looking this kind of stuff. check Demo link. http://jsbin.com/wibaxuyu/1/
a.abc{
width:200px;
height:200px;
background:rgba(145 ,145 ,89 ,00.5);
display:inline-block;
position:relative;
}
a img{
position:absolute;
top:20%;
left:20%;
z-index:9999;
width:100px;
height:100px;
opacity: 0.8;
filter: alpha(opacity=80); /* IE 5-7 */
-moz-opacity: 0.8;
}
<a class="abc">
<img src="http://lorempixel.com/100/100" />
</a>

Css: Elements with position: relative; wisible trough other elements positioned on top

I have an unordered html list on:
<ul id="maintab" class="shadetabs">
<li class="selected">selected</li>
<li>not selected</li></div>
I need to use position: relative for "selected" items:
.shadetabs li.selected{
position: relative;
top: 1px;
............
}
Everything is OK so far. But now I want to show a div over all other content of website.
<div id="vertical">
<div id="hoz">
content
</div></div>
#vertical{
position:absolute;
top:50%;
margin-top:-198px;
left:0;
width:100%;
}
#hoz{
width:320px;
margin-left:auto;
margin-right:auto;
height:90px;
border:10px solid #BF0000;
background:#f5f5f5;
text-align:center;padding:10px;
}
Unfortunately, this .shadetabs li.selected is visible trough divs "vertical" and "horizontal". I tried to add style="opacity: 1 !important;" to the "vertical" div but it doesn't help.
Give the element a z-index: 2. That way it will be drawn on top of other positioned content.

CSS - Change sub class background image on hover

I have the following code for a selectable tab:
<div class="tabOff">
<div class="lightCorner TL"></div><div class="lightCorner TR"></div>
<div class="cornerBoxInner">
<p>My Tab</p>
</div>
</div>
On the mouse over of tabOff I have the following CSS for changing the background colour:
.tabOff:hover
{
background:#AAA;
color:#CDEB8B;
}
Is there any way I can change my classes "lightCorner TL" and "lightCorner TR" to use a different background image, without JavaScript, when tabOff is hovered
This is the current CSS for lightCorner TL and TR:
.lightCorner
{
background:url(../Images/LightCorner.gif) no-repeat;
}
.TL
{
top:0px;
left:0px;
background-position:0px 0px;
}
.TR
{
top:0px;
right:0px;
background-position:-13px 0px;
}
I have never tried it, but I would start with:
.tabOff:hover .lightCorner {
}
DonĀ“t know if that's correct usage though.
.tabOff:hover div.lightCorner {
background:url(../Images/LightCorner.gif) no-repeat;
}
.tabOff:hover div.TL {
top:0px;
left:0px;
background-position:0px 0px;
}
.tabOff:hover div.TR {
top:0px;
right:0px;
background-position:-13px 0px;
}

Resources