I just need to style two-tone color background like this.
I tried and successfully did using linear gradient
background: linear-gradient(172deg, #ECB034 50%, #BE883C 50%);
But it has a problem when resizing web page. It just not well aligned to its corners. Showing weirdly. Like this
is there any way to did this?
.cta{
padding: 60px 0;
background: linear-gradient(172deg, #ECB034 50%, #BE883C 50%);
text-align:center;
}
.cta h3{
font-size: 58px;
margin-bottom: 30px;
font-weight: 700;
}
.cta a{
padding: 16px 49px;
border: 2px solid #000;
color: inherit;
font-size: 20px;
text-transform: uppercase;
display: inline-block;
font-weight: 500;
}
<div class="cta text-center">
<div class="container">
<h3>Let’s talk about your project.</h3>
Get Started >
</div>
</div>
This is a very simple fix with an SVG (as I mentioned in the comments) you simply need to add preserveAspectRatio="none" to the SVG tag and run it through a URL encoder. This one will even generate the CSS for you which is quite nice.
.cta{
padding: 60px 0;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='100%25' width='100%25' preserveAspectRatio='none' viewBox='0 0 10 10'%3E%3Crect width='10' height='10' fill='%23ECB034' /%3E%3Cpath d='m0 10 h10 v-10' fill='%23BE883C' /%3E%3C/svg%3E");
text-align:center;
}
.cta h3{
font-size: 58px;
margin-bottom: 30px;
font-weight: 700;
}
.cta a{
padding: 16px 49px;
border: 2px solid #000;
color: inherit;
font-size: 20px;
text-transform: uppercase;
display: inline-block;
font-weight: 500;
}
<div class="cta text-center">
<div class="container">
<h3>Let’s talk about your project.</h3>
Get Started >
</div>
</div>
You don't need anything complex. Simply change the angle with to bottom right
.cta{
padding: 60px 0;
background: linear-gradient(to bottom right, #ECB034 50%, #BE883C 50%);
text-align:center;
}
.cta h3{
font-size: 58px;
margin-bottom: 30px;
font-weight: 700;
}
.cta a{
padding: 16px 49px;
border: 2px solid #000;
color: inherit;
font-size: 20px;
text-transform: uppercase;
display: inline-block;
font-weight: 500;
}
<div class="cta text-center">
<div class="container">
<h3>Let’s talk about your project.</h3>
Get Started >
</div>
</div>
You can use pseudo and clip-path combination.
.box{
position:relative;
background-color: #ecae20;
text-align:center;
margin: 30px;
padding: 30px;
z-index:1;
}
.box .content{
position:relative;
z-index:3;
}
.box:before {
content: "";
position:absolute;
left:0;
bottom:0;
width: 100%;
height: 100%;
background-color: #BE883C;
clip-path: polygon(0 99%, 100% 0, 100% 99%, 0 100%);
opacity: 0.7;
z-index:2;
}
<div class="box">
<div class="content">
<p> Let's talk about your project </p>
<button> GET STARTED > </button>
</div>
</div>
As the angle needed changes with the aspect ratio it is not possible to do this with linear-gradient without some recalculation on every resize. (This is incorrect, see better suggestion from #temaniAfif using to bottom left etc.)
However, it is possible to create a triangle with its hypoteneuse being a diagonal by using clip-path and a polygon.
There is no need to inline an SVG if you put the two colors as backgrounds to the before and after pseudo elements, the after also having a clip-path.
.cta {
padding: 60px 0;
text-align: center;
position: relative;
}
.cta::before,
.cta::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.cta::before {
background-color: #ECB034;
}
.cta::after {
background-color: #BE883C;
clip-path: polygon(0 100%, 100% 0, 100% 100%);
}
.cta h3 {
font-size: 58px;
margin-bottom: 30px;
font-weight: 700;
}
.cta a {
padding: 16px 49px;
border: 2px solid #000;
color: inherit;
font-size: 20px;
text-transform: uppercase;
display: inline-block;
font-weight: 500;
}
<div class="cta text-center">
<div class="container">
<h3>Let’s talk about your project.</h3>
Get Started >
</div>
</div>
You can use pseudo element for the same.
#import "https://cdn.jsdelivr.net/gh/KunalTanwar/normalize/css/normalize.inter.min.css";
body {
height: 100%;
display: grid;
place-items: center;
}
.container {
--container-width: 400px;
--container-height: 200px;
width: 100%;
background-color: #ecb034;
height: var(--container-height);
max-width: var(--container-width);
}
.container::after {
content: "";
position: absolute;
width: 0;
height: 0;
user-select: none;
pointer-events: none;
inset: auto 0 0 auto;
border-bottom: var(--container-height) solid #be883c;
border-left: var(--container-width) solid transparent;
}
<div class="container"></div>
Make sure to keep border-left-width and width of the container same. And same for height.
Related
I want to make the color of div darker on hover
I tried decrease the brightness using filter but this affect the text too
:root{
--Dark-cyan: hsl(158, 36%, 37%);
}
#submit{
background: var(--Dark-cyan);
text-align: center;
vertical-align: middle;
color: white;
font-weight: 700;
font-size: 14px;
width: fit-content;
height: fit-content;
padding: 15px 60px;
border-radius: 15px;
}
#submit:hover{
filter: brightness(50%);
}
<div id="submit"> Add to Cart</div>
this is the result that I want:
off hover
on hover
You can use backdrop-filter instead of filter :)
"Because it applies to everything behind the element, to see the effect you must make the element or its background at least partially transparent".
Unfortunately for firefox, this requires at this time: User must explicitly enable the feature
:root {
--Dark-cyan: hsl(158, 36%, 37%, 0.9);
}
#submit {
background: var(--Dark-cyan);
text-align: center;
vertical-align: middle;
color: white;
font-weight: 700;
font-size: 14px;
width: fit-content;
height: fit-content;
padding: 15px 60px;
border-radius: 15px;
}
#submit:hover {
backdrop-filter: brightness(50%);
}
<div id="submit"> Add to Cart</div>
You could use box-shadow: inset with a large spread-radius
it doesn't affect the text color
:root{
--Dark-cyan: hsl(158, 36%, 37%);
}
#submit{
background: var(--Dark-cyan);
text-align: center;
vertical-align: middle;
color: white;
font-weight: 700;
font-size: 14px;
width: fit-content;
height: fit-content;
padding: 15px 60px;
border-radius: 15px;
}
#submit:hover{
box-shadow: inset 0 0 0 /*spread-radius:*/ 100px #33333377;
}
<div id="submit"> Add to Cart</div>
Try this:
You can try reducing the alpha property from rgba()
Try like this:
.your-css-class:hover {
background: rgba(0, 0, 0, 0.25);
}
This can be done using the pseudo ::before and ::afer and some opacity on hover. Take a look at the snippet
:root { --Dark-cyan: hsl(158, 36%, 37%, 0.9) }
.btn, .btn::before, .btn::after { border-radius: 15px }
.btn {
color: white;
cursor: pointer;
display: inline-block;
font-size: 14px; font-weight: 700;
height: fit-content; width: fit-content;
padding: 15px 60px;
position: relative;
}
.btn::before, .btn::after {
content: "";
display: block;
position: absolute;
inset: 0;
z-index: -1
}
.btn::before { background-color: black }
.btn::after { transition: opacity 360ms 0ms ease-in-out }
.btn:hover::after { opacity: 0.6 }
#submit::after { background-color: var(--Dark-cyan) }
#remove::after { background-color: red }
<div class="btn" id="submit">Add to Cart</div>
<div class="btn" id="remove">Remove from Cart</div>
I'm trying to stack the on top of each other vertically but they are overlapping for some reason and not sure if it has to do with the positioning. I'm not very good at CSS. Also, is there an easier way to align the datetime span to the right side instead of using padding-left: 1140px? Thank you
<div class="content-box">
<span class="name">John Doe</span>
<span class="datetime">May 2022</span><br><br>
<span class="content">Lorem ipsum</span>
</div>
<div class="content-box">
<span class="name">Jane Doe</span>
<span class="datetime">June 2022</span><br><br>
<span class="content">Lorem ipsum</span>
</div>
.content-box {
justify-content: center;
top: 600px;
position: absolute;
width: 75%;
border: none;
outline: none;
font-family: 'Roboto Mono', monospace;
font-size: 18px;
transform: translate(0);
background-image: linear-gradient(45deg, #4568DC, #B06AB3);
padding: 20px 40px;
border-radius: 5px;
box-shadow: 0 22px 44px rgba(128, 128, 128, 0.1);
transition: box-shadow .25s;
padding: 60px;
}
.content-box .name {
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-image: linear-gradient(45deg, #4568DC, #B06AB3);
font-size: 30px;
}
.content-box .content {
color: #4568DC;
font-size: 20px;
}
.content-box .datetime {
padding-left: 1140px;
color: black;
font-size: 18px;
}
.content-box .content {
color: #4568DC;
font-size: 20px;
}
.content-box:after {
content: '';
border-radius: 4px;
position: absolute;
margin: 1px;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: -1;
background: white;
}
.content-box:hover {
background-image: linear-gradient(-45deg, #00FFFF, #ff1a1a);
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
transition: .5s;
}
.content-box:hover .name {
background-image: linear-gradient(-45deg, #4568DC, #B06AB3);
}
The problem here is that both div has content-box class; this class applies position: absolute; , which is the main cause of overlapping. Removing this css property you should be able to se both div.
Regarding date time span you could change the class .content-box .datetime { color: black; font-size: 18px; } (you have to remove the padding)
And add the following properties to .content-box class to display datetime correctly without padding:
display: flex;
flex-flow: column;
I have the following code in the body section of my HTML index file.
<div class="titleMessage">
<div class="heading">
<p class="main">NAME HERE</p>
<p class="sub">Software Engineer</p>
</div>
</div>
Below is my CSS code:
.titleMessage {
position: absolute;
width: 100%;
height: 250px;
top: 50%;
z-index: 5;
text-align: center;
margin-top: -125px;
}
.titleMessage .heading p{
color: #080808;
text-shadow: 0px 2px 5px rgba(0,0,0,0.4);
font-weight: 100;
letter-spacing: 7px;
background: #F5F5F5;
background-size: contain;
}
.titleMessage .heading .main{
font-size: 50px;
}
.titleMessage .heading .sub{
font-size: 23px;
}
Webpage:
The resulting webpage looks strange. Specifically, I want the background color on my text which is set to #F5F5F5 to not stretch across the entire screen.
In fact, I only want the size of the background rectangle behind text to be a little bigger than the size of the actual text.
How do I do this?
You can put span tags around those texts and apply the background only to that span (spans are inline elements, which is why they won't stretch across the available width). Additionally (as shown below) you can add some padding to have more control over how much the background will extend:
.titleMessage {
position: absolute;
width: 100%;
height: 250px;
top: 50%;
z-index: 5;
text-align: center;
margin-top: -125px;
}
.titleMessage .heading p{
color: #080808;
text-shadow: 0px 2px 5px rgba(0,0,0,0.4);
font-weight: 100;
letter-spacing: 7px;
}
.titleMessage .heading p span{
background: #F5F5F5;
padding: 6px 12px 0;
}
.titleMessage .heading .main{
font-size: 50px;
}
.titleMessage .heading .sub{
font-size: 23px;
}
<div class="titleMessage">
<div class="heading">
<p class="main"><span>NAME HERE</span></p>
<p class="sub"><span>Software Engineer</span></p>
</div>
</div>
I make some changes to your CSS :
.titleMessage {
margin-top:10rem;
display:flex;
align-items:center;
justify-content:center;
width: 100%;
z-index: 5;
}
.heading p{
color: #080808;
text-align:center;
text-shadow: 0px 2px 5px rgba(0,0,0,0.4);
font-weight: 100;
letter-spacing: 7px;
background: #F5F5F5;
}
.titleMessage .heading .main{
font-size: 50px;
}
.titleMessage .heading .sub{
font-size: 23px;
}
This question already has answers here:
Text in Border CSS HTML
(10 answers)
Closed 3 years ago.
im trying to turn a design into code with html and css, but im stumped at a part in the hero section. What's the best way to position this logo with the border that stops around it.
attached is an image of the design i am trying to re-create
you can use before and after classes as
::before and ::after then add border and position it on the top of the corner left and right.
*{
margin: 0; padding: 0; box-sizing: border-box;
}
body{
font-family: Arial , Helvetica;
}
.banner-container{
min-height: 600px; height: 100vh; background-image: linear-gradient(to bottom, rgba(60, 53, 39, 0.6), rgba(60, 53, 39, 0.7)), url("https://images.pexels.com/photos/2015972/pexels-photo-2015972.jpeg?cs=srgb&dl=affection-baby-child-2015972.jpg&fm=jpg"); background-position: center; background-size: cover; background-repeat: no-repeat;
}
.banner-wrap{
margin: 0 auto; max-width: 960px; height: 100%; display: flex; align-items: center; justify-content: center;
}
.banner-box{
border-bottom: solid #A58758 4px; border-left: solid #A58758 4px; border-right: solid #A58758 4px; width: 500px; display: flex; flex-direction: column; align-items: center; position: relative; padding: 50px; margin-top: 100px;
}
.banner-box::before{
content: "";
width: 127px;
border: solid #A58758 2px;
position: absolute;
top: -4px;
left: -4px;
}
.banner-box::after{
content: "";
width: 127px;
border: solid #A58758 2px;
position: absolute;
top: -4px;
right: -4px;
}
.banner-box img{
position: absolute; top: -135px; padding: 5px;
}
.banner-box h2{
color: #fff; font-size: 2.5rem;
}
.banner-box h1{
color: #fff; margin: 5px 0; text-transform: uppercase; font-weight: 400; font-size: 3.8rem; letter-spacing: .4rem;
}
.banner-box h3{
color: #A58758; text-transform: uppercase; font-size: 2.3rem; font-weight: 400; letter-spacing: .6rem;
}
a{
background: #A58758; color: #fff; text-decoration: none; text-transform: uppercase; padding: 15px 25px; position: absolute; bottom: -25px; letter-spacing: .1rem;
}
<div class="banner-container">
<div class="banner-wrap">
<div class="banner-box">
<img src="https://www.thorndalemanors.com/wp-content/uploads/2019/01/thorndale-footer.svg">
<h2>Refined Luxury</h2>
<h1>Singles</h1>
<h3>In Brampton</h3>
Learn More
</div>
</div>
</div>
check its working properly
This is what I would do:
Wrapper element (.box-border) with two children: .box-border__top & .box-border__img
Put a border on .box-border but no top border
For the top border, use .box-border__top consisting of three elements:
.box-border__top:before: a line
.box-border__img: the logo, aligned in the center
.box-border__top:after: a line
To add spacing around the image, use .box-border__content with padding: 5em
body {
background: url(https://www.goodfreephotos.com/albums/vector-images/farm-landscape-illustration-vector-graphics.png);
background-size: cover;
}
.box-border { /* All side borders by the top */
border: .5em solid brown;
border-top: 0;
text-align: center;
}
.box-border__top { /* Align the image & borders */
display: flex;
}
.box-border__top:before,
.box-border__top:after {
content: '';
display: block;
width: 100%;
border-top: .5em solid brown; /* Sections of the top image */
}
.box-border__img { /* Center Image */
transform: translateY(-50%);
margin: 0 0 -99%;
}
/* Add some padding on the bottom */
.box-border__content { padding: 5em; }
<div class="box-border">
<div class="box-border__top">
<img class="box-border__img" src="https://upload.wikimedia.org/wikipedia/commons/6/66/Android_robot.png" width="100" height="90" />
</div>
<div class="box-border__content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Robogarden_img.png/800px-Robogarden_img.png" width="300" />
</div>
</div>
EDITED JSFIDDLE
The goal to display a transition upward height when the button is hovered, but this line of CSS .btn-position:hover ~ .bg-transit { height: 430px !important;} seems it expands downwards instead upward. Is there a way to transition UPWARD?
I dont want to add any JS to it.
HTML
<div class="career-wrapper-positions">
<div class="section-positions">
<div class="position-wrap">
<div class="position-box" id="video_interpreter">
<div class="employees"><img src="http://staging.svrs.com/assets/images/careers2018/position-lady1-1.png" alt="SVRS | Video Interpreter positions"></div>
<div class="position-tited-top-bg"></div>
<div class="position-box-info">
<div class="position-header"><h5 class="h5-careers18">CUSTOMER SERVICES</h5></div>
<div class="position-subheader" id="subheader1">positions</div>
<div class="position-p">Individually, passionate about the work. Collectively, the largest sales workforce in the world.</div>
<div class="btn-position">
<button onclick="location.href='#'" class="position-btn" id="btn1-position">Apply now</button></div>
<div class="bg-transit"></div>
</div>
</div>
</div>
</div>
CSS
.section-positions { margin: 0 auto; width: 100%; }
.position-header { text-align: center; }
.position-header p { margin-top: 0; }
.position-wrap { height: 525px; position: absolute; z-index: 10; width: 100%; text-align: center; display: flex; margin-top: 175px; }
.position-box { width: 209px !important; height: 330px; display: block; margin: 20px; background-color: #231f20; z-index: 2;}
.position-tited-top-bg { width: 209px !important; height: 20px; background-color: #231f20; -webkit-transform: skew(0deg, 2deg); transform: skew(0deg, 2deg); margin-top: -15px; position: relative;z-index: -2; }
.position-header { height: 15px;color:#ffbb11; font-size: 22px; font-family:'Source Sans Pro', sans-serif; font-weight: 400; }
.position-subheader { color: #ffbb11; margin-top: 10px; font-family:'Source Sans Pro', sans-serif;}
.position-p { color: #fff; padding: 0 10px 0 10px; font-family:'Source Sans Pro', sans-serif; font-size: 14px; margin-top: 10px; line-height: 20px; }
.position-btn { background-color: #ffbb11; width: 150px; height: 41px; border: none; border-radius: 8px; font-size: 1em; font-weight: 600; cursor: pointer; margin-top: 50px; }
.position-box-info { padding-top: 10px; }
/* this is the button to trigger a new height size transition of the background box */
.bg-transit { width: 209px !important; height: 338px; display: block; background-color: #ff0000; z-index: -1; position: relative; top: -280px; transition-property: height; transition-duration: 0.5s;}
.btn-position:hover ~ .bg-transit { height: 430px !important;}
.position-btn:hover { background-color: #231f20 !important; color: #ffbb11 !important; border: #9c7002 solid 1px; }
.employees { position: absolute; margin-top: -210px; width: 207px; margin-left: 5px; z-index: 9999;}
.position-btn:hover ~ .position-box-info selects all siblings .position-box-info that come after a .position-btn:hover. Since .position-box-info is actually the parent of the .position-btn element, nothing gets selected. In fact, you can't select a parent from a child, so you either have to add a class with javascript or change your HTML.
Also, you seem to miss a </div> closing tag.