I wanted to create an header in HTML but I made some mistakes and can't figure out how i do it the right way.
This is how I have tried to do it:
.xyz-logo {
float:left;
width:472px;
}
.headerlayout h1{
position:center;
font-family: Arial, Helvetica, sans-serif ;
font-size: x-large;
width:1920px;
height:200px;
background:lightgrey;
}
<div class="headerlayout">
<img class="xyz-logo" src="C:\Users\..." alt="Logo">
<h1 >This is the title</h1>
</div>
This is a picture of how it should look:
As Paul mentioned, you could use Flexbox or Grid to solve it, but if you want something simple that you can play with, here is a solution using absolute positioning.
just change the top, left, and bottom values to change its positioning. The transform in the title is so it is always centered.
.headerlayout{
position: relative;
width: 100%;
background-color: lightgrey;
height: 200px;
}
.xyz-logo {
position: absolute;
top: 0;
left: 0;
}
.headerlayout h1{
font-family: Arial, Helvetica, sans-serif;
font-size: 35px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -100%);
}
.something{
position:absolute;
bottom:0%;
left:0%;
}
<div class="headerlayout">
<img class="xyz-logo" src="C:\Users\..." alt="Logo">
<h1>This is the title</h1>
<div class="something">Something that changes</div>
</div >
enter link description here
Related
I would like to have headline text, similar to the way it is the image below, behind my headline text.
https://www.dropbox.com/s/f66x0txr37klbe0/example.png?dl=0
I thought potentially using a relative position on the first header would allow it but I don't see to be doing that correctly as nothing is appearing.
Can someone please help me with the code to achieve this effect?
Here is a working example using css an no z-index. Using the element creation order you can select which one is on top.
https://jsfiddle.net/s2aqxfr9/
<div>
<h1 class="h1-back">
World!
</h1>
<h1 class="h1-front">
Hello!
</h1>
</div>
Here is your CSS
div {
display:inline-block;
}
.h1-back {
position:absolute;
top:0;
left:0;
color:red;
opacity:0.5;
transform: rotate(-20deg);
}
.h1-front {
position:absolute;
top:0;
left:0;
color:blue;
}
way 1
<div class="main">
<img src="img.jpg">
<h1>Title</h1>
</div>
.main{
position:relative
}
.main img{
position:absolute;
z-index:1;
}
.main h1{
position:absolute;
z-index:2;
}
way 2:
<div class="main">
<h1>Title</h1>
</div>
.main{
background-image:url('path/to/img.jpg');
background-position:center;
background-repeat:no-repeat;
}
You have to position the second heading (or any other element) absolutely.
Positionthe top left corner in the middle, then fix the position with transform: translate():
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -40%) rotate(-12deg);
Don't forget that the element needs a parent with position: relative as a reference point.
.hero-section {
position:relative;
display: flex;
justify-content: center;
align-items: center;
min-height: 20vh;
background-color: rgba(0,0,0,0.1);
margin: 0 0 2rem 0;
padding: 1rem;
}
.another-hero-section {
position:relative
background-color: rgba(0,0,0,0.1);
margin: 0 0 1rem 0;
padding: 1rem;
}
.special-heading {
font-family: 'Amatic SC', cursive;
font-size: 5rem;
position: relative;
line-height: 1;
color: #333;
margin: 0;
}
.special-heading span {
font-family: 'Caveat Brush', cursive;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -40%) rotate(-12deg);
color: #127b9b;
text-shadow: 10px 12px 11px #000000cf;
font-size: 6rem;
}
.special-heading-foreground {
font-family: 'Caveat Brush', cursive;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(12deg);
color: #749b12;
text-shadow: 10px 12px 11px #000000cf;
font-size: 6rem;
margin: 0;
line-height 1;
}
<link href="https://fonts.googleapis.com/css?family=Amatic+SC|Caveat+Brush" rel="stylesheet">
<section class="hero-section">
<h1 class="special-heading">Well, interesting background <span>Foreground</span></h1>
</section>
<section class="hero-section">
<h1 class="special-heading">Another background</h1>
<h2 class="special-heading-foreground">Heading 2</h2>
</section>
I'm trying to put a rating text in front of an image. I did this via z-indexand position: absolute. However this text should always be on that position of the photo, now it has a static position. The text is a rating number of the title. And should be like this. How do I make this happen?
.rating{
color: white;
font-family: 'Abril Fatface', cursive;
font-size: 3.5rem;
z-index: 1;
margin-top: 5rem;
}
.rating-lant{
position: absolute;
right: 63rem;
top: 37rem;
}
.img-title-activity{
margin-left: 10rem;
z-index: 0;
}
<div class="container">
<p class="rating rating-lant">7.5</p>
<img src="./assets/img/Lantaarnopsteker-title#288x.png" alt="Lantaarnopsteker" width="584" height="264" class="img-title-activity">
</div>
Make a container div for the image and the heading text and set the position of the container div to relative. By setting giving margin top of 50%, it will bring it to the center of the image.
Here is an example I did for you
https://codepen.io/harsimarriar96/pen/WyOgVb
CSS
.image-with-text {
position: relative;
width: 800px;
}
h1 {
position: absolute;
text-align: center;
top: 50%;
width: 100%;
color: #000;
margin: 0 auto;
}
HTML
<div class="image-with-text">
<h1>Text on image</h1>
<img src="http://placehold.it/800x800" />
</div>
I want to display my page's title, "Math Achievement Tutoring", over a photograph of a hiker. My first attempt was to create this html:
<div id="wrapper">
<header>
<h1>Math Achivement Tutoring</h1>
</header>
<div id="hero">
<img src="http://michaelmossey.com/demo/home-hiker-grayish.jpg" alt="" width="500">
</div>
</div>
with this CSS, the idea being to position the h1 as absolute:
h1 {
text-align:center;
position: absolute;
color: #a04040;
}
but this means the title is no longer centered. I may run into other trouble as well if I start to fiddle with margin and padding.
h1 {
text-align:center;
position: absolute;
color: #a04040;
}
<div id="wrapper">
<header>
<h1>Math Achivement Tutoring</h1>
</header>
<div id="hero">
<img src="http://michaelmossey.com/demo/home-hiker-grayish.jpg" alt="" width="500">
</div>
</div>
What are my options for achieving this, and does it depend on where I want to take this website eventually? (like adding a navigation menu below the image)? Is there any simple demonstration code?
First, add position relative to #wrapper, then :
if you want it to be vertically & horizontally centered
h1 {
text-align:center;
position: absolute;
color: #a04040;
left: 50%;
top: 50%;
transform: translate( -50%, -50% );
}
if you want it to be vertically centered
h1 {
text-align:center;
position: absolute;
color: #a04040;
top: 50%;
transform: translateY( -50% );
}
if you want it to be horizontally centered
h1 {
text-align:center;
position: absolute;
color: #a04040;
left: 50%;
transform: translateX( -50% );
}
Just as Loesh Gupta says: make the wrapper .wrapper { position: relative; }. To center the text you can use multiple options. I'd go with something like this:
h1 { position: absolute; left: 50%; right: 50%; transform: translate(-50%, -50%); }
I can also recommend this tool: http://howtocenterincss.com/
Here's a solution using flexbox:
#wrapper {
display: flex; /* establish flex container */
flex-direction: column; /* stack flex items vertically */
position: relative; /* establish neares positioned ancenstor for absolute positioning */
}
h1 {
color: red;
}
.text {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: white;
font-weight: bold;
}
.center-aligned {
display: flex;
align-items: center;
justify-content: center;
}
<div id="wrapper" class="center-aligned">
<img class="background-image" src="http://michaelmossey.com/demo/home-hiker-grayish.jpg" />
<div class="text"><h1>Math Achivement Tutoring<h1></div>
</div>
Using a background image on a div and a display flex on the text might do it. Make sure to add the height on the text based on the image so it can be centered.
*{margin: 0 auto;}
.bg{
background-image:url('http://michaelmossey.com/demo/home-hiker-grayish.jpg');
height: 380px;
background-repeat: no-repeat;
background-size:cover;
background-position: center center;
}
.bg h1{
display: flex;
justify-content: center;
align-items: center;
height: 380px;
font-size: 3em;
color: #ffffff;
background-color: rgba(0,0,0,0.5);
}
<div class="bg">
<h1>Math Achivement Tutoring</h1>
</div>
I am trying to make my text appear ontop of my background image. I have tried playing around with the z-index and positioning, but cannot seem to get it right.
Here is my HTML:
<div id="float-left">
<div id="triangles">
<img src="img/trianglebackground.png" id="tripic">
</div>
<div id="float-left-text">
<img src="img/portrait.png" id="port">
</div>
</div>
Here is the CSS I have currently:
#tripic {
z-index:1;
height: 550px;
width: 500px;
text-align: center;
opacity: 0.2;
position: relative;
}
#float-left {
float: left;
/*background: url('img/trianglebackground.png') no-repeat center;*/
background-size:500px 550px;
background-color: #03C9A9;
height: 550px;
width: 50%;
z-index:0 ;
position: relative;
}
#float-left-text{
text-align: center;
z-index: 100;
position: absolute;
}
#port {
height: 200px;
width: 125px;
}
Right now, the entire #floatlefttext section is below the background image, whereas I would like it to be ontop. I have tried to use background-image, but I am not sure it's going to be the best way to get the results I would like. Any advice would be great, thanks!
I created a fiddle for you here: https://jsfiddle.net/0w1max4f/
#floatlefttext{
text-align: center;
z-index: 100;
position: absolute;
top: 0px;
left: 0px;
}
Is this what you were looking for? Since your html didn't actually include any text elements (just an image) to be placed on top of the background, but hopefully this will help you anyway.
What I did was to clean up your html (you had some tags that were not properly closed, for example the images and some divs) and add top and left to you absolute positioned div.
You were using absolute and relative positioning correctly but forgot to specifiy where the absolute positioned item were supposed to be placed.
here's a good article about positioning if you want to learn more:
https://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/
Something like this
<div style="position: relative; background: url(path to image); width: (width)px; height: (height)px;">
<div style="position: absolute; bottom: 0; left: 0.5em; width: 400px; font-weight: bold; color: #fff;">
<p>(text to appear at the bottom left of the image)</p>
</div>
<p style="position: absolute; top: 1em; right: 2em; width: 120px; padding: 4px; background-color: #fff; font-weight: bold; font-size: 11px;">
(text to appear at the top right of the image)
</p>
</div>
Be aware that you should separate the css from the html
Fiddle: Text ontop of an image and linkage
CSS:
div.image-container
{
width: 400px;
}
a.imagewrapper
{
width:inherit;
}
img.theimage{
width:inherit;
}
a.teasertext
{
position: absolute;
padding-top: 1%;
color: #fff;
line-height: 1.2em;
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
letter-spacing: .02em;
font-size: 1.5em;
overflow-wrap: break-word;
overflow-y: hidden;
-webkit-transition: all .3s;
transition: all .3s;
font-size: 41px;
width:inherit;
}
HTML:
<div>WOOP DE DOO</div>
<div class="image-container">
<a class="teasertext" href="www.stackoverflow.com">Text on the image, wow amazing !</a>
<a class="imagewrapper" href="www.stackoverflow.com">
<img class="theimage" src="http://img.thesun.co.uk/aidemitlum/archive/01667/THUNDER620_1667926a.jpg">
</a>
</div>
<div class="image-container">
<a class="teasertext" href="www.stackoverflow.com">Text on the image, wow amazing !</a>
<a class="imagewrapper" href="www.stackoverflow.com">
<img class="theimage" src="http://img.thesun.co.uk/aidemitlum/archive/01667/THUNDER620_1667926a.jpg">
</a>
</div>
<div>WOOP DE DOO</div>
How can I get the caption text on these images to move around when then the browser window is resized? My implementation is jicky and I need a way to keep the text from sliding around when the window is resized.
Codepen
<div class="row">
<div class="col-md-6">
<img src="http://placekitten.com/600/375" class="img-responsive" />
<h2 class="homeImageLink">
<span>Caption Text</span>
</h2>
</div>
<div class="col-md-6">
<img src="http://placekitten.com/600/375" class="img-responsive" />
<h2 class="homeImageLink">
<span>Caption Text</span>
</h2>
</div>
</div>
.homeImageLink {
position: absolute;
top: 110px;
left: 0;
text-align: center;
width: 100%;
}
.homeImageLink span {
color: red;
font-weight: 300;
font-style: italic;
text-transform: uppercase;
letter-spacing: 15px;
pointer-events: none;
}
Just add one class to parent container, make it's position relative.
.img-container {
position:relative;
}
And then make homeImageLink absolute and give top at around 45%..
It will make it vertically centered..
.homeImageLink {
position: absolute;
top: calc(50% - 24px); //24px is font size of H1 I assume
left: 0;
text-align: center;
width: 100%;
}
Demo here : http://codepen.io/anon/pen/bJadE
I came up with another solution, here's a working demo:
http://codepen.io/niente0/pen/jyzdRp
HTML:
<DIV class=wrapper>
<DIV class=divimage></DIV>
<DIV class=divtext>THIS IS A TEST</DIV>
</DIV>
CSS:
HTML,BODY {
max-width:1200px;
}
.wrapper {
position:relative;
width:100%;
max-width:1200px;
height:100%;
min-height:320px
}
.divimage { position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:url(https://thumbs.dreamstime.com/t/empty-red-banner-corners-ropes-textile-white-background-d-illustration-70434974.jpg);
background-repeat:no-repeat;
background-size:100% auto;
}
.divtext {
position:absolute;
top:0;
left:0;
width:100%;
padding-top:13.5%;
text-align:center;
font-weight:bold;
font-size:5vw;
color:white;
font-family:arial;
}
#media (min-width: 1200px) {
.divtext{
font-size:60px;
}
}