I have this fiddle and what I am trying to do is place the line directly to the left and right of the h1's and scale respectively during a resize of window. So it should look like this.
----This that this
Here we go-----
I have attached the fiddle. I have tried floating the div left and making it absolute but I'm having no luck. I have only left one div which is a red bar and removed the other one. Once I learn to do one I can do the other one. Any help is appreciated.
HTML
<h1 class="mainPageTopText">
Find this that this.
<div class="banner-bottom"></div>
</h1>
<h1 class="mainPageBottomText">
Here we go.
</h1>
</div>
</div>
CSS
.mainPageWriting {
display: flex;
}
.mainPageTopText {
width: 500px;
position: absolute;
margin-right: 400px;
margin-top: 50px;
z-index: 12;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
.banner-bottom {
height: 10px;
width: 100%;
left: 0;
position: absolute;
background-color: red;
z-index: 100;
}
.mainPageBottomText {
position: absolute;
margin-top: 100px;
padding-left: 100px;
z-index: 12;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
.centered {
background: #1D2731;
display: flex;
align-items: left;
justify-content: center;
height: 100%;
}
.banner-bottom {
height: 10px;
width: 100%;
left: 0;
position: absolute;
background-color: red;
z-index: 100;
}
Fiddle
https://jsfiddle.net/angatvir/aujrkpLk/183/
I hope this is the answer you're looking for
based on
----This that this
Here we go-----
and not
----This that this Here we go-----
#special {
}
#first {
display: grid;
grid-template-columns: 1fr auto 1fr;
grid-template-areas: "line text .";
}
#first .line {
grid-area: line;
height: 5px;
align-self: center;
background: red;
}
#first .text {
grid-area: text;
}
#second {
display: grid;
grid-area: text-below;
grid-template-columns: 1fr auto 1fr;
grid-template-areas: ". text line";
}
#second .line {
grid-area: line;
height: 5px;
align-self: center;
background: green;
}
#second .text {
grid-area: text;
}
<h1 id="special">
<span id="first">
<span class="text">This that this</span>
<span class="line"></span>
</span>
<span id="second">
<span class="text">Here we go</span>
<span class="line"></span>
</span>
</h1>
Looks quite simple, you can use psudo elements for this.
.mainPageTopText::before,
.mainPageTopText::after {
content: '----';
display:inline;
}
<h1 class="mainPageTopText">
Find this that this.
Here we go.
</h1>
Use :before and :after and in content set the line you can also style it
.mainPageWriting {
display: flex;
}
.mainPageTopText {
width: 500px;
position: absolute;
margin-right: 400px;
margin-top: 50px;
z-index: 12;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
.mainPageTopText:before{
content:'----';
}
.mainPageBottomText {
position: absolute;
margin-top: 100px;
padding-left: 50px;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
.mainPageBottomText:after{
content:'-----';
}
.centered {
background: #1D2731;
display: flex;
align-items: left;
justify-content: center;
height: 100%;
}
.banner-bottom {
height: 10px;
width: 100%;
left: 0;
position: absolute;
background-color: red;
z-index: 100;
}
<div class="centered">
<div class="mainPageWriting">
<h1 class="mainPageTopText">
Find this that this.
</h1>
<h1 class="mainPageBottomText">
Here we go.
</h1>
</div>
</div>
Update your css and html like this
HTML
<div class="centered">
<div class="mainPageWriting">
<h1 class="mainPageTopText">
<div class="left-line"></div>
Find this that this.
</h1>
<h1 class="mainPageBottomText">
Here we go.
<div class="right-line"></div>
</h1>
</div>
</div>
css
.centered {
background: #1D2731;
display: flex;
align-items: left;
justify-content: center;
height: 100%;
}
.mainPageWriting{
padding:50px 100px;
}
.mainPageTopText {
width: auto;
position: relative;
/* margin-right: 400px; */
margin-top: 50px;
z-index: 12;
text-align: left;
margin: 0px;
font-family: 'Luxim';
padding-left: 50px;
padding-right: 50px;
background: rgba(255, 255, 255, 1.0);
color: black;
}
h1 .left-line {
content: "";
position: absolute;
width: 40px;
height: 2px;
background: #000;
top: 17px;
left: 0px;
}
.mainPageBottomText {
position: relative;
/* margin-top: 100px; */
/* padding-left: 100px; */
text-align: right;
z-index: 12;
margin: 0px;
padding-left: 50px;
padding-right: 50px;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
h1 .right-line {
content: "";
position: absolute;
width: 40px;
height: 2px;
background: #000;
top: 17px;
right: 0px;
}
Try This code Below added some styles. You can make use of the pseudo elements to give the lines. removed banner-bottom div.
.mainPageWriting {
display: flex;
}
.mainPageTopText {
width: 500px;
position: absolute;
margin-right: 400px;
margin-top: 50px;
z-index: 12;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
.mainPageBottomText {
position: absolute;
margin-top: 100px;
padding-left: 100px;
z-index: 12;
font-family: 'Luxim';
background: rgba(255, 255, 255, 1.0);
color: black;
}
/*** add these */
.mainPageTopText::before{
content:"";
position:absolute;
height:0;
border:1px dashed;
width:20%;
top:0;
bottom:0;
left:-25%;
margin:auto;
}
.mainPageBottomText::after{
content:"";
position:absolute;
height:0;
border:1px dashed;
width:20%;
top:0;
bottom:0;
right:-25%;
margin:auto;
}
/** add these **/
.centered {
background: #1D2731;
display: flex;
align-items: left;
justify-content: center;
height: 100%;
}
<div class="centered">
<div class="mainPageWriting">
<h1 class="mainPageTopText">
Find this that this.
</h1>
<h1 class="mainPageBottomText">
Here we go.
</h1>
</div>
</div>
Related
when the screen gets smaller on my website, the elements go to irrelevant places. I did some research and thought I could remove it using '%' but it didn't work.
This is 1 scale:
This is 0.25 scale
/*my container*/
.container-home{
width: 100%;
height: 60rem;
display: flex;
align-items: center;
}
/*
the articles are here*/
.words {
display: flex;
flex-direction: column;
justify-content: center;
width: 60%;
height: 100vh;
margin-left: 25vh;
transition: 1.5s;
}
.header{
font-size: 5rem;
font-weight: 500;
}
.description {
display: block;
margin-top: 3rem;
font-size: 2rem;
}
/*explore text span*/
.explore{
margin-top: 2.5rem;
width: 15rem;
height: 4rem;
text-align: center;
display: block;
font-size: 2rem;
border: 0.1rem solid #000;
border-radius: 2.5rem;
margin-left: 1.5rem;
position: relative;
z-index: 1;
}
/*explore text a*/
.explore a{
display: block;
text-decoration: none;
font-size: 2rem;
color: #000;
text-align: center;
margin-top: 0.7rem;
}
.explore:hover {
border-color: transparent;
text-align: center;
transition: 1s;
transform: translateY(0.6rem) translateX(-1rem);
}
/*colored rectangle under text explore*/
.explore-hover{
display: inline;
position: absolute;
width: 15rem;
height: 4rem;
border-radius: 2.5rem;
background-color: #f1e0d4;
top: 42rem;
}
/*circle , solid circle and image in this*/
.image-design{
width: 100%;
height:100vh;
}
.circle{
position: relative;
width: 100%;
height: 100%;
clip-path: circle(300px at center);
background-color: #d7e7f1;
margin-top:8rem;
}
.solid-circle{
position: absolute;
width: 60rem;
height: 60rem;
border-radius: 50%;
background-color: transparent;
top: 30%;
left: 28%;
border: 1px solid #3398d7;
}
/*I created it to put an image on top of the circles*/
.conainer-image-design{
position: absolute;
width: 100%;
left: 25rem;
height:100vh;
}
.image{
position: relative;
top: 25%;
left: 12%;
}
<div class="container-home">
<div class="words">
<span class="header">
Handcrafted<br>
& ethically sourced
</span>
<span class="description">A collection inspired by old-world charm, crafted
<br>with moisannites and diamonds.
</span>
<span class="explore">Explore→</span>
<div class="explore-hover"></div>
</div>
<div class="image-design">
<div class="conainer-image-design">
<div class="circle"></div>
<div class="solid-circle"></div>
</div>
<span class="image"><img src="./ring.png"></span>
</div>
</div>
what do you recommend to give the measurements, I mainly use rem or % .which is better to keep the image intact?
I have a border-radius: 20px on a parent container that is breaking the styles of the button child. Look at this jsfiddle:
https://jsfiddle.net/fku9cLoe/2/
Now try to remove the border-radius on the .preview-container, you will see that the border radius on the button is fixed and the corners are not overflowing anymore.
How is this possible? Looks almost like a bug in CSS.
Looks like it gets fixed when I remove the backdrop-filter: blur(10px); but that is not the solution because it's essential to the design of the button.
.preview-container {
width: 300px;
height: 300px;
display: flex;
justify-content: stretch;
position: relative;
max-width: 100%;
overflow: hidden;
background: black;
border-radius: 20px;
}
.preview {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
button {
position: relative;
font-family: inherit;
font-size: 18px;
border-radius: 40em;
width: 8em;
height: 3em;
z-index: 1;
color: white;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.18);
}
button .text {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
line-height: 3em;
border: none;
background: linear-gradient(rgba(255, 255, 255, 0.473), rgba(150, 150, 150, 0.25));
z-index: 1;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
button .blob {
position: absolute;
z-index: -1;
border-radius: 5em;
width: 5em;
height: 5em;
background: purple;
top: -20px;
left: -20px;
}
button .blob:nth-child(2) {
left: 20px;
top: 0;
width: 10em;
background: #ff930f;
}
<section class="preview-container">
<div class="preview">
<button> <span class="text">Button</span>
<span class="blob"></span>
<span class="blob"></span>
</button>
</div>
</section>
the issue is due to backdrop-filter: blur(10px) apply on button .text as say in the doc the effect is done below the element https://developer.mozilla.org/fr/docs/Web/CSS/backdrop-filter
so in your case the effect is done on button .text which have no border-radius and have a rectangle shape
to solve your issue apply the border-radius on button .text element to give it the same shape as his container
.preview-container {
width: 300px;
height: 300px;
display: flex;
justify-content: stretch;
position: relative;
max-width: 100%;
overflow: hidden;
background: black;
border-radius: 20px;
}
.preview {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
button {
position: relative;
font-family: inherit;
font-size: 18px;
border-radius: 40em;
width: 8em;
height: 3em;
z-index: 1;
color: white;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.18);
}
button .text {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
line-height: 3em;
border: none;
background: linear-gradient(rgba(255, 255, 255, 0.473), rgba(150, 150, 150, 0.25));
z-index: 1;
border-radius: 40em;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
button .blob {
position: absolute;
z-index: -1;
border-radius: 5em;
width: 5em;
height: 5em;
background: purple;
top: -20px;
left: -20px;
}
button .blob:nth-child(2) {
left: 20px;
top: 0;
width: 10em;
background: #ff930f;
}
<section class="preview-container">
<div class="preview">
<button> <span class="text">Button</span>
<span class="blob"></span>
<span class="blob"></span>
</button>
</div>
</section>
I have three 50x50 colored blocks with content R, G, and B. Can these blocks be lined up vertically as would be expected if they were three div elements adjacent to each other?
It is possible if using a margin-bottom that is the same height of the red block but only if the red block does not contain any text. This is because the height of the text gets added to the height of the margin.
Is there a way to make this work with just .red, .red::after, and .blue?
body {
width: 100%;
height: 80vh;
display: flex;
align-items: center;
justify-content: center;
}
.demo-container {
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
border: solid 1px #d5d9dc;
}
.red {
background: pink;
display: block;
min-width: 50px;
height: 50px;
position: relative;
}
.red::after {
content: "G";
background-color: rgba(64, 255, 64, 0.5);
display: block;
min-width: 50px;
height: 50px;
position: relative;
}
.blue {
background-color: rgba(64, 64, 255, 0.5);
display: block;
min-width: 50px;
height: 50px;
position: relative;
}
<!DOCTYPE html>
<div class="demo-container">
<div class="container">
<div class="red">R</div>
<div class="blue">B</div>
</div>
<br/>
</div>
You can add position: relative;height: 100px to .red element.
then add: position: absolute; bottom: 0; to .red:after element
body {
width: 100%;
height: 80vh;
display: flex;
align-items: center;
justify-content: center;
}
.demo-container {
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
border: solid 1px #d5d9dc;
}
.red {
background: pink;
display: block;
min-width: 50px;
height: 100px;
position: relative;
}
.red::after {
content: "G";
background-color: rgba(64, 255, 64, 0.5);
display: block;
min-width: 50px;
height: 50px;
position: absolute;
bottom: 0
}
.blue {
background-color: rgba(64, 64, 255, 0.5);
display: block;
min-width: 50px;
height: 50px;
position: relative;
}
<!DOCTYPE html>
<div class="demo-container">
<div class="container">
<div class="red">R</div>
<div class="blue">B</div>
</div>
<br/>
</div>
Please run the example below. I'm trying to stretch the left line further to the left to compensate the parent's padding as you can see in the second example, while keeping the title centered relative to the parent like in the first example. I can't seem to have both.
(For anyone who's familiar, the divider I'm trying to tweak comes from ant-design)
#container {
height: 100px;
width: 400px;
background: #EFEFEF;
padding: 24px;
}
/* Normal use case */
.divider {
position: relative;
line-height: 23px;
height: 1px;
display: table;
margin: 16px 0;
color: rgba(0, 0, 0, 0.85);
font-weight: 500;
font-size: 15px;
white-space: nowrap;
text-align: center;
background: transparent;
}
.divider::before, .divider::after {
position: relative;
top: 50%;
display: table-cell;
width: 50%;
border-top: 1px solid #AAA;
-webkit-transform: translateY(50%);
-ms-transform: translateY(50%);
transform: translateY(50%);
content: '';
}
.divider-text {
display: inline-block;
padding: 0 24px;
}
/* Trying to stretch the left line to further to the left without puting the title off-center */
.divider.stretched-left {
left: -24px;
width: calc(100% + 24px);
min-width: calc(100% + 24px);
}
<div id="container">
<div class="divider">
<span class="divider-text">Title</span>
</div>
<div class="divider stretched-left">
<span class="divider-text">Title</span>
</div>
</div>
First, I would use flexbox instead of table layout then adjust the margin/padding:
Kept only the relevant code for the demo
#container {
width: 400px;
background: #EFEFEF;
padding: 24px;
}
/* Normal use case */
.divider {
display: flex;
margin: 16px 0;
align-items:center;
}
.divider::before, .divider::after {
flex:1;
height: 1px;
background:#AAA;
content: '';
}
.divider::before {
margin-right:24px;
}
.divider::after {
margin-left:24px;
}
.divider.stretched-left:before {
margin-left:-24px;
padding-left: 24px;
}
.divider.stretched-right:after {
margin-right:-24px;
padding-right: 24px;
}
<div id="container">
<div class="divider">
<span class="divider-text">Title</span>
</div>
<div class="divider stretched-left">
<span class="divider-text">another Title</span>
</div>
<div class="divider stretched-right">
<span class="divider-text">Title</span>
</div>
<div class="divider stretched-right">
<span class="divider-text">another Title</span>
</div>
<div class="divider stretched-left stretched-right">
<span class="divider-text">another Title</span>
</div>
</div>
With your original code you can try this:
#container {
height: 100px;
width: 400px;
background: #EFEFEF;
padding: 24px;
}
/* Normal use case */
.divider {
position: relative;
line-height: 23px;
height: 1px;
display: table;
margin: 16px 0;
color: rgba(0, 0, 0, 0.85);
font-weight: 500;
font-size: 15px;
white-space: nowrap;
text-align: center;
background: transparent;
}
.divider::before, .divider::after {
position: relative;
top: 50%;
display: table-cell;
width: 50%;
border-top: 1px solid #AAA;
transform: translateY(50%);
content: '';
}
.divider-text {
display: inline-block;
padding: 0 24px;
}
/* Trying to stretch the left line to further to the left without puting the title off-center */
.divider.stretched-left {
left: -24px;
width: calc(100% + 48px); /* Updated */
}
/* Added */
.divider.stretched-left:after {
border-image:linear-gradient(to left,transparent 24px, #aaa 24px) 1;
}
<div id="container">
<div class="divider">
<span class="divider-text">Title</span>
</div>
<div class="divider stretched-left">
<span class="divider-text">Title</span>
</div>
</div>
#container {
height: 100px;
width: 400px;
background: #EFEFEF;
padding: 24px;
}
.divider {
position: relative;
line-height: 23px;
height: 1px;
display: table;
margin: 16px 0;
color: rgba(0, 0, 0, 0.85);
font-weight: 500;
font-size: 15px;
white-space: nowrap;
text-align: center;
background: transparent;
width: 100%; /* SOLUTION – this is new */
}
.divider::before, .divider::after {
position: absolute; /* SOLUTION – this has changed */
top: 50%;
display: table-cell;
width: 41%; /* SOLUTION – changed, matches desired layout best */
border-top: 1px solid #AAA;
-webkit-transform: translateY(50%);
-ms-transform: translateY(50%);
transform: translateY(50%);
content: '';
}
.divider::before{
left: -24px; /* SOLUTION – compensate #container padding */
width: calc( 41% + 24px ); /* SOLUTION – add the offset to the width */
}
.divider::after{
right: 0px; /* SOLUTION */
}
.divider-text {
display: inline-block;
padding: 0 24px;
}
<div id="container">
<div class="divider">
<span class="divider-text">Title</span>
</div>
</div>
.divider.stretched-left {
left: -24px;
width: calc(100% + 48px);
min-width: calc(100% + 48px);
}
Just You have to replace last css lines code with above given code.
Solution with minimum CSS, without flex, without transform.
.divider {
position: relative;
text-align:center;
}
.divider:before {
content:'';
position: absolute;
top:50%;
height: 1px;
width: 100%;
background: #000;
left: 0;
z-index: -1;
}
.divider span{
padding: 0 24px;
z-index: 1;
background: #fff;
display: inline-block;
}
<div class="divider">
<span>Title</span>
</div>
I'm trying to code this card design:
However, I need some help with the positioning and z-index. This is how far I've come:
.card {
width: 450px;
height: 400px;
background: lightblue;
}
.card-hover-state {
position: relative;
width: 100%;
height: 100%;
background-image: linear-gradient(-180deg, #000000 0%, rgba(216,216,216,0.00) 100%);
opacity: 0.6;
}
.card-hover-state-title {
font-size: 15px;
color: #FFFFFF;
max-width: 60%;
}
.card-hover-state-button {
font-size: 11px;
color: #FFFFFF;
}
<div class="card">
<div class="card-hover-state"></div>
<div class="information-container">
<div class="card-hover-state-title">Brace yourself - A fancy Lorem Ipsum Title is comming</div>
<div class="card-hover-state-button">READ MORE</div>
</div>
</div>
However, the text isn't showing. What am I missing?
Use position: relative on .card, then you actually don't need .card-hover-state - you can use a pseudo element instead. Whichever of those you use, you need to add position: absolute; top: 0; left: 0; to position it over the .card background.
Then I would make .information-center a flex parent and use justify-content: space-between to separate its children, and align-items: center to center them vertically, and add position: relative so it will have a position that puts it on top of the absolutely positioned pseudo element (or .card-hover-state) that comes before it.
.card {
width: 450px;
height: 400px;
background: lightblue;
position: relative;
}
.card::before {
content: '';
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(
-180deg,
#000000 0%,
rgba(216, 216, 216, 0.00) 100%
);
opacity: 0.6;
}
.information-container {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
color: #fff;
}
.card-hover-state-title {
font-size: 15px;
max-width: 60%;
}
.card-hover-state-button {
font-size: 11px;
}
<div class="card">
<div class="information-container">
<div class="card-hover-state-title">Brace yourself - A fancy Lorem Ipsum Title is comming</div>
<div class="card-hover-state-button">READ MORE</div>
</div>
</div>
You can get it by using below approach.
I just added display:table to your .information-container and assigned width:100% to take full parent div width, after that I assigned .card-hover-state-title and .card-hover-state-button
to position:relative so they don't use the parent div's opacity:0.6 and also added display:table-cell and width to get inline both.
I added CSS properties in the following classes:
.information-container {
display: table;
width: 100%;
padding: 20px;
box-sizing: border-box;
}
.card-hover-state-title {
font-size: 15px;
color: #FFFFFF;
width: 50%;
position: relative;
display: table-cell;
}
.card-hover-state-button {
font-size: 11px;
color: #FFFFFF;
position: relative;
display: table-cell;
text-align: right;
vertical-align:middle;
}
.card {
width: 450px;
height: 400px;
background: lightblue;
position: relative;
}
.card-hover-state {
position: absolute;
width: 100%;
height: 100%;
background-image: linear-gradient(-180deg, #000000 0%, rgba(216, 216, 216, 0.00) 100%);
opacity: 0.6;
}
.information-container {
display: table;
width: 100%;
padding: 20px;
box-sizing: border-box;
}
.card-hover-state-title {
font-size: 15px;
color: #FFFFFF;
width: 50%;
position: relative;
display: table-cell;
}
.card-hover-state-button {
font-size: 11px;
color: #FFFFFF;
position: relative;
display: table-cell;
text-align: right;
vertical-align:middle;
}
<div class="card">
<div class="card-hover-state"></div>
<div class="information-container">
<div class="card-hover-state-title">Brace yourself - A fancy Lorem Ipsum Title is comming</div>
<div class="card-hover-state-button">READ MORE</div>
</div>
</div>