Trying to get banner inside of the header - html

I am trying to get a banner with "slogan" and an image to appear inside the header area. When I write it out it appears below the header section, and I cannot figure out how to get it inside the header area.
I would also like to make it responsive. So I would like the "slogan" to move up and the image to move below the "slogan" when it reaches less than 768px
Thanks
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Cabin', sans-serif;
}
/* Header */
.header-image {
background-image: url('https://images.unsplash.com/photo-1472376758045-62f519fc676d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8300925c51f6d651fa7cb9c41eaafb45&auto=format&fit=crop&w=2850&q=80');
background-position: center;
background-size: cover;
background-attachment: scroll;
color: white;
width: 100%;
height: 49em;
}
.header-wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
width: 100%;
height: 49em;
}
.logo {
grid-column: 1;
display: flex;
justify-content: flex-start;
margin-left: .5em;
}
.nav-header {
grid-column: 2;
list-style: none;
display: flex;
justify-content: space-around;
}
/* Banner */
.slogan,
.banner {
margin: 0;
}
.banner-image {
width: 15em;
height: 15em;
border-radius: 50%;
}
<!-- HEADER -->
<header class="header-image">
<div class="header-wrapper">
<h1 class="logo">STARTUP NAME</h1>
<nav>
<ul class="nav-header">
<li class="navmenu">Services</li>
<li class="navmenu">Pricing</li>
<li class="navmenu">Contact</li>
</ul>
</nav>
</div>
</header>
<!-- BANNER -->
<section class="main-banner">
<div class="banner-container">
<h1 class="slogan banner">Some Cool Slogan</h1>
<span class="slogan banner">A cool subtitle explaining said cool Slogan</span>
<img class="banner-image banner" src="https://images.unsplash.com/photo-1532007271951-c487760934ae?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f7ad947fb913065733cd1494ed95ef59&auto=format&fit=crop&w=1100&q=80" alt="">
</div>
</section>

I adjusted the code to have a wrapper around the title and to have it at the center of the page. And added media query CSS to come one below the other in mobile
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Cabin', sans-serif;
}
/* Header */
.header-image {
background-image: url('https://images.unsplash.com/photo-1472376758045-62f519fc676d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8300925c51f6d651fa7cb9c41eaafb45&auto=format&fit=crop&w=2850&q=80');
background-position: center;
background-size: cover;
background-attachment: scroll;
color: white;
width: 100%;
height: 49em;
}
.header-wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
width: 100%;
height: 49em;
}
.logo {
grid-column: 1;
display: flex;
justify-content: flex-start;
margin-left: .5em;
}
.nav-header {
grid-column: 2;
list-style: none;
display: flex;
justify-content: space-around;
}
/* Banner */
.slogan,
.banner {
margin: 0;
}
.banner-image {
width: 15em;
height: 15em;
border-radius: 50%;
}
section.main-banner {
position: absolute;
width:100%;
text-align:center;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.sloganWrapper{
display:inline-block;
vertical-align: middle;
}
img.banner-image.banner {
vertical-align: middle;
}
#media only screen and (max-width:767px){
.sloganWrapper{
display:block;
}
}
<!-- HEADER -->
<header class="header-image">
<div class="header-wrapper">
<h1 class="logo">STARTUP NAME</h1>
<nav>
<ul class="nav-header">
<li class="navmenu">Services</li>
<li class="navmenu">Pricing</li>
<li class="navmenu">Contact</li>
</ul>
</nav>
</div>
</header>
<!-- BANNER -->
<section class="main-banner">
<div class="banner-container">
<div class="sloganWrapper">
<h1 class="slogan banner">Some Cool Slogan</h1>
<span class="slogan banner">A cool subtitle explaining said cool Slogan</span></div>
<img class="banner-image banner" src="https://images.unsplash.com/photo-1532007271951-c487760934ae?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f7ad947fb913065733cd1494ed95ef59&auto=format&fit=crop&w=1100&q=80" alt="">
</div>
</section>

I think it's because your .main-banner is not being contained in the header.
Try making header position: absolute; and then move the banner image to .main-banner
See if it's what you need...
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Cabin', sans-serif;
}
/* Header */
.header-wrapper {
position: absolute;
top: 0;
left: 0;
display: grid;
grid-template-columns: 1fr 1fr;
width: 100%;
color: #fff;
}
.logo {
grid-column: 1;
display: flex;
justify-content: flex-start;
margin-left: .5em;
}
.nav-header {
grid-column: 2;
list-style: none;
display: flex;
justify-content: space-around;
}
/* Banner */
.main-banner {
padding-top: 100px;
background-image: url('https://images.unsplash.com/photo-1472376758045-62f519fc676d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8300925c51f6d651fa7cb9c41eaafb45&auto=format&fit=crop&w=2850&q=80');
background-position: center;
background-size: cover;
background-attachment: scroll;
color: white;
width: 100%;
height: 49em;
margin-bottom: 20px;
}
.slogan,
.banner {
margin: 0;
}
.banner-image {
width: 15em;
height: 15em;
border-radius: 50%;
}
<!-- HEADER -->
<header>
<div class="header-wrapper">
<h1 class="logo">STARTUP NAME</h1>
<nav>
<ul class="nav-header">
<li class="navmenu">Services</li>
<li class="navmenu">Pricing</li>
<li class="navmenu">Contact</li>
</ul>
</nav>
</div>
</header>
<!-- BANNER -->
<section class="main-banner">
<div class="banner-container">
<h1 class="slogan banner">Some Cool Slogan</h1>
<span class="slogan banner">A cool subtitle explaining said cool Slogan</span>
<img class="banner-image banner" src="https://images.unsplash.com/photo-1532007271951-c487760934ae?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f7ad947fb913065733cd1494ed95ef59&auto=format&fit=crop&w=1100&q=80" alt="">
</div>
</section>
Testing

Related

Hollow circle items

I would like to achieve circle cuts/hollows in the layer that covers the background images.
I have the background image covered with white tint (opacity 60%).
On the background, I have 3 circles that include text.
How can I cut "rings" in the white tint?
I would like to make hollows/cuts in the white tint like here:
My code looks now as below:
body {
margin: 0;
}
.block {
position: relative;
width: 100%;
}
.bg {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -3;
}
.bg:before {
content: "";
background: #ffffff;
opacity: 0.6;
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
}
.bg img {
display: block;
object-fit: cover;
object-position: center;
width: 100%;
height: 100%;
}
.wrapper {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 0 30px;
}
.item {
background: #aaaaaa;
width: 150px;
height: 150px;
border-radius: 100%;
display: flex;
flex-direction: columns;
justify-content: center;
align-items: center;
padding: 10px;
}
.item h2 {
font-family: Arial, sans-serif;
font-size: 15px;
color: #000000;
text-align: center;
margin: 0;
}
<section class="block">
<div class="bg">
<img src="https://i.picsum.photos/id/98/1920/1080.jpg?hmac=38vHAR4QCfR9YGpaasbQ0h390ZJnDlnQqzv3xTDF6ik" alt="" />
</div>
<div class="wrapper">
<div class="item">
<div class="item__content">
<h2>Heading 1</h2>
</div>
</div>
<div class="item">
<div class="item__content">
<h2>Heading 2</h2>
</div>
</div>
<div class="item">
<h2>Heading 3</h2>
</div>
</div>
</section>
You can do it like below. I have simplified the code as well:
body {
margin: 0;
}
section {
min-height: 100vh;
/* a grid container with 3 columns*/
display: grid;
grid-template-columns: 1fr 1fr 1fr;
/* the image as background */
background: url(https://i.picsum.photos/id/98/1920/1080.jpg?hmac=38vHAR4QCfR9YGpaasbQ0h390ZJnDlnQqzv3xTDF6ik) center/cover;
}
.item {
overflow: hidden; /* hide the overflow of the shadow */
/* center the heading */
display: grid;
place-items: center;
/**/
}
.item h2 {
width: 80%; /* adjust this to control the size */
aspect-ratio: 1; /* keep it a perfect circle */
box-sizing: border-box;
border-radius: 50%;
/* center the content of the heading */
display: grid;
place-items: center;
/**/
padding: 20px; /* this will control the inner space */
background: rgb(255 255 255/60%) content-box; /* color only the content area */
box-shadow: 0 0 0 100vmax rgb(255 255 255/60%); /* a big box-shadow */
}
<section>
<div class="item">
<h2>Heading 1</h2>
</div>
<div class="item">
<h2>Heading 2</h2>
</div>
<div class="item">
<h2>Heading 2</h2>
</div>
</section>

CSS Cascading Issue

I'm working on a project and my CSS doesn't seem to be cascading correctly.
I have set some styles (mainly the color property) at the HTML tag level. However it is not cascading to the rest of my elements, specifically the .logo class, but also some other classes. Can anyone help me understand why this is happening?
Here is my code:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-family: Helvetica, Arial, sans-serif;
color: seashell;
background-color: black;
text-align: center;
font-size: 22px;
opacity: 0.9;
}
/* Header and Nav Bar */
.header {
display: flex;
justify-content: space-between;
align-items: center;
height: 69px;
width: 100%;
position: fixed;
top: 0;
z-index: 10;
border-bottom: 1px solid seashell;
}
.logo {
margin-left: 10px;
max-height: 50px;
}
.navigation {
display: flex;
list-style: none;
}
.navigation a {
padding: 15px;
}
.navigation a:hover {
text-decoration: none;
}
/******* Hero *******/
#hero {
background-image: url(/Images/img-mission-background.webp);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
top: 70px;
height: 700px;
width: 1200px;
margin: auto;
opacity: 0.8;
}
#hero h2,
h4 {
padding: 12px;
}
/***** Content ******/
.content {
position: relative;
top: 100px;
}
<!--******* Header ******* -->
<header class="header">
<img src="/Images/img-tea-cozy-logo.webp" alt="Tea Cozy Logo" class="logo" />
<ul class="navigation">
<li>Mission</li>
<li>Featured Tea</li>
<li>Locations</li>
</ul>
</header>
<section id="hero">
<h2>Our Mission</h2>
<h4>
Handpicked, Artisanally Curated, Free Range, Sustainable, Small Batch, Fair Trade, Organic Tea
</h4>
</section>
<section class="content">
<h1>Tea of the Month</h1>
</section>

Creating a responsive image for a section

I'm sure I have made some kind of really obvious stupid mistake here but it's been bugging me for a while now and I just cannot figure it out no matter where I look.. I am just practicing with a very basic, boring site and I need the image to be responsive in the section underneath the header, but for some reason no matter what I do, I just can't get it to work.
Sorry if this has been answered, I had a look and couldn't find anything exactly the same. If anyone could shed some light on this for me I would be very appreciative. Thanks in advance.
HTML:
<html>
<body>
<header>
<div class="container">
<div class="brand">
<img class="brandImg" src="https://photos-1.dropbox.com/t/2/AACo_XuN80WW6m3RltLuUDD-Koivyw205OCV55h43hevVQ/12/184045382/png/32x32/1/_/1/2/network.png/EKPi4YsBGMICIAIoAg/u6N5dEYvNDRNysVhT6Arx-eKOa64tOkilzRp8K3e93Y?preserve_transparency=1&size=1600x1200&size_mode=3" alt="Brand Image">
<h3 class="mainTitle">Network Solutions</h3>
</div>
<nav>
<ul class="navBar">
<li>About |</li>
<li>Portfolio |</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
<section id="showcase">
<div class="heroImg">
<div class="container">
</div>
</div>
</section>
</body>
</html>
CSS:
/* MAIN STYLES */
.container {
max-width: 60%;
margin: 0 auto;
}
/* HEADER */
header {
height: 100px;
border-bottom: 2px solid black;
border-top: 2px solid black;
}
.brand {
float: left;
display: inline;
margin-top: 20px;
}
.brandImg {
height: 4em;
width: 4em;
float: left;
margin-bottom: 5px;
}
.mainTitle {
font-family: 'IBM Plex Mono', monospace;
line-height: 1.2em;
position: relative;
left:8px;
top: -5px;
}
/* MAIN NAVIGATION */
ul {
float: right;
}
li {
margin-top: 15px;
float: left;
display: inline;
font-size: 40px;
padding-left: 15px;
}
a {
color: #000;
text-decoration: none;
}
a:hover {
color: gray;
}
/* HERO SECTION */
#showcase {
width: 100%;
height: 100%;
}
.heroImg {
background-image: url("https://photos-1.dropbox.com/t/2/AADgiVKPX---q_yzz3R6QXjMuvUF9x1suRGMjLMV8QkZVQ/12/184045382/jpeg/32x32/1/_/1/2/hero.jpeg/EKPi4YsBGMICIAIoAg/-UTK8zUqda_wA3F-VrZAdIZvo84OHHGWCbLEcdCi1K8?size=1600x1200&size_mode=3");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
Codepen link
The logo image in your pen is throwing a 403 error. Generally speaking, you can make an image responsive with the following CSS:
img {
display: inline-block;
max-width: 50px; /* Width of your image */
max-height: 50px; /* Height of your image */
width: 100%;
height: auto;
}
Here is a JSFiddle example. Drag the window to see how the image reacts.
img {
display: inline-block;
max-width: 650px;
max-height: 250px;
width: 100%;
height: auto;
}
<img src="http://via.placeholder.com/650x250" alt="Stack Overflow Test Image" />
Here's another example using Flexbox making the image responsive relative to another element:
#test {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
img {
display: inline-block;
max-width: 250px;
max-height: 150px;
width: 100%;
height: auto;
}
h1 {
margin-left: 15px;
-webkit-flex: none;
-ms-flex: none;
flex: none;
}
<div id="test">
<div id="logo">
<img src="http://via.placeholder.com/250x150" alt="Stack Overflow Test Image" />
</div>
<h1>This is a Test Title</h1>
</div>

How to fix website header text to header image

I am having trouble fixing/anchoring some slogan text to a website header. I get it to the position i want but when the page is resized the text is no longer in the position i want it. Can this be done in html and css or does the text have to be put onto the actual image?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
background-color: #fff;
color: #555;
font-family: 'Lato', 'Arial'. 'sans-serif';
font-weight: 300;
font-size: 20px;
text-rendering: optimizeLegibility;
}
.row {
max-width: 1140px;
margin: 0 auto;
}
header {
background-image: url(img/view3.jpg);
height: 100vh;
background-size: cover;
background-position: center;
}
.header-text-box {
position: absolute;
width: 1140px;
top: 50%;
left: 30%;
color: white;
}
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,300i,400" rel="stylesheet">
<nav>
<div class="row">
<a href="index.html">
<img src="https://static1.squarespace.com/static/524263b4e4b0adb01903b572/t/575edefe86db433ce0efcf9b/1465835270342/" alt="developer logo" class="avatar">
</a>
<ul class="main-nav">
<li>About</li>
<li>Projects</li>
<li>Blog</li>
</ul>
</div>
</nav>
<div class="header-text-box">
<h1>The header text i</h1>
<p>want goes here.</p>
</div>
Would this solution be considered bad practice?
header {
background-image: url(img/test.jpg);
height: 100vh;
background-size: cover;
background-position: center;
width: 100vw;
}
.header-text-box {
position: absolute;
width: 1140px;
top: 50vh;
left: 30vw;
color: white;
}
Try using vh and vw for your positioning. % is a bit funky especially with height.
.header-text-box {
top: 50vh;
left: 30vw;
}
Also be sure to set
header {
position: relative;
}
so the .header-text-box will follow the header tag instead of the body tag
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
background-color: #fff;
color: #555;
font-family: 'Lato', 'Arial'. 'sans-serif';
font-weight: 300;
font-size: 20px;
text-rendering: optimizeLegibility;
}
.row {
max-width: 1140px;
margin: 0 auto;
}
header {
background-image: url(https://static1.squarespace.com/static/524263b4e4b0adb01903b572/t/575edefe86db433ce0efcf9b/1465835270342/);
height: 100vh;
background-size: cover;
background-position: center;
display: flex; /* this is the magic css */
justify-content:center; /* this is the magic css */
align-items:center; /* this is the magic css */
}
.header-text-box {
color: white;
}
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,300i,400" rel="stylesheet">
<nav>
<div class="row">
<header>
<div class="header-text-box">
<h1>The header text i</h1>
<p>want goes here.</p>
</div>
</header>
<ul class="main-nav">
<li>About</li>
<li>Projects</li>
<li>Blog</li>
</ul>
</div>
</nav>
Not sure if this is what you are going for. But I am assuming you want the header text centered in the header image. I try to avoid absolute position as it tends to be messy.
for this type of stuff I like to use flex
here is a fun way to master flex: http://flexboxfroggy.com/
flexbox w background image and vmin
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
background-color: #fff;
color: white;
}
header {
background-image: url(https://static1.squarespace.com/static/524263b4e4b0adb01903b572/t/575edefe86db433ce0efcf9b/1465835270342);
height: 100vh;
background-size: cover;
background-position: center;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-content: center;
align-items: center;
}
header > h1 {
font-size: 12vmin;
flex: 0 1 auto;
align-self: auto;
}
header > p {
font-size: 6vmin;
flex: 0 1 auto;
align-self: auto;
}
<header>
<h1>The header text</h1>
<p>subtext this is subtext</p>
</header>

How can I vertically center all children of my div using css?

Here is my code
.header {
width: 100%;
height: 100px;
background: black;
}
.header .headerContainer {
position: relative;
top: 50%;
transform: translateY(-50%);
height: inherit;
}
img#logo {
height: 75%;
}
p#logotext {
color: white;
display: inline
}
<div class="header">
<div class="headerContainer">
<img src="https://cdn.worldvectorlogo.com/logos/react.svg" alt="Logo" id="logo" />
<p id="logotext">Welcome To Here</p>
</div>
</div>
However, this is not aligning the elements properly.
How should I modify my CSS so that headerContainer does the alignment properly?
You can use flexbox to solve this:
.header {
background: black;
height: 100px;
width: 100%;
}
.header .headerContainer {
align-items: center;
display: flex;
height: inherit;
}
img#logo {
height: 75%;
}
p#logotext {
color: white;
display: inline
}
<div class="header">
<div class="headerContainer">
<img src="https://placehold.it/50x50" alt="Logo" id="logo" />
<p id="logotext">Welcome To Here</p>
</div>
</div>
So you don't need to use position or tranform to vertical center the items. If you want to learn more about flexbox I recommend this site for a quick overview / reference.
Use This Code
<style>
.class{
Position:absolute;
top:50%;
left:50%;
transform:rotateX(-50%,50%);
}
</style>
You can also use CSS Grid.
.header {
background: black;
height: 100%
width: 100%;
padding: 20px;
}
.header .headerContainer {
display: grid;
grid-template-columns: 1fr 1fr;
}
img#logo {
width: auto;
height: auto;
align-self: center;
}
p#logotext {
color: white;
align-self: center;
}
<div class="header">
<div class="headerContainer">
<img src="http://via.placeholder.com/350x150" alt="Logo" id="logo" />
<p id="logotext">Welcome To Here</p>
</div>
</div>
so close .... you just need to put dispaly : flex; into headerContainer
.header {
background: black;
height: 100px;
width: 100%;
}
.header .headerContainer {
align-items: center;
display: flex;
height: inherit;
}
img#logo {
height: 75%;
}
p#logotext {
color: white;
display: inline
}