Simulate borders with CSS - css

When I add td element with a dark background in my table that has a light background with a border, I want that in the dark td element, the border of the table doesn't see.
For example:
table {
border: 1px solid yellow;
width: 40%;
border-spacing: 0;
}
td {
padding: 10px;
}
td.black {
background: #000;
color: #fff;
}
<table>
<tr>
<td class="black">Something</td>
</tr>
<tr>
<td>Something else</td>
</tr>
</table>
In the first td, the dark td, I don't want to see the yellow border of the table.

You can't, but you could just add the border to the default 'td' element insted of 'table' and create a special rule for the black one.
table {
width: 40%;
border-spacing: 0;
/* border-collapse: collapse; // get a single border */
}
td {
padding: 10px;
border: 2px solid yellow;
}
td.black {
background: #000;
color: #fff;
border: 2px solid green;
}
http://jsfiddle.net/pr1d3c5b/
If you want to add just a box-shadow, you can try with this variation (for red color), but it's not precise
-webkit-box-shadow: 0px 0px 0px 2px rgba(255, 0, 0, 1);
-moz-box-shadow: 0px 0px 0px 2px rgba(255, 0, 0, 1);
box-shadow: 0px 0px 0px 2px rgba(255, 0, 0, 1);
http://jsfiddle.net/pr1d3c5b/1/
You can try this generator http://css3gen.com/box-shadow/ and play with the 'spread' value under the optional settings

Related

how can I get this kind of box shadow or outline?

Is this a box shadow or an outline? I'm confused because outlines can't have radius property and box shadows have blur effect.
That can be a combination of border and box-shadow and outline: none.
I have added the border and box-shadow to default state, if needed we can move that to :focus
body {
padding: 10px;
zoom: 250%;
}
.custom {
width: 100%;
height: 30px;
border-radius: 5px;
border: 2px solid #0000ff;
box-shadow: 0 0 0 2pt rgb(0 0 255 / 30%);
}
.custom:focus {
outline: none;
}
<input type="text" class="custom">
Use an outline with a rgba color on an input with a border radius:
input {
border: 1px solid #ae11fc;
border-radius: 0.5rem;
font-size: 1rem;
height: 2rem;
}
input:focus {
outline: #ae11fc44 solid 0.2rem;
}
Checkout out this fiddle
You can achieve the required styling by adding the following properties to your input style. You can play around it here: https://codepen.io/taleyamirza/pen/ExmzYJr
input:focus {
outline-color: #6c8afc;
border-color: #9ecaed;
box-shadow:0 0 10px #6c8afc;
-moz-box-shadow: 0px 0px 4px #6c8afc;
-webkit-box-shadow: 0px 0px 4px #6c8afc;
}

How to overlap box-shadows on table rows?

I have a table on which I want to highlight a number of successive rows (TR's) by applying a box-shadow around them.
My strategy was to apply a class called "selected-top" to the first row of the selection, classes "selected-middle" for the middle part, and "selected-bottom" for the last row.
However, the shadows of the middle rows bleed over. I tried to rectify this by using z-index (I know that I have to add a relative property with that, so I did), but they seem to have no effect:
Here's the code:
tr.selected-top {
box-shadow: -5px -5px 5px #000, 5px -5px 5px #000;
position: relative;
z-index:10;
}
tr.selected-middle {
box-shadow: -5px 0px 5px #000, 5px 0px 5px #000;
position: relative;
z-index: -1;
}
The table is just a regular table:
<table>
<tr><td>stuff</td></tr>
<tr class="selected-top"><td>highlighting starts</td></tr>
<tr class="selected-middle"><td>highlighting middle</td></tr>
<tr class="selected-bottom"><td>highlighting end</td></tr>
<tr><td>other stuff</td></tr>
</table>
What am I doing wrong?
By the way, I did try to only apply a shadow to only the sides for the middle rows, but that way the shadow is not continuous.
Update: #Aditya Toke, like so: (left is wrong shading, right is correct shading)
You can achieve it using ::before and ::after pseudo elements to mask the top and bottom shadow from "middle" row.
The height of the pseudo elements is set exactly equal to the length of the shadow for masking and is absolute position.
Since the shadow hides the top borders of selected-bottom and it's next sibling element we need to add them back as:
tr.selected-middle td,
tr.selected-bottom td {
border-bottom: 1px solid #666;
}
body {
background-color: #1b1b1b;
margin: 20px;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: auto;
box-sizing: border-box;
border: none;
margin: auto;
}
tr { display: block; }
tr, td {
height: 50px;
background: #333;
color: #eee;
}
td {
padding-left: 16px;
min-width: 170px;
width: 100%;
border-top: 1px solid #666;
}
tr.selected-top {
position: relative;
box-shadow: -5px -5px 5px #000, 5px -5px 5px #000;
}
tr.selected-middle {
position: relative;
box-shadow: 0px 0px 5px 5px #000;
}
tr.selected-bottom {
position: relative;
box-shadow: 5px 5px 5px #000, -5px 5px 5px #000;
}
tr.selected-middle ::before,
tr.selected-middle ::after {
pointer-events: none;
position: absolute;
content:" ";
background-color: #333;
left: 0;
width: 100%;
}
tr.selected-middle ::before {
height: 10px;
top: -10px;
}
tr.selected-middle ::after {
top: calc(100% + 4px);
height: 5px;
}
tr.selected-middle td,
tr.selected-bottom td {
border-bottom: 1px solid #666;
}
<table>
<tbody>
<tr>
<td>Some stuffs</td>
</tr>
<tr class="selected-top">
<td>highlighting starts</td>
</tr>
<tr class="selected-middle">
<td>highlighting middle</td>
</tr>
<tr class="selected-bottom">
<td>highlighting ends</td>
</tr>
<tr>
<td>Some stuffs</td>
</tr>
</tbody>
</table>
table {
height: 67vh;
width: 59vw;
background-color: #333333;
}
td {
/* background-color: #333333; */
color: white;
}
div {
display: flex;
justify-content: center;
align-items: center;
}
.div1 {
box-shadow: -5px -5px 5px #000, 5px -5px 5px #000;
height: 100%;
border: 1px solid darkgrey;
border-left: 0;
border-right: 0;
}
.div2 {
box-shadow: -4px 0px 2px 0.5px #000, 2px 0px 0.5px 0.5px #000, 5px 0.5px 3px 0px #000;
height: 100%;
border: 1px solid #333333;
}
.div3 {
box-shadow: -6px 3px 5px #000, 6px 5px 6px 1px #000;
height: 100%;
position: relative;
border: 1px solid darkgrey;
border-left: 0;
border-right: 0;
}
<!DOCTYPE html>
<html lang="en">
<body>
<table>
<tr>
<td>stuff</td>
</tr>
<tr class="selected-top">
<td>
<div class="div1">
highlighting starts
</div>
</td>
</tr>
<tr class="selected-middle">
<td>
<div class="div2">
highlighting middle
</div>
</td>
</tr>
<tr class="selected-bottom">
<td>
<div class="div3">
highlighting end
</div>
</td>
</tr>
<tr>
<td>other stuff</td>
</tr>
</table>
</body>
</html>
I tried to create similar to what you have provided in the expected output

Remove Box Shadow from Left Side

I'm creating a custom sider toggle for an ant design project and I'm struggling to preserve three sides (i.e top, right, left) of the box-shadow (i.e. 2px 2px 8px rgba(0, 0, 0, 0.15)) and remove the box-shadow/blur entirely from the left side. My most recent attempt is below. Any thoughts?
JSX:
<span onClick={this.toggleCollapse} className="ant-layout-sider-zero-width-trigger">
{collapsed ? <Icon type="menu-unfold" /> : <Icon type="menu-fold" />}
</span>
LESS:
.ant-layout-sider-zero-width-trigger {
background: #fff;
color: #000000a6;
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15), inset -2px 0px 0px #fff;
&:hover {
background: #fff;
}
}
btw I've seen similar questions on Stack but none worked for me after much experimentation.
An idea is to use another container and rely on some overflow:
.container {
display:inline-block;
padding:5px 5px 5px 0;
overflow:hidden;
}
.box {
width:200px;
height:50px;
background: #fff;
color: #000000a6;
box-shadow:
2px 2px 8px rgba(0, 0, 0, 0.15),
inset -2px 0px 0px #fff;
}
<div class="container">
<div class="box">
</div>
</div>
You could increase the offset of the shadow and reduce its size:
html {
background: white;
}
body {
padding: 2em;
margin: 2em;
background: yellow;
box-shadow: 4px 4px 8px -4px, inset -2px 0px 0px #fff;
}

Table header with rounded corners and border

Is it possible for a table header to have rounded corners and a 1px border?
When I apply a border to the th elements, the border corners are square instead of round.
table {
border-collapse: collapse;
}
th {
background: cyan;
border: 1px solid;
}
th:first-child {
border-radius: 10px 0 0 0;
}
th:last-child {
border-radius: 0 10px 0 0;
}
td {
border: 1px solid;
}
<table>
<tr><th>Col 1</th><th>Col 2</th></tr>
<tr><td>a</td><td>b</td></tr>
<tr><td>c</td><td>d</td></tr>
</table>
This makes all table headers (if you are using semantic th cells instead of body td cells) have rounded corners, but if you wish it for only selected tables - then rename the class to table.rounded th and just add rounded class to those tables:
th {
-khtml-border-radius: 4px 4px 4px 4px;
-moz-border-radius: 4px 4px 4px 4px;
-ms-border-radius: 4px 4px 4px 4px;
-o-border-radius: 4px 4px 4px 4px;
-webkit-border-radius: 4px 4px 4px 4px;
border-radius: 4px 4px 4px 4px;
border: solid 1px black;
}
EDIT: you need to have border-collapse: separate; on your table for this to be possible...
Add a <div> wrapper inside of each <th>. Add your border styles to the wrappers.
table {
border-collapse: collapse;
}
th {
padding: 0;
}
th div {
background: cyan;
border: 1px solid;
width: 80px;
}
th:first-child div {
border-radius: 10px 0 0 0;
}
th:last-child div {
border-radius: 0 10px 0 0;
}
<table>
<tr>
<th><div>Col 1</div></th>
<th><div>Col 2</div></th>
<th><div>Col 3</div></th>
<th><div>Col 4</div></th>
</tr>
</table>
You can use box-shadow to fake the border:
box-shadow: 0px 0px 2px #ddd inset;
Admittedly, this results in a brighter color than with normal borders, so you'll have to compensate for that.

Is it possible to set transparency in CSS3 box-shadow?

Is it possible to set transparency on the box shadow?
This is my code:
box-shadow:10px 10px 10px #000;
-webkit-box-shadow:10px 10px 10px #000;
-moz-box-shadow: 10px 10px 10px #000;
I suppose rgba() would work here. After all, browser support for both box-shadow and rgba() is roughly the same.
/* 50% black box shadow */
box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.5);
div {
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
color: white;
background-color: red;
margin: 10px;
}
div.a {
box-shadow: 10px 10px 10px #000;
}
div.b {
box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.5);
}
<div class="a">100% black shadow</div>
<div class="b">50% black shadow</div>

Resources