CSS border-radius parent child issue (with :hover & position:absolute) - hover

There is known problem with border radius and child elements. Child elements protrude from rounded corners of parent.
Common solution is to add overflow:hidden to parent element. But it still doesn't work when parent have position:absolute.
http://jsfiddle.net/Xhrx8/2/

HTML
<div id="items">
<div id="top">One</div>
<div>Two</div>
<div>Three</div>
<div id="bottom">Four</div>
CSS
#items {
border: 1px solid black;
border-radius: 10px;
overflow: hidden;
position: absolute;
}
#items div {
border-bottom: 1px solid black;
padding: 5px;
}
#items #top:hover {
border-top-right-radius: 10px;
border-top-left-radius: 10px;
background-color: #ccc;
}
#items div:hover{
background-color: #ccc;
}
#items #bottom:hover {
background-color: #ccc;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
Live Example http://jsfiddle.net/Xhrx8/3/

It seems that is a bug with chrome css.
A workaroud that we can do is use a wrapper as
<div style="position:absolute">
<div id="items">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
</div>
<div>
and remove position:absolute from #items
FIDDLE

This is a known bug in Chrome (Works fine in Firefox).
You'll need a wrapper around your DIV #items and assign properties to that wrapper.

I like user1136403's answer, but I'd use the first and last-child css selectors. That way you don't have to add the id="top", id="bottom" to the first and last li's in the HTML.
HTML
<div id="items">
<div >One</div>
<div>Two</div>
<div>Three</div>
<div >Four</div>
</div>
CSS
#items {
border: 1px solid black;
border-radius: 10px;
overflow: hidden;
position: absolute;
}
#items div {
border-bottom: 1px solid black;
padding: 5px;
}
#items div {
border-bottom:none; //removes the double border on the bottom
}
#items div:hover{
background-color: #ccc; //this is the only background color def you need
}
#items div:first-child:hover {
border-top-right-radius: 10px;
border-top-left-radius: 10px;
}
#items div:last-child:hover {
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
Also note you don't need 'background-color' in the first, last-child css blocks. It is already defined in #items div:hover{}. Here is the fiddle.
http://jsfiddle.net/honkskillet/CHL8K/

You need to force the hardware acceleration through css3.
#items {
[......]
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}

Related

Is there a way to prevent the box-shadow cumulative effect from overlapping elements?

If 2 elements overlap and both have the same box-shadow applied, the shadow is cumulative at the point where the elements intersect. Is there a way to make the shadow look the same even if elements overlap?
The example below shows what I mean. I've tried the various options with mix-blend-mode to no avail.
.div1,.div2 {
width: 50px;
height: 50px;
box-shadow: 1px 1px 5px 1px gray;
position: absolute;
background-color: white;
}
.div2 {
top: 25px;
background-color: green;
}
<div class="div1"></div>
<div class="div2"></div>
Use a drop-shadow on a parent element. I am using the body here but you have to consider another element based on your real code
.div1,.div2 {
width: 50px;
height: 50px;
position: absolute;
background-color: white;
}
.div2 {
top: 25px;
background-color: green;
}
body {
filter:drop-shadow(1px 1px 5px gray)
}
<div class="div1"></div>
<div class="div2"></div>

What is the difference between margin-block-start and margin-top?

Trying to understand the core difference in usage between the two, but I fail to find an article or doc that details such a comparison. Taking the example provided here, assuming the following:
div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
margin-block-start: 20px;
background-color: #c8c800;
}
<div>
<p class="exampleText">Example text</p>
</div>
The difference between this instance, and one in which margin-top is used, is quite small (however visible).
The specifications state that margin-block-start depends on layout model while margin-top refer to the width of the containing block. Would love it if someone could explain it in layman's term.
From the official1 specification you can read:
These properties correspond to the margin-top, margin-bottom, margin-left, and margin-right properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
By default, you will have the following mapping:
margin-block-start = margin-top
margin-block-end = margin-bottom
margin-inline-start = margin-left
margin-inline-end = margin-right
Example:
.margin {
margin-top:50px;
margin-bottom:10px;
margin-left:100px;
margin-right:200px;
}
.margin-alt {
margin-block-start:50px;
margin-block-end:10px;
margin-inline-start:100px;
margin-inline-end:200px;
}
div {
border:2px solid;
padding:20px;
}
<div class="margin">
A
</div>
<hr>
<div class="margin-alt">
A
</div>
Now if we change the writing mode, you will see that we will have a different mapping.
.margin {
margin-top:50px;
margin-bottom:10px;
margin-left:100px;
margin-right:200px;
}
.margin-alt {
margin-block-start:50px;
margin-block-end:10px;
margin-inline-start:100px;
margin-inline-end:200px;
}
div {
border:2px solid;
padding:20px;
writing-mode: vertical-lr;
}
<div class="margin">
A
</div>
<hr>
<div class="margin-alt">
A
</div>
<div class="margin-alt" style="writing-mode: vertical-rl;">
A
</div>
In the above, you will notice when using vertical-lr a mapping equal to
margin-block-start = margin-left
margin-block-end = margin-right
margin-inline-start = margin-top
margin-inline-end = margin-bottom
and when using vertical-rl
margin-block-start = margin-right
margin-block-end = margin-left
margin-inline-start = margin-top
margin-inline-end = margin-bottom
I will not detail all the cases, but basically each margin-*-* property will be mapped to a margin-* property based on the values of writing-mode, direction, and text-orientation.
You can play with the different values to see the different cases.
Your examples are a bit complex because you are having margin-collapsing and the default margin applied to p so it's difficult to understand.
Here is a better one:
div:not([class]) {
background-color: yellow;
width: 120px;
height: 120px;
border:1px solid;
}
.exampleText {
writing-mode: vertical-lr;
margin-block-start: 20px; /* we will end with a margin-left */
background-color: #c8c800;
}
.exampleText2 {
writing-mode: vertical-lr;
margin-top: 20px; /* this will remain a margin-top */
background-color: #c8c800;
}
<div>
<div class="exampleText">Example text</div>
</div>
<div>
<div class="exampleText2">Example text</div>
</div>
1: the link you are using is the MDN page which is a good reference but not the official specification.
The margin-block-start CSS property defines the logical block start
margin of an element, which maps to a physical margin depending on the
element's writing mode, directionality, and text orientation.
Please run the snippet to see the behavior in action:
document.addEventListener('DOMContentLoaded', event => {
const choice = document.querySelectorAll('.choice');
const target = document.querySelectorAll('.row-target')[0];
choice.forEach(el => el.addEventListener('click', event => {
choice.forEach(el => el.classList.remove('selected'));
event.target.classList.add('selected');
target.setAttribute('style', event.target.innerText);
}));
})
* {
box-sizing: border-box;
}
#container {
width: 300px;
height: 200px;
display: flex;
align-content: flex-start;
flex-direction: column;
justify-content: flex-start;
margin-left: 20px;
}
.row {
height: 33.33%;
display: inline-block;
border: solid #5b6dcd 10px;
background-color: rgba(229,232,252,.6);
flex-shrink: 0;
}
.row-target {
border: solid 10px #ffc129;
background-color: rgba(255,244,219,.6);
}
.transition-all {
transition: all .3s ease-in;
}
.choice {
background-color: #fff;
display: flex;
align-items: center;
flex-grow: 1;
position: relative;
z-index: 1;
display: block;
margin: .2em 0;
width: 100%;
border: 2px solid #d6dee0;
border-left: 5px solid #d6dee0;
font-size: 14px;
cursor: pointer;
transition: background-color .2s ease-out,border .2s ease-out;
}
.choice.selected:before {
opacity: 1;
right: -1.5em;
}
.choice:before {
content: '';
position: absolute;
top: 50%;
right: -10px;
z-index: 1;
opacity: 0;
transition: all .2s ease-out;
transform: translateY(-50%);
border-left: 10px solid #1b76c4;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
}
.selected {
border-color: #1b76c4;
border-left-color: #1b76c4;
box-shadow: inset 0 2px 2px -2px rgb(0 0 0 / 20%);
transition: height .5s;
cursor: text;
}
<table>
<tr>
<td>
<div class="choice selected">
margin-block-start: 20px; <br>
writing-mode: horizontal-tb;
</div>
<div class="choice">
margin-block-start: 20px; <br>
writing-mode: vertical-rl;
</div>
<div class="choice">
margin-block-start: 20%; <br>
writing-mode: horizontal-tb;
</div>
<div class="choice">
margin-block-start: auto; <br>
writing-mode: vertical-lr;
</div>
</td>
<td valign="top">
<div id="container">
<div class="row">One</div>
<div class="row row-target transition-all" id="example-element" style="margin-block-start: 20px; writing-mode: horizontal-tb;">Two</div>
<div class="row">Three</div>
</div>
</td></tr>
</table>

how to extend background color when i hover

I'm working with bootstrap panel. PSD suggest that when I hover over a panel background color and content color will change. that's fine I can do that.
but how to extend hover-color in top and bottom? and content position should stay there!
<div class="row">
<div class="col-md-4">
<div class="panel">
</div>
</div>
</div>
.panel:hover{
background-color: #13BDFF;
}
Update
Just use outline CSS property which has excellent browser support (IE8+). Demo:
.panel:hover {
background-color: #13BDFF;
outline: 5px solid #13BDFF;
}
/* just styles for demo */
.panel {
padding: 10px;
background-color: lime;
}
<div class="panel">
This is panel
</div>
Original answer (not recommended way)
You can use transparent borders (also padding can help you with this) and negative margin for this:
.panel:hover {
background-color: #13BDFF;
border: 5px solid transparent;
margin-left: -5px;
margin-top: -5px;
}
/* just styles for demo */
.panel {
padding: 10px;
background-color: lime;
}
<div class="panel">
This is panel
</div>
https://jsfiddle.net/xkqvv92p/
Here's a version using padding on hover.
.rowArea {
height: 400px;
background-color: red;
display: flex;
align-items: center;
}
#container {
margin: auto;
width: 200px;
height: 300px;
background-color: white;
border-radius: 5px;
padding: 5px;
}
#container:hover {
padding: 30px 5px;
background-color: #13C3FF;
}
<div class="rowArea">
<div id="container">hi</div>
<div id="container">hi2</div>
</div>
Changing the border color and size might solve the issue.
please refer the sample fiddle :
.panel:hover{
background-color: #13BDFF;
border-color : #13BDFF;
border:10px solid #13BDFF;
}
https://jsfiddle.net/3wkjuzbk/1/

How to create diagonal boxes using css?

I want to create diagonal box inside box. How can I do this using css.
I am attaching an image, exactly what i want. If any one have any idea please share with me.
My Fiddle: http://jsfiddle.net/Ae8Wv/660/
My codes are here:
HTML:
<div class="foo bg1"></div>
<div class="foo bg2"></div>
CSS:
.foo {
float: left;
width: 40px;
height: 40px;
margin: 5px 5px 5px 5px;
border-width: 1px;
border-style: solid;
border-color: rgba(0,0,0,.2);
}
.bg1 {
background-color:#13b4ff;
}
.bg2 {
background-color:#ab3fdd;
}
My Fiddle: http://jsfiddle.net/Ae8Wv/660/
Making divs absolute may disturb other elements. You can also move the second div inside first div and apply margin on second div like shown in this fiddle : http://jsfiddle.net/6k9Ltyoa/
<div class="foo bg1">
<div class="foo bg2"></div>
</div>
.foo {
float: left;
width: 40px;
height: 40px;
border-width: 1px;
border-style: solid;
border-color: rgba(0,0,0,.2);
}
.bg1 {
background-color:#13b4ff;
}
.bg2 {
background-color:#ab3fdd;
margin-top:50%;
margin-left:50%;
}
http://jsfiddle.net/Ae8Wv/661/
you can position the second div and assign top,left.
.bg2 {
background-color:#ab3fdd;
position: absolute;
top: 10px;
left: 10px;
}
You just need to add some absolute position to the second box. I'd recommend wrapping it all up to make it responsive too with the container having relative positioning. Use the left/top % values to move the box, greater increase will move them further respectively.
http://jsfiddle.net/Ae8Wv/662/
.bg2 {
background-color:#ab3fdd;
position:absolute;
left:2%;
top:2%;
}
I added the wrapper for you here too. Up to you whether or not you want it :)
http://jsfiddle.net/Ae8Wv/665/
Just add some margin to the purple box like this
http://jsfiddle.net/8odoros/Ae8Wv/667/
.bg2 {
background-color:#ab3fdd;
margin-left:-30px;
margin-top:20px;
}
how about translations?
.bg2{transform: translate(-40px, 20px)}
fiddle
Give the .bg2 div a position: absolute;. And don't forget to put a position: relative; on .bg1, or else the absolute positioning won't work.
HTML
<div class="foo bg1">
<div class="foo bg2"></div>
</div>
CSS
.foo {
position: relative;
float: left;
width: 40px;
height: 40px;
margin: 5px 5px 5px 5px;
border-width: 1px;
border-style: solid;
border-color: rgba(0,0,0,.2);
}
.bg1 {
background-color:#13b4ff;
}
.bg2 {
position: absolute;
top: 50%;
left: 50%;
background-color:#ab3fdd;
}
http://jsfiddle.net/skeurentjes/Ae8Wv/671/

Border radius property breaks on table footer

I'm trying to make a table with rounded corners with both a header and a footer with different colors than the main table. Ideally, the header and footer would both inherit from the parent table, but being able to separately round the footer/header would be fine for my purposes.
The current issue is highlighted here: http://jsfiddle.net/VfVx9/
tfoot{
background: #ff0000;
border-radius: 20px;
}
In my mind directly giving the footer a border radius should round the corners, but that doesn't quite seem to be working. Any ideas?
Why don't you just do this:
<div id="table">
<div class="head">
Table head
</div>
<div class="tablerow">
Table row content
</div>
<div class="tablerow">
Table row content
</div>
<div class="footer">
Table footer
</div>
and then:
#table {
background-color: blue;
width:200px;
border-radius: 10px;
}
#table div {
padding: 5px;
}
#table .head {
background-color: green;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
#table .footer {
background-color: red;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
Here's a fiddle: http://jsfiddle.net/VfVx9/
http://jsfiddle.net/JLyrp/
.test {
background: #0000ff;
border-radius: 10px;
width: 100px;
}
tfoot {
background: #ff0000;
border-radius:20px;
display:block //float or position:absolute also works
}
I believe this depends on which browser you are using, try this:
tfoot{
background: #ff0000;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
}