I'm developing a web UI that currently has a blue banner. However, when I try to modify its size in the CSS chunk below, it doesn't update. Before, in the code below, background-size was set to cover, but I need the height of the banner to shrink.
#header {
background-color: #04f;
color: rgba(255, 255, 255, 0.75);
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-align-items: center;
-webkit-align-items: center;
-ms-align-items: center;
align-items: center;
-moz-justify-content: center;
-webkit-justify-content: center;
-ms-justify-content: center;
justify-content: center;
-moz-flex-direction: column;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
padding: 8em 0 6em 0;
background-size: 20px 20px;
background-position: center top;
background-attachment: fixed;
text-align: center;
position: relative;
cursor: default;
}
<!DOCTYPE HTML>
<html>
<head>
<title>Author Script by SANDERS</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="static/main.css?version=1" />
</head>
<body>
<!-- Header -->
<header id="header" class="alt">
<div class="inner">
<h1>Sanders Author Script</h1>
<p>A free author formatting script by Stephan J. Sanders</p>
</div>
</header>
</body>
</html>
You can add height property to the css ID.
#header {
background-color: #04f;
height : 500px;
width : 100%;
}
Related
I am using display: flex for a page with a header, main, and footer. The issue I am running into is that the main is not vertically centered and is lower than I'd want it to be. I can't seem to figure out the best way to go about this and I've messed with the padding and margin to align it, however is there a better way?
body {
min-height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
}
.header-main {
width: 100%;
display: inline-flex;
justify-content: space-between;
flex-wrap: wrap;
align-items: center;
}
.footer-main {
width: 100%;
text-align: center;
min-height: 50px;
}
.error-wrapper {
text-align: center;
flex: 1;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<header class="header-main">
<h1 class="header-title">TITLE</h1>
<ul class="header-elements">
<li>
ABOUT
</li>
</ul>
</header>
<main class="error-wrapper">
<p id="error-segment">404</p>
<h1 id="message-segment">PAGE NOT FOUND</h1>
</main>
<footer class="footer-main">
<p class="footer-text">footer</p>
</footer>
</body>
</html>
I fail to get the image (logo) in the center of the top bar!! I tried everything, I used align-self: center; , display:block; but no luck!! I don't know what i'm missing here!
codesandbox Link to the code for better viewing
The code:
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="مرحبا">
<meta name="description" content="">
<style>
.mail {
justify-content: center;
align-content: center;
align-items: center;
}
.headerContainer{
width: 100%;
display: flex;
justify-content: space-between;
align-content: center;
align-items: center;
align-self: center;
margin-bottom: 50px;
background-color: black;
}
.logo-image-cont{
align-content: center;
align-items: center;
align-self: center;
}
.logo-image {
width: 20%;
height: 10%;
}
</style>
</head>
<body>
<div class="mail">
<header class="headerContainer">
<div class="logo-image-cont">
<img
src="https://i.ibb.co/jwjBMnS/Kia-logo.png"
class="logo-image"
/>
</a>
</div>
</header>
</div>
</body>
</html>
Add the following CSS:
.logo-image-cont {
display: flex;
justify-content: center;
}
See the snippet below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="مرحبا">
<meta name="description" content="">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
#import url('https://fonts.googleapis.com/css2?family=Tajawal:wght#200;300;400;500;700;800;900&display=swap');
.mail {
justify-content: center;
align-content: center;
align-items: center;
}
.headerContainer {
width: 100%;
display: flex;
justify-content: space-between;
align-content: center;
align-items: center;
align-self: center;
margin-bottom: 50px;
background-color: black;
}
.logo-image-cont {
display: flex;
justify-content: center;
}
.logo-image {
width: 20%;
height: 10%;
}
.emailSection {
display: flex;
justify-content: center;
align-self: center;
align-content: center;
font-family: 'Tajawal', sans-serif;
text-align: center;
}
</style>
</head>
<body>
<div class="mail">
<header class="headerContainer">
<div class="logo-image-cont">
<img src="https://i.ibb.co/jwjBMnS/Kia-logo.png" class="logo-image">
</div>
</header>
<section class="emailSection" id="sec-3cf1">
<div>
</div>
</section>
<footer class="emailFooter">
<div class="footerCopyrightCont">
</div>
</footer>
</div>
</body>
</html>
Add
display: flex;
justify-content:center;
inside your logo-image-con div block
Link to corrected code
add text-align: center; to .logo-image-cont
Replace the css class with this
.logo-image-cont{
align-content: center;
align-items: center;
align-self: center;
display: flex;
}
.logo-image {
width: 20%;
height: 10%;
margin: 0 auto;
}
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="مرحبا">
<meta name="description" content="">
<style>
.mail {
justify-content: center;
align-content: center;
align-items: center;
}
.headerContainer{
width: 100%;
display: flex;
justify-content: space-between;
align-content: center;
align-items: center;
align-self: center;
margin-bottom: 50px;
background-color: black;
}
.logo-image-cont{
align-content: center;
align-items: center;
align-self: center;
display: flex;
}
.logo-image {
width: 20%;
height: 10%;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="mail">
<header class="headerContainer">
<div class="logo-image-cont">
<img
src="https://i.ibb.co/jwjBMnS/Kia-logo.png"
class="logo-image"
/>
</a>
</div>
</header>
</div>
</body>
</html>
Is there a way to stop the span from going to a new line when the parent is flex-direction: column?
.card-content-column {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
width: 100%;
margin-top: 20px;
}
.card-content-column__title {
font-size: 24px;
width: 100%;
margin-bottom: 15px;
color: #004a88;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
<div class="card-content-column">
<!--title row-->
<h2 class="card-content-column__title">Taken with natural breathing
<span class="asterisk-weight-normal">*</span></h2>
<!--content-->
</div>
You can change the h2's display property to inline-block. It will work.
.card-content-column {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
width: 100%;
margin-top: 20px;
}
.card-content-column__title {
font-size: 24px;
width: 100%;
margin-bottom: 15px;
color: #004a88;
display: inline-block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<body>
<div class="card-content-column">
<!--title row-->
<h2 class="card-content-column__title">
Taken with natural breathing
<span class="asterisk-weight-normal">*</span>
</h2>
<!--content-->
</div>
<script src="index.js"></script>
</body>
</body>
</html>
You should use display:contents
.card-content-column {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
width: 100%;
margin-top: 20px;
}
.card-content-column__title {
font-size: 24px;
width: 100%;
margin-bottom: 15px;
color: #004a88;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.card-content-column__title .asterisk-weight-normal {
display: contents;
}
<div class="card-content-column">
<!--title row-->
<h2 class="card-content-column__title">
Taken with natural breathing
<span class="asterisk-weight-normal">*</span>
<span>extra column</span>
<span>extra column</span>
</h2>
<!--content-->
</div>
I am trying to add image to the flex item, but i am not able to fit it to the complete div container.
following is my code. can someone advise how can i have image fit in to flex item (div container).
<!DOCTYPE html>
<html lang="en">
<head>
<title>Flex Box</title>
<meta charset="utf-8">
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 800px;
height: 500px;
background-color: blueviolet;
-webkit-flex-direction: column-reverse;
flex-direction: column;
-webkit-align-content: stretch;
align-content: stretch;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: space-around;
justify-content: space-around;
}
.flex-item {
background-color: bisque;
margin: 15px;
width: 600px;
flex-grow: 1;
}
.third_item {
-webkit-flex: 1;
flex: 1;
}
#iimage {
background-color: transparent;
}
</style>
</head>
<body>
<article class="flex-container">
<div class="flex-item third_item">
<img src="block_beach_1.jpg" width="600px" height="100px" id="iimage">
</div>
</article>
</body></html>
You can fit the image to the container by specifying a width 100% in your css for the image. Also remove the inline width and height property for the image.
Edit: If you want to fit the image horizontally and vertically, apply height 100% along with the width value.
.flex-container {
display: -webkit-flex;
display: flex;
width: 800px;
height: 500px;
background-color: blueviolet;
-webkit-flex-direction: column-reverse;
flex-direction: column;
-webkit-align-content: stretch;
align-content: stretch;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: space-around;
justify-content: space-around;
}
.flex-item {
background-color: bisque;
margin: 15px;
width: 600px;
flex-grow: 1;
}
.third_item {
-webkit-flex: 1;
flex: 1;
}
#iimage {
width: 100%;
height: 100%;
background-color: transparent;
}
<article class="flex-container">
<div class="flex-item third_item">
<img src="https://miro.medium.com/max/3000/1*MI686k5sDQrISBM6L8pf5A.jpeg" id="iimage" />
</div>
</article>
I'm working on duplicating this website for practice. using flex to put the navbar side-by-side with the rest of the page (refer to link), but the items aren't going side by side, they're just overlapping. i tried using the overflow: hidden;, like you would for float. i tried adding fixed height and width to the items. can't figure out why they wont go side by side like they're supposed to
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="practice.css">
</head>
<body>
<div class="wholepage">
<nav class="navbar">
<ul>
<li>H</li>
<li>C</li>
<li>P</li>
</ul>
</nav>
<div class="body">
<div class="head">
<div class="left"><h1>essential<br>looks</h1></div>
<div class="right"></div>
</div>
</div>
</div></body>
</html>
the css:
.wholepage {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: stretch;
-ms-flex-align: stretch;
align-items: stretch;
overflow: hidden;
}
.navbar {
width: 5%;
background-color: #353535;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-flow: column nowrap;
flex-flow: column nowrap;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
height: 100%;
position: fixed;
}
.navbar ul {
margin: 0;
padding: 0;
list-style: none;
}
.navbar li {
color: white;
margin: 9px auto;
}
.navbar a {
text-decoration: none;
color: white;
font-size: 1.25rem;
}
.body {
overflow: hidden;
}
.head {
overflow: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 80%;
margin: auto;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.left {
float: left;
}
/*# sourceMappingURL=practice.css.map */
I figured it out. It was not flex-direction column, row was correct. but since i tried to do a "position: fixed;" on the navbar, it screwed up the flexbox. once i removed that, it worked. my question now is, is there a way to do a non-scrolling section with flex or will i have to use a different method