How to achieve this effect with css - html

I would to be able to create this effect shown here:
Where a block of a section is pushed up on top of another section, it's often times a block of text that does it, but I couldn't find a good example of it so my s/s uses an image.
I know this is a very common effect but I don't know its name so I am struggling to find guides on it. If someone can just give me the name of this CSS effect that'd be awesome so I can search for it on the web and learn how to achieve this effect.

I used a negative margin on the overlaying element: https://jsfiddle.net/2ezwtj1j/3/
html
<div id="landing"></div>
<div id="card">
<h1>My Sick Header</h1>
<p>My amazing content.</p>
</div>
css
#landing {
margin:0px;
padding-bottom: 200px;
background: #7703a5;
background: -moz-linear-gradient(-45deg, #7703a5 0%, #00c7ef 100%);
background: -webkit-linear-gradient(-45deg, #7703a5 0%,#00c7ef 100%);
background: linear-gradient(135deg, #7703a5 0%,#00c7ef 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7703a5', endColorstr='#00c7ef',GradientType=1 );
}
#card {
padding: 1vw;
box-shadow: 0 1px 3px 0 #D4D4D5, 0 0 0 1px #D4D4D5;
width:80%;
height:300px;
background:#fff;
margin: 0 auto;
margin-top:-100px;
font-family: sans-serif;
}

In their case, they used absolute positioning. You can also move an element up (into another section) using transform: translate();. Below is an example.
BTW, you can always use your dev tools to inspect the page and see what CSS they used to position that element. Here is the URL for that layout in your screenshot. http://unbounce.com/landing-page-template/mova/
* {margin:0;}
section {
background: red;
height: 100vh;
position: relative;
}
section:nth-child(2) {
background: blue;
}
h1 {
background: #fff;
position: absolute;
top: -.5em;
width: 50%;
text-align: center;
left: 50%;
transform: translateX(-50%);
}
<section></section>
<section><h1>hello</h1></section>

You can achieve this by using the negative top margin take a look:
https://jsfiddle.net/7Lb5x1he/
HTML
<div></div>
<div></div>
<div></div>
CSS
div {
height: 200px;
border: 1px solid black;
}
div:nth-of-type(1) {
background: lightblue;
}
div:nth-of-type(2) {
background: grey;
}
div:nth-of-type(3) {
width: 60%;
margin: -300px auto 0 auto;
background: white;
}

Related

Inner rounded shadows inside div

I have a div which looks something like this:
.box{
box-sizing: border-box;
border: solid 0.01rem #2e2e2e;
border-radius: 3px;
width:100px;
height:100px;
background:red;
}
<div class="box"/>
And I'm trying to achieve this effect. How can I make this box look with such shadows from the inside of the div?
linear gradient
blur filter
absolute positioning
pseudo-elements
flexbox
.box {
box-sizing: border-box;
border-radius: 10%;
width: 100px;
height: 100px;
background: linear-gradient(270deg, red, #c10606);
position: relative;
}
.box:before {
position: absolute;
content: '';
top: 10%;
right: 10%;
bottom: 10%;
left: 10%;
background: linear-gradient(90deg, red, #c10606);
border-radius: 12%;
filter: blur(1px); /* optional for a softer effect */
}
/* optional layout and styling for box contents */
.box {
display: flex;
align-items: center;
text-align: center;
font-family: arial;
color: #ddd;
font-weight: bold;
}
.box * {
position: relative; /* puts interior content over the pseudo-element */
}
<div class="box">
<span>Interior content</span>
</div>
CSS box-shadow
I think the answer posted by #isherwood works as the best one for your use-case. But, there is a way to make the shadow show on the inside of the element by setting the last parameter of box-shadow as inset.
There are a few catches for this solution though. A few things which I could not achieve:
I am unable to implement linear gradient to the shadow.
I am unable to give a border-radius to the inner boundary of the shadow.
div.box {
background: linear-gradient(90deg, hsl(26, 68%, 26%), hsl(26, 68%, 45%));
height: 100px;
width: 100px;
box-shadow: 0 0 0 12px hsl(26, 68%, 35%) inset;
border-radius: 10px;
}
<div class="box"></div>
Reference: How to create an inner shadow using CSS
Well, I edited your code. Here is the demo.
Basically, I added one more div and added some style. Hope it will give you an idea.
Also, I added a snippet down below:-
.box {
box-sizing: border-box;
border: solid 0.01rem #2e2e2e;
border-radius: 15px;
width: 100px;
height: 100px;
background: red;
padding: 10px 0px 10px 0px;
}
.inner-div {
box-sizing: border-box;
border-radius: 15px;
width: 78px;
height: 78px;
background: #ee1717;
margin: 0 auto;
}
<div class="box"/>
<div class="inner-div"></div>
<div>

Css shadow entire screen length

box shadows are basically your shape blurred.
that means that at the edges the shadow is curved up.
what if you don't want that? what if your shadow is for a top bar and you don't want it to seems like it ends?
issue:
desired effect :
how do I obtain this?
html :
<div class="TopBar"> </div>
css :
.TopBar {
box-shadow: 0 4px 28px black;
}
Am I supposed to use an absolute positioned element that's bigger than screen width or something?
You can add a spread parameter to the shadow (not exactly the same appearance, but at least it does what you ask for):
html,
body {
margin: 0;
}
.TopBar {
height: 40px;
background: #444;
box-shadow: 0px 4px 24px 16px black;
}
<div class="TopBar"></div>
Fake it! You can use linear gradient and a pseudo element to get the effect you want:
.TopBar {
height: 50px;
background: gray;
position: relative;
}
.TopBar::after {
content: "";
background: linear-gradient(to bottom, rgba(0,0,0,.8) 0%,rgba(0,0,0,0) 100%);
position: absolute;
width: 100%;
height: 20px;
top: 100%;
}
<div class="TopBar"> </div>
You can add a pseudo-element (:before) to extend it beyond your original container and therefore, get a wider shadow :
html, body { margin:0; padding: 0 }
.TopBar {
height: 50px;
position: relative;
}
.TopBar:before {
content: "";
display: block;
position: absolute;
height: 100%;
width: 100%;
background: #454545;
box-shadow: 0 4px 28px #000;
transform: scaleX(1.1);
z-index: -1;
}
.TopBar .content {
color: #add8e6;
}
<div class="TopBar">
<div class="content">Here's some text inside my top bar</div>
</div>

Style nav button with css shap with gradient, gradient background, and centered text

So I'm trying to make a nav buttons without using a image. But I can't get the CSS to work out properly. I managed to get everything but the vertical alignment of the text, yet to get that far I feel the code as become more sloppy than necessary. Here is what I have:
.nav_button {
height: 18px;
background: linear-gradient(#3D3C3B 0%, #0A0B0A 50%);
margin-top: 5px;
}
.arrow_container {
display: inline-block;
width: 35px;
}
.nav_arrow {
width: 20px;
height: 18px;
background: linear-gradient(#D2DA76 0%, #5EB649 50%);
}
.nav_link {
display: inline-block;
width: 125px;
text-align: center;
}
.nav_arrow::after {
display: block;
content: '';
height: 18px;
width: 20px;
background: linear-gradient(to bottom right, #D2DA76 0%, #5EB649 50%);
transform: translate(10px, 0px) scale(.8, .715) rotate(45deg);
}
<a href='#'>
<div class='nav_button'><span class='arrow_container'><div class='nav_arrow'></div></span><span class='nav_link'>Test</span></div>
</a>
Is there a better way to write this? if not I at least need to know how to vertical align the text. line-height did not work.
Edit: Here is a demo pic. the arrow is backwards but it's close.
A better solution may be to actually build your button's structure relative to the size of the text's line-height, rather than trying to hardcode the size and then update the line-height secondly.
The simplification of the html is based upon the idea that we use a single gradient overlay on the button rather than fading both the button background and the "arrow" section with different colours independently. However, this doesnt exactly match the design.
.nav_button_alt{
display:inline-block;
border:1px solid #888;
color:#FFF;
text-decoration:none;
font-family:Helvetica, Arial, sans-serif;
position:relative;
background:#5EB649;
font-size:1.2em;
line-height:1.4em;
padding:0 0.2em 0 40px;
min-width:125px; /* remove this if you wish the buttons to be relative to the size of the text*/
}
.nav_button_alt > span{
display:inline-block;
position:relative;
width:100%;
z-index:3;
text-align:center;
}
/* provides the fade */
.nav_button_alt:before{
content:"";
position:absolute;
top:0;
left:0;
right:0;
z-index:2;
height:100%;
background-image: linear-gradient(rgba(255,255,255,0.6) 0%, rgba(255,255,255,0) 50%);
}
/* provides the "black" overlay of the green background */
.nav_button_alt:after{
content:"";
position:absolute;
left:1.2em; /* distance from the right that the arrow starts */
top:0;
height:0;
right:0;
border-left:1em solid transparent; /* size of the green arrow's point */
border-top:0.7em solid #000; /* half the height of the button */
border-bottom:0.7em solid #000; /* half the height of the button */
z-index: 1;
}
<a href="#" class="nav_button_alt">
<span>Test</span>
</a>
Try vertically aligning the text inside the button.
.nav_button {
height: 18px;
background: linear-gradient(#3D3C3B 0%, #0A0B0A 50%);
margin-top: 5px;
}
.arrow_container {
display: inline-block;
width: 35px;
}
.nav_arrow {
width: 20px;
height: 18px;
background: linear-gradient(#D2DA76 0%, #5EB649 50%);
}
.nav_link {
display: inline-block;
width: 125px;
text-align: center;
vertical-align:top;
}
.nav_arrow::after {
display: block;
content: '';
height: 18px;
width: 20px;
background: linear-gradient(to bottom right, #D2DA76 0%, #5EB649 50%);
transform: translate(10px, 0px) scale(.8, .715) rotate(45deg);
}
<a href='#'>
<div class='nav_button'><span class='arrow_container'><div class='nav_arrow'></div></span><span class='nav_link'>Test</span></div>
</a>
Use "line-height" for vertical alignment of text. Here's an example
div {
height: 90px;
line-height: 90px;
text-align: center;
border: 2px dashed #f69c55;
}
<div>
Hello World!
</div>

vertical align two elements within a div

I have the following div:
<div class="transparent-panel">
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
and I want the text and button to appear centred within the div. Currently it appears like so:
and I am having no luck getting to centre. Here is the css for the transparent-panel div:
.transparent-panel {
padding: 40px 20px 40px 20px;
width: 100%;
height: 100%;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
I tried using position: relative; on the div and then position: absolute; on the h3 and a tag but that didn't work.
If anyone can help me out it would be much appreciated. I am using Bootstrap 3.
Here is a bootply demo http://www.bootply.com/sQ5gyYn7Ru
One way to do it would be to wrap the panel in a container, put the background color on the container and then use a few lines of CSS to vertically center the panel within the container:
HTML:
<div class="panel-container">
<div class="transparent-panel">
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
</div>
CSS:
html,body {
height:100%;
}
.panel-container {
height:100%;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
.transparent-panel {
padding: 40px 20px 40px 20px;
width: 100%;
text-align:center;
/* Code to vertically center below */
position: relative;
top: 50%;
transform: translateY(-50%);
}
Bootply Example
I find it useful to set the container div as display: table, and wrap the content in a inner div set as display: table-cell.
Then you can use the vertical-align property:
Updated BootPly
/* CSS used here will be applied after bootstrap.css */
.teachers-image {
background-size: cover;
height: 418px;
color: #ffffff;
}
.transparent-panel {
padding: 0 20px;
display: table;
width: 100%;
height: 100%;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
.transparent-panel > div {
display: table-cell;
vertical-align: middle;
}
.btn-white-big {
background-color: #ffffff;
height: 50px;
color: #339933;
font-size: 18px;
font-weight: 500;
line-height: 30px;
#include add-border(3px, white, all);
#include border-radius(30px);
&:hover,
&:focus,
&.focus {
background-color: #339933 !important;
color: white;
}
}
<div class="teachers-image">
<div class="transparent-panel">
<div>
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
</div>
</div>
Use a container with View Height for top to bottom centering:
height: 100vh;
The View Height will always use the windows display height.
Fiddle
HTML:
<div class="container">
<div class="transparent-panel">
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
</div>
CSS:
.container {
height: 100vh;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
.transparent-panel {
width: 100%;
text-align:center;
position: relative;
top: 50%;
}

Need help getting an effect on a header and with a button

I am trying to get a certain effect on a header for a mockup. It has white glow almost not noticeable. You will see it in this picture i provide behind the title and sub title. How can i get that glow effect with css? I do have a header with the entire thing but is that a good idea to use an image for an entire header? Also i want those two lines near the subtitle. Is it possible to code those lines? And last, the button "order now", will that be possible to make with css or should i just use an image of that and link it?
mockup
jsfiddle - http://jsfiddle.net/ezdr3xdg/1/ [what i currently have]
<header>
<h1>Taffies Cupcakes</h1>
<h2>Fresh and tasty</h2>
</header>
body{
background-color:#e7d2c9;
}
header h1{
font-family:georgia;
font-size:46px;
color:#784f3d;
text-align:center;
margin-top:50px;
}
header h2{
font-family:segoe script;
font-size:32px;
color:#846a5f;
text-align:center;
}
All of this is possible to do in CSS 3, I wouldn't recommend it though. Using an image for the button and the header is the best idea if you want it to look the same in all browsers. If you want to do it in CSS anyway try this:
HTML:
<header>
<div class="shadow"></div>
<h1>Taffies Cupcakes</h1>
<h2><div class="line"></div>Fresh and tasty<div class="line"></div></h2>
</header>
CSS:
header > .shadow {
width: 0px;
height: 0px;
margin: 0px 50%;
box-shadow: 0px 0px 200px 100px white;
}
header h2 > .line {
height: 1px;
width: 100px;
margin: 5px 20px;
background-color: #846a5f;
display: inline-block;
vertical-align: middle;
}
As the other answers have mentioned, radial-gradient is probably the way to go here. Just apply it to the header element instead of using my version with box-shadow (which might be a little hacky to some).
Update for the button:
HTML:
<button class="special"><div class="icon"></div><div class="headline">ORDER NOW</div><div class="description">We deliver in 24 hours</div></button>
CSS:
button.special {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #784f3d), color-stop(1, #846a5f) );
background:-moz-linear-gradient( center top, #784f3d 5%, #846a5f 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#784f3d', endColorstr='#846a5f');
background-color:#784f3d;
color: #e7d2c9;
text-align: left;
border: 0;
outline: 0;
border-radius: 5px;
height: 42px;
}
button.special > .icon {
width: 27px;
height: 27px;
/*background-image: url('triangle-button.png')*/
position: absolute;
margin: 5px;
}
button.special > .headline {
margin-left: 42px;
font-size: 18px;
}
button.special > .description {
margin-left: 42px;
font-size: 12px;
}
http://jsfiddle.net/ezdr3xdg/17/
Use CSS radial-gradient()
DEMO 1:
body {
height: 100vh;
background-color: #e7d2c9;
background-image: -webkit-radial-gradient(center top, ellipse farthest-corner, #fff 0%, #e7d2c9 50%);
}
DEMO 2:
body{
height:100vh;
background-color:#e7d2c9;
background-image: -webkit-radial-gradient(center top, ellipse farthest-corner, #fff 0%, #e7d2c9 100%);
}
DEMO 3:
body {
height: 100vh;
background-color: #e7d2c9;
position:relative;
}
body:after {
content: '';
position: absolute;
left: 50%;
top: -150px;
margin-left: -100px;
width: 200px;
height: 200px;
border-radius: 50%;
z-index:-1;
background: rgba(255, 255, 255, 0.42);
box-shadow: 0 0 40px 64px rgba(255, 255, 255, 0.42);
}
I have update your jsfiddle with a starting template of sorts. Its CSS# gradients and border-radius. http://jsfiddle.net/ezdr3xdg/7/
the button:
<div id="order_now">
<div id="triangle-right"></div>
<div id="text">
ORDER NOW
<div id="sub_order">we deliver in 24hours</div>
</div>
</div>
CSS:
The Button:
#order_now{
background: linear-gradient(#846a5f, brown);
width: 200px;
border-radius: 5px;
padding: 5px;
color: white;
font-size: 12pt;
font-weight: bold;
}
#sub_order{
font-size: 10pt;
font-style: italic;
}
#triangle-right {
width: 0;
height: 0;
border-top: 25px solid transparent;
border-left: 50px solid white;
border-bottom: 25px solid transparent;
display: inline-block;
}
#text{
display: inline-block;
}
The Background:
body{
background:linear-gradient(to right, red, blue, red);
}
this should be enough to get you started.