CSS HTML Place severel centered divs in td - css

At first, when I say centered, I mean both, vertically and horizontally centered.
I have a table with several tiles (divs) like in Windows 8 with background.images.
Every tile has a centered label (also a div) with a description and a semi transparent background.
Now I'd like to add another div between the tile itself and the label. These div should have a semi-transparent background-color as an overlay of the underlying tile-image-div.
But when I add this overlay-div, my label is not centered horizontally anymore, it is placed at the top of the tile. How can I keep it centered?
This is my code on fiddle:
fiddle (please take a look)
(The problem in the fiddle code is this line:
<div class="SemiTransOverlay"> When I delete this div everything is centered correctly.
What do I have to change to keep everything centered and keep div?)

first of all why you are using tables for layout purposes? we are in 21st century, so start using div's and for accomplishing the semi transparent div to place behind the label and vertically aligned label you need to use position: absolute; and top: -50%;, I've also modified line-height for div.SemiTransLabelGross and also used position: relative and z-index properties
Demo
CSS
table.Kacheln
{
border-spacing: 5px;
border-collapse:separate;
border:0px;
}
.wrap {
position: relative;
height: 100%;
}
td.KachelFlavourGross01
{
text-align:center;
/*background:url(../img/Div/bg.jpg) no-repeat 0 0;*/
background-color:#FF0000;
width:404px;
height:200px;
}
div.SemiTransOverlay
{
height:100%;
width:100%;
background-color:rgba(255, 255, 255, 0.5);
position: absolute;
z-index: 1;
}
div.SemiTransLabelGross
{
font-size:2em;
font-family:Verdana;
font-style:italic;
line-height:60px;
background-color: rgba(255, 255, 255, 0.75);
width:404px;
height:60px;
z-index: 2;
position: absolute;
top: 50%;
margin-top: -30px; /* Half of height */
}

Aligning vertically, what I do is, set padding instead of height.
eg:
div.SemiTransLabelGross
{
font-size:2em;
font-family:Verdana;
font-style:italic;
line-height:120%;
background-color: rgba(255, 255, 255, 0.75);
width:404px;
padding: 20px 0; /* removed the height property */
}
Sorry for misunderstanding, from the above answer, I think you wanted that light pink div itself to be vertically centered. In that case, add padding to its parent.
div.SemiTransOverlay
{
width:100%;
background-color:rgba(255, 255, 255, 0.5);
padding: 20% 0;
}
OR, you can add margin to
div.SemiTransLabelGross {
margin-top: 20%;
}

Related

Non-transparent white background but keep borders on table

I have almost successfully made the left columns of my table sticky, so that the rest can be scrolled. This, however, has created a new problem: the table background is white, which means scrolled cells transpire underneath the sticky cells (see screenshot 1). To resolve this, I've made the background of the sticky cells non-transparent by using background-color: rgba(255, 255, 255, 1.0);. But this also removes the borders of the sticky cells (see screenshot 2). Both variants are ugly.
I've tried adding border:1px solid #cdcdcd; (even adding !important) to the sticky cells but the borders are still invisible. Any suggestions?
Here's the entire formatting applied to the table:
div#scrollable {
overflow-x: scroll;
}
table#stats {
border-collapse:collapse;
width:100%;
}
table#stats th.sticky, td.sticky {
position: -webkit-sticky; /* for Safari */
position: sticky;
left: 0;
}
table#stats td.sticky {
background-color: rgba(255, 255, 255, 1.0);
border:1px solid #cdcdcd !important;
}
table#stats tr#means {
background-color:#ddffd5;
}
table#stats td.stats {
border:1px solid #cdcdcd;
}
transparent sticky cells
non-transparent sticky cells
I did not find any other solution than this
th.sticky:after, td.sticky:after{
content : "";
position: absolute;
bottom: 0;
display: block;
width: 100%;
height: 1px;
background-color: #cdcdcd;
}
EDIT : Other solution here Stack overflow post

Flexible-width centered heading banner with three background images?

The site I'm working on has headings that look like this:
http://i.imgur.com/ssvj8J1.png
They need to...
a) be centered on the page
b) be flexible width, to fit the contained text with a few em of padding either side.
c) work on IE9+, and of course all the other modern browsers
d) work on any background (so the images used can't contain white bits to help with overlaying)
I started off chopping it into 3 bits, and using ::before and ::after. This had problems with the backgrounds overlapping.
I then tried a sliding-doors approach, with just 2 images, but obviously had similar problems.
Now I'm on multiple BG images, which I've not used before. Same problem as above, they overlap. The solution seems to be to "clip" the middle one to content-box, but then that limits the padding I can use to strictly 53px, the "width" of each end bit of the banner, making them look too cramped?
Also, what's the best way of centering these? They're h1 tags. Do I need to use positioning/translation/inline-block? Or can I somehow keep them as 100% width block elements (which would be easier/better) and just centralise the backgrounds?
This is what I had before I tried to make them fluid:
h1{
background:url(banner.png) 50% 0 no-repeat;
line-height:52px;
color:#fff;
padding:0 0 6px}
And this is where I'm at now:
h1{
background-image:url(banner-left.png), url(banner-mid.png), url(banner-right.png);
background-position:0%, 50%, 100%;
background-repeat:no-repeat, repeat-x, no-repeat;
background-clip:border-box, content-box, border-box;
line-height:52px;
color:#fff;
display:inline-block;
padding:0 53px 6px}
I'm not happy with this for the reasons mentioned above. I feel I'm missing some obvious/easy tricks?!
Thanks - CSS seems to have moved on a lot since I last did anything significant!
You can use a pseudo elements and avoid the images completely.
Codepen Demo
HTML
<div><h1><span>Short Text</span></h1></div>
<div><h1><span>Much Longer Text</span></h1></div>
CSS
body {
text-align: center;
}
div {
margin: 25px;
}
h1 {
position: relative;
line-height: 1em;
max-width:50%;
display: inline-block;
}
h1 span {
color:gold;
padding: .5em;
background: black;
box-shadow:
0 0 0px 1px gold,
0 0 0px 3px black;
}
h1::before, h1::after {
position: absolute;
content:"";
top:35%;
z-index:-1;
border: solid black;
border-width:25px;
}
h1::before { /* left */
border-left-color:transparent;
left:0;
transform:translateX(-75%)
}
h1::after { /* right */
border-right-color:transparent;
right:0;
transform:translateX(75%)
}

CSS image border transparency/color issue

I wanted to make a cool div, so I made this image to get its borders:
The problem is that half of the borders are transparent area, so when I try to fill the empty center of the div with background-color it also paints the outer, transparent area. I'd like the background color not to get past the border.
Here's what I'm talking about:
#charset "utf-8";
/* CSS Document */
#testDiv{
border-image-source:url(https://s9.postimg.org/40j461sf3/Div_Sprite.png);
border-image-slice: 50% 25% 25%;
border-image-repeat:repeat;
border-image-width:auto;
border-image-repeat:round;
background-color: red;
min-height:600px;
width:600px;
}
#body {
height:100%;
width: 100%;
background: #CCC;
position: absolute;
margin: 50px 0 0 0;
}
<div id="testDiv">
</div>
Or see http://jsfiddle.net/6M59T/119/.
How can I solve this? I've thought on putting a slightly smaller div inside this one, but I don't know how to adjust it so it always covers a bit less than its parent. Also, I'd like to keep it as simple as possible. Any ideas?
Maybe i am mistaken, but you can try to play with border-image-outset and margin attribute.
float:left;
margin:50px 20px;
border-image-source:url(http://s9.postimg.org/40j461sf3/Div_Sprite.png);
border-image-slice: 50% 25% 25%;
border-image-repeat:repeat;
border-image-width:auto;
border-image-repeat:round;
background-color: red;
border-image-outset:30px;
http://jsfiddle.net/6M59T/120/

CSS Only Folded Corner Div

So I have been slamming my head against the wall trying several different methods online and can't get anything to work.
I have a div that needs to be fluid width, and its height needs to be variable as well.
The div sits on top of a tile-able background image. It has a 1px border around it.
I need the bottom right of the div to fold up, like a piece of paper.
I tried using an image, in a div anchored to the bottom. But that requires a fixed width or height as far as I can tell.
I tried this method but it requires a solid background color. I have a repeating image.
I tried this method, which uses gradients to control the opacity at the corner, this almost works, but my div requires a border. Applying the border ruins the effect.
background:
linear-gradient(45deg, rgba(255,0,0,0.4), rgba(255,0,0,0.4)),
linear-gradient(135deg, rgba(255,0,0,0.4), rgba(255,0,0,0.4)),
linear-gradient(225deg, transparent 10px, rgba(255,0,0,0.4)
background-size: 14px 14px, 50% 100%, 50% 50%, 50% 50%;
background-position: 100% 0, 0 0, 100% 100%, 100% 0;
background-repeat: no-repeat;
//then an :after pseudo class to create the corner fold
Any help would be greatly appreciated. Thanks.
This question got me bussy for some time, this seems to be a really hard thing to do with CSS only. I managed to achieve the effect(the paper flip with a border around the element) you wanted, but it requires alot of CSS and I don't know how far you want to go. I applied border-radius to the top right corner and used a triangle to overlap the border-radius. This did not cover the entire border radius, so I used a span to form 2 shapes to overlay the remaining gap.
Look at this fiddle for the result, any improvements are welcome
http://jsfiddle.net/EnVnW/
CODE:
body {
background: #444 url('http://leaverou.me/ft2010/img/darker_wood.jpg') bottom;
}
.arrow_box {
color:red;
position: relative;
background: #88b7d5;
border: 4px solid #c2e1f5;
height:400px;
border-radius:0 300px 0 0; /* here we give the box a round corner on the top right side */
}
.arrow_box:after, .arrow_box:before { /* we create 2 triangles in the top right corner, one for the border and one for the filling */
-ms-transform:rotate(-135deg); /* rotate to make the triangle have the right angle */
-webkit-transform:rotate(-135deg);
transform:rotate(-135deg);
bottom: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
top:42px;
right:-20px;
}
/* here we position the triangles in the top right corner */
.arrow_box:after {
border-color: rgba(200, 265, 0, 0);
border-bottom-color: #00b7d5;
border-width: 100px;
left: 100%;
margin-left: -240px;
}
.arrow_box:before {
border-color: rgba(194, 225, 245, 0);
border-bottom-color: #c2e1f5;
border-width: 105px;
left: 100%;
top:39px;
margin-left: -245px;
}
/* we still have a massive gap next to the triangle, so we fill it up with 2 rectangles. One on the left side of the triangle and one on the bottom side of the triangle, we also will give them a border to finish the line around the element */
.arrow_box span {
border-top: 4px solid #c2e1f5;
position:absolute;
width:150px;
height:140px;
background-color:black;
right:140px;
top:-4px;
background: #88b7d5;
}
.arrow_box span:after {
border-right: 4px solid #c2e1f5;
content: "";
position:absolute;
width:150px;
height:150px;
background: #88b7d5;
left:140px;
top:140px;
}
With CSS4 this will be alot easier to do, here you can read about it;
http://dev.w3.org/csswg/css-backgrounds-4/#border-corner-shape

Vertically centering menu items between menu separator images

This is what I'm trying to achieve, and have come pretty close:
This is my CSS:
li {
float: left;
position: relative;
padding-left: 55px;
background: url(../../images/separator.png);
background-repeat: no-repeat;
background-position: left bottom;
height: 87px;
}
a {
font-size: 15px;
line-height: 67px;
}
I'm almost there, but there are a few problems. The only way I came up with to have the menu items vertically in the middle of the separators was to use line-height. But now of course when hovering over the links the hover is the height of the line-height, and I don't want that.
Also: is there a way to have the menu items go "inside" the separator images, like in the picture? The separator image is a transparent png. If not I'll just decrease the padding on the menu items to try and get them closer.
First method:
Give the link a height, position it 50% from the top, half the height back to top:
a {
font-size: 15px;
height:30px;
display:block;
position:relative;
top:50%;
margin-top:-15px;
}
Demo
http://jsbin.com/ovaqix/1/edit
Second Solution
Make the a element display:table-cell and same height as li, then use vertical-align:
a {
display:table-cell;
height:87px;
vertical-align:middle;
}
Demo
http://jsbin.com/ovaqix/2/edit
Table-cell doesnt work in IE7
Have you tried changing stating a height in a:hover ?
To have the menu items go inside the separators, I think that you need to create after and before pseudo elements, with the border hack to generate triangular shapes. Something in he line of:
a:before {
border-top: 38px solid transparent;
border-bottom: 60px solid transparent;
border-right: 60px solid black;
}
If you provide more details, I can be more specific.

Resources