Gradient and text over image - html

I am working currently on my website and wanted to ask best solution for this situation.
Biggest struggle is that I need to put gradient over img + text and arrow icon.
I tried 2 different ways:
I was able to put gradient over image using :after, but now I don't know how to put text over image and that left arrow to the right of image.
I used <figure> and <figcaption> I think this solution isn't the best, using negative margins to put text over image. But on this case I am not able to use :after solution.
I included photo — there you can see how it should look like. Also I am starting my coding career and if you notice bad practises please let me know!
figure {
display: inline-block;
margin: 15px 12px;
box-shadow: 0 20px 30px rgba(0, 0, 0, 0.2);
}
figcaption {
margin-top: -80px;
}
figcaption p {
margin-top: 0px;
margin-bottom: 0px;
padding-left: 44px;
text-align: left;
color: #ffffff;
font-family: "Proxima Nova";
font-size: 25px;
font-weight: 700;
line-height: 35px;
}
.cs-text {
margin-top: -10px;
color: #b9b8b8;
font-family: "Proxima Nova";
font-size: 12px;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
}
figcaption img {
position: relative;
float: right;
padding: 10px 35px 50px 0px;
}
.cs-item {
position: relative;
display: inline-block;
max-width: 430px;
max-height: 254px;
}
.cs-item:after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.11) 36%, rgba(0, 0, 0, 0) 46%);
}
<div class="case-study-items">
<div class="cs-item">
<img src="https://www.upload.ee/image/7272952/case-studies-item.png" alt="">
<p class="solgu">Melb Lashes</p><img src="https://www.upload.ee/image/7272954/left-arrow.png" /></p>
<p class="cs-text">Case-study</p>
</div>
<figure>
<img src="https://www.upload.ee/image/7272952/case-studies-item.png" alt="">
<figcaption>
<p>Melb Lashes<img src="https://www.upload.ee/image/7272954/left-arrow.png" /></p>
<p class="cs-text">Case-study</p>
</figcaption>
</div>

Welcome to StackOverflow. Be sure to search the site for answers, prior to asking a question. The question is actually two questions, and has been answered in other posts.
For gradients over images, see here.
By structuring the HTML properly, and simplifying the CSS, the texts and arrow image can float over the image and gradient, by being nested within the parent element that has the image and the gradient.
<div class="case-study-items">
<div class="cs-item"> <!-- image and gradient here -->
<p class="cs-title">Melb Lashes <span class="cs-left-arrow"></span></p>
<p class="cs-text">Case-study</p>
</div>
</div>
I've created a Codepen example to demonstrate.

You can try to assign cs-item class to Figure, and set figcaption with z-index:1 and position: relative
figure {
display: inline-block;
margin: 15px 12px;
box-shadow: 0 20px 30px rgba(0, 0, 0, 0.2);
}
figcaption {
margin-top: -80px;
position:relative;
z-index:2;
}
figcaption p {
margin-top: 0px;
margin-bottom: 0px;
padding-left: 44px;
text-align: left;
color: #ffffff;
font-family: "Proxima Nova";
font-size: 25px;
font-weight: 700;
line-height: 35px;
}
.cs-text {
margin-top: -10px;
color: #b9b8b8;
font-family: "Proxima Nova";
font-size: 12px;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
}
figcaption img {
position: relative;
float: right;
padding: 10px 35px 50px 0px;
}
.cs-item {
position: relative;
display: inline-block;
max-width: 430px;
max-height: 254px;
}
.cs-item:after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.11) 36%, rgba(0, 0, 0, 0) 46%);
}
<figure class="cs-item">
<img src="https://www.upload.ee/image/7272952/case-studies-item.png" alt="">
<figcaption>
<p>Melb Lashes<img src="https://www.upload.ee/image/7272954/left-arrow.png" /></p>
<p class="cs-text">Case-study</p>
</figcaption>
</figure>

Related

Two tone style background

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.

Overlapping Divs, need them to be vertical on top of each other

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;

How to align my div to the right side of container per element?

Hope your all well.
Is it possible to align my div to the right side within my container? I try using align functions but does not seem to work. is it possible?
Note, the alignment solution should be for div (chatline) and HTML code only, as i need another div to align (chatline) on the right or left etc. so please don't use CSS alignment on the hold container.
Any help would be grateful here. thanks Yummi
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: darkgrey;
font-size: 14px;
line-height: .3;
letter-spacing: .5px;
}
#chattext {
font-family: Arial;
color: grey;
font-size: 12px;
line-height: 1.1;
letter-spacing: .5px;
}
.chatbox {
position: absolute;
width: 400px;
padding: 15px;
padding-top: 5px;
border-radius: 0px 0px 30px 30px;
background-color: rgba(0, 0, 0, .4);
grid-template-columns: 500px;
display: grid;
}
.bubble {
position: absolute;
max-width: 200px;
padding: 15px;
padding-top: 10px;
border-radius: 0px 30px 30px 30px;
background-color: rgba(0, 0, 0, .3);
}
<div class="chatbox">
<div style="height:200px">
<p class="bubble" id="chattext">This should be right > please use htnl code on this div to align</p>
<p style="margin-top:70px;" class="bubble" id="chattext">stay left</p>
</div>
</div>
You can define new class and use it in every bubble you want it in right
.right_chat {
right:0;
}
another advice id prefer to use just for one element so in my code i change it to class and use it in html code
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: darkgrey;
font-size: 14px;
line-height: .3;
letter-spacing: .5px;
}
.chattext {
font-family: Arial;
color: grey;
font-size: 12px;
line-height: 1.1;
letter-spacing: .5px;
}
.right_chat {
right:0;
}
.chatbox {
position: absolute;
width: 400px;
padding: 15px;
padding-top: 5px;
border-radius: 0px 0px 30px 30px;
background-color:rgba(0, 0, 0, .4);
grid-template-columns: 500px;
display: grid;
}
.bubble {
position: absolute;
max-width:200px;
padding: 15px;
padding-top: 10px;
border-radius: 0px 30px 30px 30px;
background-color:rgba(0, 0, 0, .3);
}
<div class="chatbox">
<div style="height:200px"><p class="bubble chattext right_chat" id="">This should be right > please use htnl code on this div to align</p><p style="margin-top:70px;" class="bubble chattext">stay left</p></div>
</div>
Is this what you want?
I didn't change the default behavior of the bubble class. Since the bubble is position: absolute I created one extra class named right that you can add on each bubble you want to be aligned on the right.
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: darkgrey;
font-size: 14px;
line-height: .3;
letter-spacing: .5px;
}
#chattext {
font-family: Arial;
color: grey;
font-size: 12px;
line-height: 1.1;
letter-spacing: .5px;
}
.chatbox {
position: absolute;
width: 400px;
padding: 15px;
padding-top: 5px;
border-radius: 0px 0px 30px 30px;
background-color:rgba(0, 0, 0, .4);
grid-template-columns: 500px;
display: grid;
}
.bubble {
position: absolute;
max-width:200px;
padding: 15px;
padding-top: 10px;
border-radius: 0px 30px 30px 30px;
background-color:rgba(0, 0, 0, .3);
}
.message-wrapper .bubble.right {
right: 0;
}
<div class="chatbox">
<div class="message-wrapper" style="height:200px">
<p class="bubble right" id="chattext">This should be right > please use htnl code on this div to align</p>
<p style="margin-top:70px;" class="bubble" id="chattext">stay left</p>
</div>
</div>

How center the text between the limits of the picture

I'm doing a tool to help in a game. The original game looks like this:
I was able to do the elixir number on the purple drop on the top-left. The transparent label to show the Level. (still need to work with the right colors based in card rarity).
But cant make the label center on the bottom and if possible looks like inside the border instead of above the whole picture.
I was trying following this question CSS center text (horizontally and vertically) inside a div block but haven't be able to make it work.
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header-content {
position: absolute;
bottom: 0;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
/* width: 100%; */
line-height: 40px;
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>
There are a few things you need to take into consideration.
Centralising this element
To address your issue of centralising this element with a couple of methods:
Option 1.
You can make the entire span width 100% and center the text within it by adding this to #header-content:
width: 100%;
display: block;
text-align:center;
As shown here: https://codepen.io/anon/pen/RjmMjQ
Option 2.
You can remove the absolute positioning, use display:inline-block, and, adding text-align:center; on the parent element like so:
https://codepen.io/anon/pen/wPbmrQ
Option 3.
If the element is position:absolute; you can also use:
left: 50%;
transform: translateX(-50%);
Positioning the element relative to an image:
You also said you would like this element to be positioned inside the border. Because this border is set on the image itself, you will need to position your element so it is relative to the image.
To make sure everything lines up correctly with padding we need to set the following, otherwise padding & css borders are not included in any width you set.:
*{
box-sizing: border-box;
}
Then you need to get the exact position right for aligning you element with the image, these seem to work right:
width: 170px;
bottom: 18px;
left:50%;
transform: translateX(-50%);
border-radius: 0 0 12px 12px;
This is done for you here:
https://codepen.io/anon/pen/YEbMYB
First you need to make the image max-width:100% to avoid overflow, then simply adjust left/right/bottom values since your element is absolute position and add text-align:center :
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header img {
max-width:100%;
}
#header-content {
position: absolute;
bottom: 5px;
left:5px;
right:5px;
text-align:center;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
/* width: 100%; */
line-height: 40px;
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>
By using left:0; right:0; and appropirate margin value, you should be able to center it. You could also set the width of the #header-content and set margin:0 auto;, it would achieve the same effect.
I also fit the image inside parent and added a curve to the label, you can see everything commented in css.
Working snippet:
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header img {width:100%; /* sets image to fit parent */}
#header-content {
position: absolute;
bottom: 0;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
/* width: 100%; */
line-height: 40px;
right:0; left:0; /*center*/
margin:0 18px 24px 18px; /* set margin to appropriate values top right bottom left*/
border-bottom-left-radius:13px; border-bottom-right-radius:13px; /* curved edges */
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>
Not too sure, but looks like you are just missing coordonates and text-align.
update example for #header-content:
bottom: 30px;
left:24px;
right:24px;
text-align:center;
and eventually
border-radius:0 0 10px 10px;
text-shadow:1px 1px white;
Demo below:
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(218, 21, 225);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header-content {
position: absolute;
bottom: 30px;
left:24px;
right:24px;
text-align:center;
border-radius:0 0 10px 10px;
text-shadow:2px 2px black, -1px -1px black;;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(218, 21, 225,0.5);
/* padding:10px;
width: 100%; */
line-height: 40px;
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>

How to vertically center div in fluid container?

I would like to be able to vertically center a div containing meta data such as Title and Author within a container that has a fluid width. In the example below, I would like the .meta div to be vertically centered within the article which is fluid width.
I tried following this article (http://css-tricks.com/centering-in-the-unknown/) but it doesn't work.
HTML
<div class="container">
<h3>Test</h3>
<article>
<div class="meta">
<div class="title"></div>
<div class="author"></div>
<img src="" />
</div>
</article>
</div>
CSS (using LESS)
.container {
h3 {
margin: -5px 0 0 0;
padding: 32px 0px 16px 0;
.freight-sans-pro;
font-size: 1.375em;
line-height: 1em;
font-weight: 200;
}
article {
max-height: 375px;
overflow: hidden;
position: relative;
z-index: 900;
margin-bottom: 2px;
background-color: #color-black;
line-height: 0em;
a {
max-height: 375px;
display: block;
img { opacity: .5; .opacity-transition; }
}
.meta {
width: 100%;
position: absolute;
bottom: 40%;
z-index: 500;
padding: 0px 10%;
color: #color-white;
font-size: 20px;
text-align: center;
.title {
margin: 0;
font-size: 2em;
line-height: 1em;
font-weight: 700;
text-shadow: 0px 2px 20px rgba(0, 0, 0, 0.7);
padding-bottom: 8px;
text-decoration: none;
display: block;
}
.author {
margin: 0;
font-size: .8em;
line-height: .75em;
font-style: italic;
text-transform: uppercase;
text-shadow: 0px 2px 20px rgba(0, 0, 0, 0.7);
text-decoration: none;
display: block;
}
}
}
}
Tried your Less but got an error in codepen.io so could not debug.
You could try something simple like this:
.container {
border: 2px solid blue;
width: 180px;
height: 120px;
overflow: hidden;
display: table-cell;
vertical-align: middle;
}
Check it working here
You might find this article useful as well: http://logconsole.com/vertical-align-center-image/
It's about vertically centring image, but in most cases you could just change image with a div.
Try this on what you want to be centered. I altered #domkoscielak's code so that it work.
.meta {
width: 180px;
height: 120px;
top: 50%;
margin-top: -60px; /*half of height*/
position: absolute;
}