I want to enter a title, a line and a subtitle in the center of an image (horizontally and vertically), in this order from top to bottom, with the line between the two texts, but they keep overlapping. I've tried some answers from other questions, such as changing from div to span and setting display:block in the outter div and display:inline-block in the inner divs, for example, but nothing works.
With flexbox, I ran into the issue of needing to name all of their classes the same for it to work, which is not viable because they have different properties.
Appreciate the help!
Here's the code and the fiddle:
https://jsfiddle.net/u8asjmy7/
HTML
<div class="banner">
<div class="titulo-banner"><b>BIG TITLE</b></div>
<div class="linha-banner"></div>
<div class="texto-banner"><b>Small<br>subtitle.</b></div>
</div>
CSS
body, html {
height: 100%;
margin: 0;
}
.banner {
background-image: linear-gradient(to bottom, rgba(245, 246, 252, 0.1), rgba(20, 20, 20, 0.90)), url('../images/cp/brian-lundquist.png');
object-fit: cover;
height: 100%;
width: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
text-align: center;
color: white;
}
.titulo-banner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: Martel;
font-size: calc(15px + 2vw);
}
.linha-banner {
height: 4px;
width: 15vw;
background: #ffc700;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.texto-banner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: Martel;
font-size: calc(15px + 0.5vw);
}
Hmm, I think you could still use flexbox without having to name all the existing classes, does this accomplish what you need?
body,
html {
height: 100%;
margin: 0;
}
.banner {
background-image: linear-gradient(to bottom, rgba(245, 246, 252, 0.1), rgba(20, 20, 20, 0.90)), url('../images/cp/brian-lundquist.png');
object-fit: cover;
height: 100%;
width: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
text-align: center;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.titulo-banner {
font-family: Martel;
font-size: calc(15px + 2vw);
}
.linha-banner {
height: 4px;
width: 15vw;
background: #ffc700;
}
.texto-banner {
font-family: Martel;
font-size: calc(15px + 0.5vw);
}
<div class="banner">
<div class="titulo-banner"><b>BIG TITLE</b></div>
<div class="linha-banner"></div>
<div class="texto-banner"><b>Small<br>subtitle.</b></div>
</div>
If you must use position: absolute, you should do it only on the container of those texts. Let me know if you need a better solution
Related
.c{
display: flex;
padding-top: 18em;
.backgroundDiv{
background: url("/images/DSC8253.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center center ;
height: 20em;
opacity: 0.6;
position: absolute;
width: 100%;
z-index: -1;
}
}
.bigText{
display: flex;
text-transform: uppercase;
font-size: 3em;
font-family: cursive;
font-weight: 600;
height: 8em;
top:2em;
}
<section class="c">
<div class="backgroundDiv"></div>
<div class="bigText">
<p>Pilki-HUILKI</p>
</div>
</section>
Here in css file you type like below ( just small change )
.c {
display: flex;
position: relative;
height: 100vh;
}
.backgroundDiv {
background: url('/images/DSC8253.png');
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
height: 20em;
opacity: 0.6;
position: absolute;
width: 100%;
z-index: -1;
}
.bigText {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
text-transform: uppercase;
font-size: 3em;
font-family: cursive;
font-weight: 600;
}
I use position absolute to make the text over the background then i use transform to make it to the center
After ~2 hours of researching I couldn't find a solution for my problem, I am trying to inherit the center of the background since the "blurred-box" gets bigger depending on the computer resolution.
It looks like this(laptop resolution):
And I would like to make it show the center of the background image instead of the corner.
* {
margin: 0;
padding: 0;
}
html {
width: 100vw;
height: 100vh;
}
body {
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-position: top;
background-image: url(https://images.unsplash.com/photo-1477346611705-65d1883cee1e?dpr=0.800000011920929&auto=format&fit=crop&w=1199&h=800&q=80&cs=tinysrgb&crop=);
width: 100%;
height: 100%;
font-family: Arial, Helvetica;
letter-spacing: 0.02em;
font-weight: 400;
-webkit-font-smoothing: antialiased;
}
.blurred-box {
position: fixed;
width: 550px;
height: 670px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: inherit;
border-radius: 2px;
overflow: hidden;
}
.blurred-box:after {
content: '';
width: 1000px;
height: 1000px;
background: inherit;
position: absolute;
bottom: 0;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
}
.user-login-box {
position: relative;
margin-top: 50px;
text-align: center;
z-index: 1;
}
.user-login-box>* {
display: inline-block;
}
<div class="blurred-box">
<div class="user-login-box">
<h1>text here</h1>
</div>
</div>
If someone posts a solution I would like to have a link for documentation with those informations(if that is okay), thanks.
You are almost good, remove the use of translate() which is creating the issue and center your element using margin:auto instead:
body {
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-position: top;
background-image: url(https://images.unsplash.com/photo-1477346611705-65d1883cee1e?dpr=0.800000011920929&auto=format&fit=crop&w=1199&h=800&q=80&cs=tinysrgb&crop=);
margin:0;
height: 100vh;
font-family: Arial, Helvetica;
letter-spacing: 0.02em;
font-weight: 400;
-webkit-font-smoothing: antialiased;
}
.blurred-box {
position: fixed;
width: 550px;
height: 670px;
top: 0;
left: 0;
bottom:0;
right:0;
margin:auto;
background: inherit;
border-radius: 2px;
overflow: hidden;
}
.blurred-box:after {
content: '';
width: 1000px;
height: 1000px;
background: inherit;
position: absolute;
bottom: 0;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
filter: blur(10px);
}
.user-login-box {
position: relative;
margin-top: 50px;
text-align: center;
z-index: 1;
}
.user-login-box>* {
display: inline-block;
}
<div class="blurred-box">
<div class="user-login-box">
<h1>text here</h1>
</div>
</div>
I wanted to put a background image inside the div "pageIntro". I've tried setting the background color to transparent, checked the image file path numerous times (it is certainly correct as when I click it in my code using vsCode it pops the correct image).
Note: putting a background color works fine
screensnip of the div with NO background color. Background-image is set to '/img/home/flower-cup.jpg'.
screensnip of the div with GOLD background color. Background-image is still set to '/img/home/flower-cup.jpg'.
Here's the CSS of the div and all the elements inside it:
div.pageIntro {
position: relative;
background-image: url('/img/home/flower-cup.jpg') ;
background-repeat: no-repeat;
background-size: cover;
max-width: 100%;
width: 100vw;
height: 100vh;
z-index: 001;
text-align: center;
}
.introDiv {
background-color: black;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 002;
}
.introText {
font-weight: bold;
font-family: "eczar";
color: whitesmoke;
font-size: 50px;
z-index: 002;
}
.subIntroButton {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color:rgba(0, 0, 0, 0.1);
width: 150px;
border-style: solid;
border-radius: 5%;
border-color: whitesmoke;
border-width: 2px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-align: center;
color: whitesmoke;
padding: 10px 10px;
}
Here's the HTML:
<div class='pageIntro'>
<div class="introDiv">
<p class='introText'> You deserve it. </p>
<a href="menu.html" style="text-decoration : none">
<div class='subIntroButton'> check treats </div>
</a>
</div>
<span class="blinking" href="javascript:"><img src="img/arrow-down.png" style="position: relative; bottom: 12%; width: 40px"></span></div>
</div>
Thank you very much :)
UPDATE:
Here's what it looks like when putting the background-image on BOTH inner and outer div. Unfortunately, it only works on the inner.
Issue is with your Image Relative Path i just tried you code with an online image path its working fine.
div.pageIntro {
position: relative;
background-image: url('https://images.pexels.com/photos/531880/pexels-photo-531880.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500') ;
background-repeat: no-repeat;
background-size: cover;
max-width: 100%;
width: 100vw;
height: 100vh;
z-index: 001;
text-align: center;
}
.introDiv {
background-color: black;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 002;
}
.introText {
font-weight: bold;
font-family: "eczar";
color: whitesmoke;
font-size: 50px;
z-index: 002;
}
.subIntroButton {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color:rgba(0, 0, 0, 0.1);
width: 150px;
border-style: solid;
border-radius: 5%;
border-color: whitesmoke;
border-width: 2px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-align: center;
color: whitesmoke;
padding: 10px 10px;
}
<div class='pageIntro'>
<div class="introDiv">
<p class='introText'> You deserve it. </p>
<a href="menu.html" style="text-decoration : none">
<div class='subIntroButton'> check treats </div>
</a>
</div>
<span class="blinking" href="javascript:"><img src="img/arrow-down.png" style="position: relative; bottom: 12%; width: 40px"></span></div>
</div>
Hi As I can see your relative path.
if the image forlder is in same path of your html
What i can see error in your HTML. Which is span is not properly closed with a and img tag.
<div class='pageIntro'>
<div class="introDiv">
<p class='introText'> You deserve it. </p>
<a href="menu.html" style="text-decoration : none">
<div class='subIntroButton'> check treats </div>
</a>
</div>
<span class="blinking" href="javascript:"><img src="img/arrow-down.png" style="position: relative; bottom: 12%; width: 40px"/></span>
</div>
you can use .
div.pageIntro {
position: relative;
background-image: url('./img/home/flower-cup.jpg') ;
background-repeat: no-repeat;
background-size: cover;
max-width: 100%;
width: 100vw;
height: 100vh;
z-index: 001;
text-align: center;
}
Or if its one above your path you can use ..
div.pageIntro {
position: relative;
background-image: url('../img/home/flower-cup.jpg') ;
background-repeat: no-repeat;
background-size: cover;
max-width: 100%;
width: 100vw;
height: 100vh;
z-index: 001;
text-align: center;
}
I have created one JS fiddle
I'm having problem with making the button appear on the center of screen. The button is supposed to be in the center of the screen, but somehow my css is making in that the center of the button is at the left top corner. Any one know why?
Some more details:
I want it to be like this:
how it should look
But instead it looks like this:
how it looks
Anyone can help?
Here is the code:
html, body {margin: 0; height: 100%; overflow: hidden}
img
{
max-width: 100%;
height: auto;
position: relative;
top: 33%;
}
.obj1
{
width: 20%;
height: 100%;
background: rgb(136, 44, 44);
float:left;
position: relative;
}
.obj2
{
width: 20%;
height: 100%;
background: rgb(255, 255, 255);
position: relative;
float:left;
}
.obj3
{
width: 20%;
height: 100%;
background: rgb(0, 0, 0);
position: relative;
float:left;
}
.obj4
{
width: 20%;
height: 100%;
background: rgb(42, 75, 148);
position: relative;
float:left;
}
.obj5
{
width: 20%;
height: 100%;
background: rgb(72, 114, 48);
position: relative;
float:left;
}
.obj6
{
width: 20%;
height: 100%;
background: rgb(119, 39, 112);
position: relative;
float:left;
}
#show-more
{
background: #1594e5;
color: #fff;
font-family: calibri;
display: block;
width: 140px;
font-size: 24px;
text-transform: uppercase;
padding: 10px;
text-align: center;
margin: 20px auto;
cursor: pointer;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
}
<body>
<div class="obj1">
</div>
<div class="obj2">
</div>
<div class="obj3"></div>
<div class="obj4"></div>
<div class="obj5"></div>
<a id="show-more">Show More</a>
</body>
Using position absolute and top/left you point to a top-left corner of the element.
Additionally use transform: translate(-50%, -50%); to move the button to top and left of 50% of his height/width
Am sure that I am doing something stupid, but cannot figure out how to get the contents of a DIV to fully render in front of another DIV that has a masked background.
See sample here: https://jsfiddle.net/pLwbsqjv/
What I am trying to do is to get the circle to fully display in front of the green circle that is a masked background.
The only constraint is that the circle with the number in it cannot be positioned absolutely as needs to have its width / height set on a % basis, eg: percentage of the outer container.
Anyone tell me what I am doing wrong?!
Thanks
body {
background: #252526;
}
.ontop {
margin: -50% 0 0 0;
border-radius: 50%;
width: 22%;
height: 22%;
padding: 10px;
background: rgb(34, 51, 68, .5);
border: 2px solid #def;
color: #def;
text-align: center;
font: 30px Arial, sans-serif;
}
.bounds {
width: 200px;
height: 200px;
}
.color-circle {
-webkit-mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
background-color: #26bf75;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
.bottom {
height: 80%;
width: 100%;
}
<div id="bounds" class="bounds">
<div class="bottom">
<div class="color-circle"></div>
</div>
<div class="ontop">01</div>
</div>
You can add position: relative and z-index to .ontop:
body {
margin: 0;
background: #252526;
}
.ontop {
position: relative;
z-index: 1;
margin: -50% 0 0 0;
border-radius: 50%;
width: 22%;
height: 22%;
padding: 10px;
background: rgb(34, 51, 68, .5);
border: 2px solid #def;
color: #def;
text-align: center;
font: 30px Arial, sans-serif;
}
.bounds {
width: 200px;
height: 200px;
}
.color-circle {
-webkit-mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
background-color: #26bf75;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
.bottom {
height: 80%;
width: 100%;
}
<div id="bounds" class="bounds">
<div class="bottom">
<div class="color-circle"></div>
</div>
<div class="ontop">01</div>
</div>
Note:
Regarding this comment:
The only constraint is that the circle with the number in it cannot be
positioned absolutely as needs to have its width / height set on a %
basis, eg: percentage of the outer container.
Position absolute would have worked as well. You need to designate the container for the absolutely positioned element. To do so, the container must have any position that is not static. In this example I've added position relative to .bounds:
body {
margin: 0;
background: #252526;
}
.ontop {
position: absolute;
z-index: 1;
margin: -50% 0 0 0;
border-radius: 50%;
width: 22%;
height: 22%;
padding: 10px;
background: rgb(34, 51, 68, .5);
border: 2px solid #def;
color: #def;
text-align: center;
font: 30px Arial, sans-serif;
}
.bounds {
position: relative; /** this sets the container **/
width: 200px;
height: 200px;
}
.color-circle {
-webkit-mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
background-color: #26bf75;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
.bottom {
height: 80%;
width: 100%;
}
<div id="bounds" class="bounds">
<div class="bottom">
<div class="color-circle"></div>
</div>
<div class="ontop">01</div>
</div>