Box shadow with transparent layer [duplicate] - css

This question already has answers here:
Transparent space between div and border with a border radius
(2 answers)
Closed 11 months ago.
I am trying to create a button with box-shadow like below:
with transparent space between the button and the shadow. How can it be implemented?

I don't think box-shadow is the best approach. You can instead try outline css property.
.btn {
display: inline-block;
margin: 20px;
padding: 15px 30px;
background-color: #aaa;
border-radius: 25px;
outline: 4px solid #aaa;
outline-offset: 4px;
}
<div class="btn">
Action
</div>

.button-wrapper {
margin: 0 auto;
display: table;
padding: 100px 0;
background-color: #625e5e;
width: 100%;
text-align: center;
}
.button-wrapper button.custom-btn {
border: 0;
background-color: transparent;
padding: 0px 0px;
border-radius: 100px;
color: #fff;
border: 5px transparent solid;
outline: 5px rebeccapurple solid;
}
body {
margin: 0;
}
.button-wrapper button.custom-btn span {
border: 0;
background-color: rebeccapurple;
padding: 10px 0px;
border-radius: 100px;
min-width: 115px;
color: #fff;
font-size: 15px;
letter-spacing: 2px;
display: block;
border: 5px transparent solid;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<div class="button-wrapper">
<button type="button" class="custom-btn">
<span class="">Action</span>
</button>
</div>
</body>
</html>

Related

Adding shadows on tab overlaps in CSS

I am creating a tab based system where you can add days and add information for each day. I am trying to achieve an overlapping look when it comes to the tabs and would like to add a sort of shadow like effect when a tab is being overlapped by another on the left side. In this specific example, when day one is active, day 2's inner left portion will have a bit of a shadow to make it look like it is being overlapped. How can I achieve this effect?
.breakout-holder {
width: 100%;
border: 1px solid black;
}
.heading {
/* background-color: grey; */
height: 40px;
display: flex;
align-items: flex-end;
}
.active {
background-color: lightgreen !important;
/* box-shadow: inset 0 20px 20px -20px #000000; */
z-index: 5000;
}
.tab {
font-weight: bold;
background-color: lightgrey;
color: black;
height: 90%;
width: auto;
padding: 0 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
border-radius: 15px 15px 0 0;
cursor: pointer;
}
.tab:not(:first-child) {
margin-left: -5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="breakoutStyle.css">
<title>Breakout room form</title>
</head>
<body>
<div class="breakout-holder">
<div class="heading">
<div class="tab active">
Day 1
</div>
<div class="tab">
Day 2
</div>
<div class="tab" style="z-index: -10">
+
</div>
</div>
<div class="body"></div>
</div>
</body>
<script src="app.js"></script>
</html>
I have tried adding in a box shadow to the tab elements that are on top of another tab. This method did not work as it looks a little cheap in my opinion.
Here is the css I tried to add to the tab css class
-webkit-box-shadow: 34px 0px 25px -13px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 34px 0px 25px -13px rgba(0, 0, 0, 0.75);
box-shadow: 34px 0px 25px -13px rgba(0, 0, 0, 0.75);
You can use pseudo elements for this, but the caveat is you can't use a negative z-index because of the stacking context and the need for the active tab to be above the other tabs.
This is basically using the box-shadow and the transform: skew to fake either side of the active tab.
Then I have styles for the first and last active tabs so the :before and :after, respectively, do not show up if either are active.
This approach gives you a little more of a "polished" look instead of just using box-shadow on the active tab.
.breakout-holder {
width: 100%;
border: 1px solid black;
}
.heading {
/* background-color: grey; */
height: 40px;
display: flex;
align-items: flex-end;
position: relative;
}
.tab.active {
position: relative;
background-color: lightgreen !important;
z-index: 5;
}
.tab {
position: relative;
font-weight: bold;
background-color: lightgrey;
color: black;
height: 90%;
width: auto;
padding: 0 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
border-radius: 15px 15px 0 0;
cursor: pointer;
}
.tab:not(:first-child) {
margin-left: -5px;
}
.tab::before,
.tab::after {
content: '';
position: absolute;
left: 0;
bottom: 2px;
box-shadow: -3px 0px 4px 1px rgba(0, 0, 0, .3);
transform: skew(-5deg,-10deg);
width: 1px;
height: 60%;
border-radius: 0;
display: none;
}
.tab::after {
left: auto;
right: 0;
box-shadow: 3px 1px 4px 1px rgba(0, 0, 0, .3);
transform: skew(5deg,10deg);
}
.tab.active::before,
.tab.active::after {
z-index: -1;
display: block;
}
.tab.active:first-child::before {
display: none;
}
.tab.active:last-child::after {
display: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="breakoutStyle.css">
<title>Breakout room form</title>
</head>
<body>
<div class="breakout-holder">
<div class="heading">
<div class="tab">
Day 1
</div>
<div class="tab active">
Day 2
</div>
<div class="tab">
+
</div>
</div>
<div class="body"></div>
</div>
</body>
<script src="app.js"></script>
</html>
Add this to the active tab: box-shadow: 2px 1px 2px 1px rgba(0, 0, 0, 0.4);
.breakout-holder {
width: 100%;
border: 1px solid black;
}
.heading {
/* background-color: grey; */
height: 40px;
display: flex;
align-items: flex-end;
}
.active {
background-color: lightgreen !important;
box-shadow: 2px 1px 2px 1px rgba(0, 0, 0, 0.4);
z-index: 5000;
}
.tab {
font-weight: bold;
background-color: lightgrey;
color: black;
height: 90%;
width: auto;
padding: 0 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
border-radius: 15px 15px 0 0;
cursor: pointer;
}
.tab:not(:first-child) {
margin-left: -5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="breakoutStyle.css">
<title>Breakout room form</title>
</head>
<body>
<div class="breakout-holder">
<div class="heading">
<div class="tab active">
Day 1
</div>
<div class="tab">
Day 2
</div>
<div class="tab" style="z-index: -10">
+
</div>
</div>
<div class="body"></div>
</div>
</body>
<script src="app.js"></script>
</html>
.breakout-holder {
width: 100%;
border: 1px solid black;
}
.heading {
/* background-color: grey; */
height: 40px;
display: flex;
align-items: flex-end;
}
.active {
background-color: lightgreen !important;
-webkit-box-shadow: 0px 10px 4px -2px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 10px 4px -2px rgba(0,0,0,0.75);
box-shadow: 0px 10px 4px -2px rgba(0,0,0,0.75);
z-index: 5000;
}
.tab {
font-weight: bold;
background-color: lightgrey;
color: black;
height: 90%;
width: auto;
padding: 0 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
border-radius: 15px 15px 0 0;
cursor: pointer;
}
.tab:not(:first-child) {
margin-left: -5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="breakoutStyle.css">
<title>Breakout room form</title>
</head>
<body>
<div class="breakout-holder">
<div class="heading">
<div class="tab active">
Day 1
</div>
<div class="tab">
Day 2
</div>
<div class="tab" style="z-index: -10">
+
</div>
</div>
<div class="body"></div>
</div>
</body>
<script src="app.js"></script>
</html>
It would be nice if you could link some examples of what you are going for, but something you can possibly do is this:
/* background-image: linear-gradient(#134C13, #66AF66, lightgreen); */
.breakout-holder {
width: 100%;
border: 1px solid black;
}
.heading {
/* background-color: grey; */
height: 40px;
display: flex;
align-items: flex-end;
}
.tab {
font-weight: bold;
background-color: lightgrey;
color: black;
height: 90%;
width: auto;
padding: 0 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
border-radius: 15px 15px 0 0;
cursor: pointer;
}
.active {
background-color: lightgreen !important;
border-right: 5px solid black;
border-bottom: 2px solid black;
/* box-shadow: inset 0 20px 20px -20px #000000; */
z-index: 5000;
}
.tab:not(:first-child) {
margin-left: -5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="breakoutStyle.css">
<title>Breakout room form</title>
</head>
<body>
<div class="breakout-holder">
<div class="heading">
<div class="tab active">
Day 1
</div>
<div class="tab">
Day 2
</div>
<div class="tab" style="z-index: -10">
+
</div>
</div>
<div class="body"></div>
</div>
</body>
<script src="app.js"></script>
</html>

Banner not displaying CSS

I have the following code to display a banner in my CSS stylesheet.
#banner {
background-image: url(../Images/banner.png);
background-repeat: no-repeat;
background-size: cover;
border: 5px solid #dedede;
height: 200px;
}
The banner is not displaying. Instead I get a small white cube in the top left hand corner.
The full CSS style sheet is:
body {
font-family: lucida grande,tahoma,verdana,arial,sans-serif;
background-color: #e9e9e9;
}
body p {
font-size: 0.8em;
line-height: 1.28;
}
#wrapper {
width: 1080px;
background-color: #fff;
margin: 0 auto;
padding: 10px;
border: 5px solid #dedede;
}
#banner {
background-image: url(../Images/banner.png);
background-repeat: no-repeat;
background-size: cover;
border: 5px solid #dedede;
height: 200px;
}
#content_area {
float: left;
width: 750px;
margin: 20px 0 20px 0;
padding: 10px;
}
#sidebar {
clear: right;
width: 250px;
height: 400px;
margin: 20px 10px;
padding: 10px;
border: 2px solid #E3E3E3;
}
footer {
clear: both;
width: auto;
height: 40px;
padding: 10px;
border: 3px solid #E3E3E3;
text-align: center;
color: #fff;
text-shadow: 0.1em 0.1em #333;
background-image: url(../Images/banner.jpg);
}
#navigation {
height: 60px;
border: 3px solid #E3E3E3;
margin-top: 20px;
text-shadow: 0.1em 0.1em #333;
background-image: url(../Images/footer.jpg);
}
#nav {
list-style: none;
}
#nav ul {
margin: 0;
padding: 0;
width: auto;
display: none;
}
#nav li {
font-size: 24px;
float: left;
position: relative;
width: 180px;
height: 50px;
}
#nav a:link, nav a:active, nav a:visited {
display: block;
color: #fff;
text-decoration: none;
}
#nav a:hover {
color: lightblue;
}
Here is my HTML code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css"/>
</head>
<body>
<div id="wrapper">
<div id=banner">
</div>
<nav id="navigation">
<ul id="nav">
<li>Home</li>
<li>Books</li>
<li>Publications</li>
<li>About Us</li>
</ul>
</nav>
<div id="content_area">
<?php echo $content; ?>
</div>
<div id="sidebar"></div>
<footer>
<p>All rights reserved</p>
</footer>
</body>
</html>
Looks like a double quotation marks error in the id attribute value
<div id=banner">
This is what I would do:
1. Try doing background-repeat: repeat; ... see what happens.
2. right click on the small image and click view image to confirm that the image is the right one.
3. post the html for better understanding.

100% width w/o parent element

I'm a bit confused. I'm building an To-Do List app and I'm trying to set the header as 100% of the screen width. I have the correct meta tags, I believe, but setting the header at 100% width is stretching the element past the right side of the screen. Is there something I'm doing wrong?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo List App</title>
<link rel="stylesheet" text="text/css" href="style.css">
</head>
<body>
<header>
<input type="text" placeholder="Enter an activity...">
<button></button>
</header>
</body>
</html>
#charset "UTF-8";
header {
width: 100%;
height: 80px;
position: fixed;
padding: 15px;
top: 0px;
left: 0px;
z-index: 5;
background: #25b99a;
box-shadow:0px 2px 4px rgba(44, 62, 80, 0.15);
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
header input {
width: 100%;
height: 50px;
float: left;
background: rgba(255,255,255,0.2);
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-radius: 5px;
border: 0px;
box-shadow: none;
outline: none;
}
You need to include the box-sizing property.
Info from MDN
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
}
header {
width: 100%;
height: 80px;
position: fixed;
padding: 15px;
top: 0px;
left: 0px;
z-index: 5;
background: #25b99a;
box-shadow: 0px 2px 4px rgba(44, 62, 80, 0.15);
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
header input {
width: 100%;
height: 50px;
float: left;
background: rgba(255, 255, 255, 0.2);
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-radius: 5px;
border: 0px;
box-shadow: none;
outline: none;
}
<header>
<input type="text" placeholder="Enter an activity...">
<button></button>
</header>

Transfer inline style to external style sheet

I have used inline styling to put a radiused border around the five images in my index file. How do I apply this style to them by declaring css attributes/values in the external style sheet. Here is a demo of the index file http://jsfiddle.net/23nfM/embedded/result/
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>pedrosdigitalsolutions.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="image/x-icon" href="/custom pds/images/cheat_1.ico" rel="shortcut icon">
<link media="screen" type="text/css" href="style.css" rel="stylesheet">
</head>
<body>
<?php include 'header.php' ?>
<div id="content">
<p class="tab"><font size="7"><b>For all things</b></font><br>
<font size="7"><b>Electronic Arduino</b></font><br>
<font size="7"><b>and "other stuff"</b></font><br>
<font size="6"><b>Love ♥ The Duino</b></font>
</p>
<img style="position:absolute; top:515px; left:692px; width:300px; height:225px; border: 1px solid #000000; border-radius: 8px"
src="http://www.pedroduino.com/custom pd/images/Manual Shift Register 300x225.gif">
<img style="position:absolute; top:215px; left:692px; width:300px; height:225px; border: 1px solid #000000; border-radius: 8px"
src="http://www.pedroduino.com/custom pd/images/Manual LCD 300x225.gif">
<img style="position:absolute; top:515px; left:150px; width:300px; height:225px; border: 1px solid #000000; border-radius: 8px"
src="http://www.pedroduino.com/custom pd/images/LCDBitmap_via_SR.gif">
<img style="position:absolute; top:815px; left:150px; width:300px; height:225px; border: 1px solid #000000; border-radius: 8px"
src="http://www.pedroduino.com/custom pd/images/8_LED_Array.gif">
<img style="position:absolute; top:815px; left:692px; width:300px; height:225px; border: 1px solid #000000; border-radius: 8px"
src="http://www.pedroduino.com/custom pd/images/Nicks Clock 300x225.gif">
</div>
<?php include 'footer.php' ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="nagging-menu.js" charset="utf-8"></script>
</body>
</html>
body {
background: #efefef;
border: none;
color: #3F4C6B;
font: normal 13px Verdana, sans-serif;
margin: 0;
padding: 0;
text-align: center; }
#content {
height: 950px;
margin-bottom: 25px;
margin: 0 auto;
padding: 30px 0;
text-align: justify;
width: 950px;
}
.default {
-moz-box-shadow: 0 5px 20px #888;
-webkit-box-shadow: 0 5px 20px #888;
box-shadow: 0 5px 20px #888;
height: 50px;
width: 100%; }
.fixed {
-moz-box-shadow: 0 0 40px #222;
-webkit-box-shadow: 0 0 40px #222;
box-shadow: 0 0 40px #222;
left: 0px;
position: fixed;
top: -5px;
width: 100%; }
#footer {
-moz-box-sizing: border-box;
background: none repeat scroll 0 0 #98B0D9;
background: -webkit-linear-gradient(#98B0D9);
height: 70px;
position: relative;
z-index: 1;
}
h1 { line-height: 15px; }
#header {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background: linear-gradient(#606C88, #3F4C6B) repeat scroll 0 0 rgba(0, 0, 0, 0);
background: -webkit-linear-gradient(#606C88, #3F4C6B);
border-color: #0F1620 #000000;
border-image: none;
height: 93px;
margin: 0;
width: auto; }
#logo {
border: medium none;
float: left;
margin: 0; }
#menu {
-moz-border-radius: 5px;
background: -webkit-linear-gradient(#c3d9ff, #98b0d9);
background: linear-gradient(#c3d9ff, #98b0d9) repeat scroll 0 0 rgba(0, 0, 0, 0);
border-radius: 5px;
line-height: 50px;
margin: 0 135px;
margin: 0 auto;
width: 100%;
padding: 0;
text-align: center;
z-index: 5;
float: center;
}
#navi {
height: 50px;
margin-top: 0; }
ul { padding: 0; }
ul li {
display: inline;
list-style-type: none;
margin-right: 15px; }
ul li a {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-webkit-transition-duration: 0.5s, 0.5s;
-webkit-transition-property: color, background;
border-radius: 5px;
color: #fff;
padding: 3px 7px;
text-decoration: none;
text-shadow: 1px 1px 1px #000; }
ul li a:hover {
-webkit-transition-duration: 0.5s, 0.5s;
-webkit-transition-property: color, background;
background: #606C88;
color: #ff0; }
Strip out the inline styles, and put something like this in your external style sheet:
#content img {position:absolute; width:300px; height:225px; border: 1px solid #000000; border-radius: 8px}
Some styles specific to each image have been left out. For those, add a class or id to the image and then write styles for that image. E.g. the first image could have a class of .lalala and then you'd do this in your style sheet:
.lalala {top:515px; left:692px;}
There are a lot of ways to do that, but the easiest path for your current code would be to declare the border and some other styles in the stylesheet, and then position the images with inline styles.
So in the stylesheet, add:
#content img {
position:absolute;
width:300px;
height:225px;
border: 1px solid #000000;
border-radius: 8px;
}
Then in the html, remove all of the inline styles on each image except top and left.

Center button in CSS

Trying to center a button with CSS. However, whenever I use display: block and margin: 0 auto; I get text decoration under the button text.
.app-download .btn {
display: block;
margin: 0 auto;
text-decoration: none;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
font-family: "News Cycle", sans-serif;
font-size: 1.5em;
border-radius: 5px;
color: #ffffff;
background: steelblue;
width: 400px;
padding: 20px 0;
}
.app-download .btn:hover {
background: tomato;
text-decoration: none;
}
MY HTML
<div class="app-download">
<div class="container">
<button type="button" class="btn">Download for iPhone</button>
<button type="button" class="btn">Download for Android</button>
</div>
</div>
How can I center the button without getting a text decoration underneath?
Without your HTML, we can only guess at what you are doing here. But here's one possible solution:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style media="all">
.app-download {text-align: center;}
.app-download .btn {
display: inline-block;
text-decoration: none;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
font-family: "News Cycle", sans-serif;
font-size: 1.5em;
border-radius: 5px;
color: #ffffff;
background: steelblue;
width: 400px;
text-align:center;
padding: 20px 0;
}
.app-download .btn:hover {
background: tomato;
text-decoration: none;
}
</style>
</head>
<body>
<div class="app-download">
Button
</div>
</body>
</html>
Add this to your CSS
a
{
text-decoration:none;
}
Working Fiddle

Resources