Vertical align header page elements - html

I have header tag, which has full width/height image on the background.
I need to algin elements in the center of that page exactly as picture shows.
First goes image, than text, than buttons one after another one and on the very bottom of the page is slider
apart from slider, I've managed to put all content to the center with code below
Also, I'm using boostrap and jquery if needed
It's one page design, this is just a header
Thank you for any help :)
<header>
<img src="" alt="full">
<h1>The</h1>
Login
Browse
<div class="swiper-container">
</div>
</header>
SCSS
header {
margin-top: -56px !important;
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(../img_cover_m.jpg);
background-size: cover;
background-position: center;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
img {
margin-top: 5%;
max-width: 50%;
height: auto;
}
h1 {
color: #fff;
}
.btn {
#include Myriad-Pro-Light;
}
.btn-green {
margin-top: 5%;
color: #fff;
}
.btn-grey {
color: #000;
}
.swiper-container {
margin-top: 5%;
width: 100%;
height: 300px;
}
}

You can achieve this by using the following properties at the appropriate places.
text-align:center;
display:flex;
align-center;
margin:0 auto;
Also as your using bootstrap so some of the classes may get overwritten so make sure to use !important on properties that you want to force your setting on.
Using your code i have made some changes using the above mentioned suggestions and here is the code:
<header>
<img src="http://placehold.it/350x150" alt="full">
<h1>The</h1>
Login
Browse
<div class="swiper-container">
<p>Large full width div, which must stay on the bottom of the header tag</p>
</div>
</header>
header {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(../img_cover_m.jpg);
background-size: cover;
background-position: center;
height: 100vh;
min-width: 20%;
display: flex;
flex-direction: column;
align-items: center;
}
img {
margin: 0 auto;
display: block;
max-width: 50%;
height: auto;
}
h1 {
color: #fff;
text-align:center;
}
.btn {
#include Myriad-Pro-Light !important;
margin: 10px auto !important;
display: block !important;
width: 25vw !important;
text-align:center !important;
padding: 6px 0px !important;
}
.btn-green {
color: #fff;
display:block;
}
.btn-grey {
color: #000;
display:block;
}
.swiper-container {
background-color:red;
width: 100%;
height: 300px;
position:absolute;
bottom:0;
display: flex;
align-items: center;
justify-content: center
}
.swiper-container p{
#include Myriad-Pro-Light !important;
margin:0 auto;
color:white;
font-size: 18px;
}
Here is a sample using this code. http://codepen.io/Nasir_T/pen/PboZme

Related

How to make image fit in div?

I am trying to create a simple card, where image should cover/fit the full width of the container div.
My desired style would be something similar like in the image below.
I tried to apply object-fit:cover with 100% width but didn't help.
Here is how it looks like now
Here is related code and sandbox link
html/jsx
import React from "react";
import styles from "./Card.module.css";
function App() {
return (
<div className={styles.cardWrapper}>
<img
src="https://i.ebayimg.com/00/s/MTAyNFg1NzY=/z/qWYAAOSwm1Vcc6F4/$_72.JPG"
alt="description"
/>
<h3 style={{ fontSize: "15px" }}>title</h3>
<div className={styles.description}>description</div>
</div>
);
}
export default App;
and css
.cardWrapper {
width: 165px;
height: 192px;
display: flex;
flex-direction: column;
justify-content: center;
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 25%);
text-align: center;
margin: 0 auto;
align-items: center;
}
.description {
font-size: 12px;
color: #808080;
margin-top: 20px;
font-weight: 400;
}
.cardWrapper img {
height: 100%;
width: 100%;
object-fit: contain;
width: auto;
height: auto;
}
Any help will be appreciated
Simply remove the width: auto and height: auto from your .cardWrapper img:
.cardWrapper {
width: 165px;
display: flex;
flex-direction: column;
justify-content: center;
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 25%);
text-align: center;
margin: 0 auto;
align-items: center;
padding-bottom: 15px;
}
.description {
font-size: 12px;
color: #808080;
margin-top: 20px;
font-weight: 400;
}
.cardWrapper img {
height: 100%;
width: 100%;
}
<div class="cardWrapper">
<img
src="https://i.ebayimg.com/00/s/MTAyNFg1NzY=/z/qWYAAOSwm1Vcc6F4/$_72.JPG"
alt="description"
/>
<h3>title</h3>
<div class="description">description</div>
</div>
You were overwriting your already working 100% rules, so just leave them in, and remove anything else. You dont need the object-fit either.
As stated by #louielyl in the comments:
remove the absolute height on the .cardWrapper as well, otherwise the description has no room left in the wrapper and falls out.
The reason why your width:100% and height:100% didn't work is because your latter css width: auto; height: auto; overwrite them.
Try this and you will see your image grows as expected:
.cardWrapper img {
height: 100%;
width: 100%;
object-fit: contain;
}
It happens because it is CSS's behavior to override with the latter styling that has the same property, for details, you could take a look at Specificity.

Center Vertically Image and UL both at Once (HTML CSS) [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Closed 2 years ago.
I am actually trying to design the navbar for website and I am facing issue , I have one logo to show on the left and UL to right side on nav , I have created both and now I want them both to be center-vertical in their div container , unfortunately I am not able to center-vertical UL tag , need some help in css or html !
Here I am attaching the html
header {
height: 100vh;
background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(../../img/static/cover.jpg);
background-size: cover;
background-repeat: no-repeat;
}
.div_nav {
overflow: auto;
width: 80%;
margin: 0px auto;
padding: 16px 32px;
background-color: rgba(139, 0, 139, 0.459);
}
.nav_logo {
background-color: darkorange;
height: 72px;
width: auto;
}
.nav_ul {
background-color: darkslateblue;
float: right;
margin: auto 0px;
list-style: none;
}
.nav_ul li {
margin-left: 16px;
display: inline-block;
}
.nav_ul li a {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
}
<header>
<nav>
<div class="div_nav">
<img src="././img/static/logo.png" alt="Bbooster_Logo" class="nav_logo">
<ul class="nav_ul">
<li>Para</li>
<li>Sagro</li>
<li>Miasa</li>
<li>Varga</li>
</ul>
</div>
</nav>
</header>
here I am attaching the image of output which I am currently getting
add flex rules for the .div_nav class and remove float: right from the .nav_ul class, since justify-content: space-between is used
header {
height: 100vh;
background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(../../img/static/cover.jpg);
background-size: cover;
background-repeat: no-repeat;
}
.div_nav {
display: flex;
align-items: center;
justify-content: space-between;
overflow: auto;
width: 80%;
margin: 0px auto;
padding: 16px 32px;
background-color: rgba(139, 0, 139, 0.459);
}
.nav_logo {
background-color: darkorange;
height: 72px;
width: auto;
}
.nav_ul {
background-color: darkslateblue;
/*float: right;*/
margin: auto 0px;
list-style: none;
}
.nav_ul li {
margin-left: 16px;
display: inline-block;
}
.nav_ul li a {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
}
<header>
<nav>
<div class="div_nav">
<img src="././img/static/logo.png" alt="Bbooster_Logo" class="nav_logo">
<ul class="nav_ul">
<li>Para</li>
<li>Sagro</li>
<li>Miasa</li>
<li>Varga</li>
</ul>
</div>
</nav>
</header>
Well, you want to say horizontal UL. You can use flex for this..
.div_nav {
width: 80%;
margin: 0px auto;
padding: 16px 32px;
background-color: rgba(139, 0, 139, 0.459);
/* Edit */
display: flex;
align-items: center;
/* This centers the elements consisting inside a flexible row div */
justify-content: space-between;
/*to keep the maximum space between consisting childs */
}
Remove the float from nav_ul

How can i get 4 divs next to each other [duplicate]

This question already has answers here:
How do you make div elements display inline?
(20 answers)
Closed 4 years ago.
Hello everyone i have a header with a div in my header with a pic in it but i want to display my pics next to eachother but instead of that its displays it under each other how can i fix this i tried to change my css but didnt work.
its now like this when i add anoter div
How it is now:
I want it like this:
this is my code
#import url('https://fonts.googleapis.com/css?family=Josefin+Sans:400,400i,600,600i');
html,
body {
margin: 0;
height: 120%;
font-family: 'Josefin Sans', sans-serif;
}
.header {
position: relative;
overflow: hidden;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: flex-start;
align-content: flex-start;
height: 50vw;
min-height: 400px;
max-height: 550px;
min-width: 300px;
color: #eee;
}
.header:before {
content: "";
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1.0, 1.0);
transform: translateZ(0);
background: #1B2030 url(https://unsplash.it/1999/999?image=1063) top center no-repeat;
background-size: cover;
background-attachment: fixed;
animation: grow 60s linear 10ms infinite;
transition: all 0.2s ease-in-out;
z-index: -2
}
.header a {
color: #eee
}
.info {
width: 100%;
padding: 25% 10% 0 10%;
text-align: center;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.2)
}
.author {
display: inline-block;
width: 50px;
height: 50px;
border-radius: 50%;
background: url(http://favim.com/media/uploads/images/610/140308/black-n-white-cute-funny-iron-man-Favim.com-1462744.jpg) center no-repeat;
background-size: cover;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
margin-bottom: 3px
}
.info h4,
.meta {
font-size: 0.7em
}
.meta {
font-style: italic;
}
.twtr {
margin-top: 100px
}
.btn.twtr:after {
content: "\1F426";
padding-left: 5px
}
<body>
<div class="header">
<div class="info">
<h1>TestHeader</h1>
<div class="meta">
test
</div>
<div class="meta">
<br> By James Nodws on May 30, 2017
</div>
</div>
</div>
</body>
You First Have clear the body from margin and padding just in case
body{padding:0;margin:0;}
after that give each div 25% width and display either inline or inline-block
div{width:25%;display:inline;}
Add :
.meta {
display: inline-block
}
div are int display mode block by default, so it wraps the entire ligne. Change to inline-block to allow multiple divs horizontally
You have two options here
You can use Bootsrap as described in here.
Use below CSS
.meta {
float:left;
width: 30%;
}
You can use any other class which is applied only for image divs.
I think you should try using .
.meta {
display : flex;
}
This also aligns all the the <divs> in a single row
you can use flex property for,
Display:flex apply flex layout to the flex items or children of the container only. So, the container itself stays a block level element and thus takes up the entire width of the screen. ... Display:inline-flex apply flex layout to the flex items or children as well as to the container itself.

slogan and background image attach responsively

I am trying to design such header where the slogan and background image are attached in the stated picture. I want to use flex to make it work but it is not working. Giving width breaks the responsiveness. I have created a jsbin to show the demo and here it is
http://jsbin.com/muguwavosa/edit?html,css,output
The source code
.header {
display: flex;
flex-direction: column;
background-image: url('https://www.rj-investments.co.uk/wp-content/uploads/2018/02/Home-Featured.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
padding: 100px 0;
}
.slogan-wrapper {
background: #fff;
padding: 80px 0 0 40px;
margin-top: 70px;
}
.slogan-text > h1 {
font-size: 3.375rem;
font-weight: 900;
letter-spacing: 5px;
color: #373f48;
}
.slogan-text {
padding: 100px 70px 100px 0;
position: relative;
background: #fff;
z-index: 1;
}
<div class="header">
<div class="slogan-wrapper grid">
<div class="slogan">
<div class="slogan-text">
<h1>Hustle, Loyalty, Respect</h1>
</div>
</div>
</div>
This is what I wanted exactly and its a full width header
Did you notice that the class 'span' div is closed with a p tag? If you wanted to put the width there then that would be the problem.
Change the below code in CSS file and try once.
.header {
display: flex;
flex-direction: column;
background-image: url('https://www.rj-investments.co.uk/wp-content/uploads/2018/02/Home-Featured.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
padding: 100px 0;
}
.slogan-wrapper {
margin-top: 70px;
}
.slogan-text > h1 {
font-size: 3.375rem;
font-weight: 900;
letter-spacing: 5px;
color: #373f48;
background-color: #fff;
padding: 80px 40px;
width: auto;
max-width: 319px;
}
.slogan-text {
padding: 100px 30px 100px 0;
position: relative;
z-index: 1;
}

Issue with Flexbox Height Growth

The issue I am having is with my Flexbox growing in height when I enter content inside of it. I am not 100% sure why this is happening, but I believe it has something to do with it not being in an absolute position and thus keeping its height property.
Included is the CodePen where I have the HTML and CSS setup for the Flexbox style site that I am making (Also included the Snippet below) Here is so info about it
body p {
color: white;
font-size: 30px;
margin-top: 10px !important; }
.home-wrap {
display: flex;
min-height: 100vh;
justify-content: center;
transition: background 1.5s ease-in-out; }
.home-sections {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 775px;
max-width: 775px; }
.home-sections section {
border-radius: 20px;
border: 3px solid white;
overflow: hidden; }
.home-sections .flex {
display: flex;
flex-direction: row; }
.home-sections .flex--center {
justify-content: center; }
.col-1 {
text-align: center; }
.alignTop {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 100%;
align-items: flex-start;
transition: opacity 1.5s ease-in-out; }
.alignCenter {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
position: relative;
width: 50%; }
.alignBottom {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 100%;
align-items: flex-end;
transition: opacity 1.5s ease-in-out; }
section.about {
position: absolute;
width: 100%;
height: 220%;
left: 100%;
box-shadow: -6px 6px 8px rgba(0, 0, 0, 0.6);
z-index: 1;
transition: transform 1.5s ease-in-out;
animation: enticing-grow 2s 2;
background-color: #CB7E15; }
section.about .displayB {
display: block;
text-align: center; }
section.about .displayB h1 {
margin-top: 10px;
text-align: center;
font-size: 30px;
text-shadow: 5px 5px 8px white; }
section.about .displayB p {
font-size: 16px; }
section.about .mike-faq {
display: flex;
opacity: 0;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
max-width: 100%;
transition: all 1.5s ease-in-out; }
section.setup {
width: calc(55% - 6px);
height: 80%;
box-shadow: -8px 8px 8px rgba(0, 0, 0, 0.6);
background-color: #004EFF; }
section.social {
width: calc(45% - 6px);
height: 55%;
box-shadow: 8px 8px 8px rgba(0, 0, 0, 0.6);
opacity: 0.5;
transition: all 1s ease-in-out;
background-color: #585656; }
section.social:hover {
opacity: 1;
transform: scale(1.5);
z-index: 2; }
section.social .displayB {
display: block; }
section.social .displayB p {
text-align: center;
margin: 10px; }
section.social .social-wrap {
display: flex;
flex-direction: row;
max-width: 100%;
justify-content: space-around; }
section.social .social-wrap .twitter-logo {
background-image: url(/assets/img/twitter-logo.gif);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #1DA1F2; }
section.social .social-wrap .email-logo {
background-image: url(/assets/img/gmail-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #E70F10; }
section.social .social-wrap .facebook-logo {
background-image: url(/assets/img/facebook-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 10px 5px #3C5A98; }
section.social .social-wrap .github-logo {
background-image: url(/assets/img/github-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #E04006; }
section.twitch {
width: calc(55% - 6px);
height: 80%;
box-shadow: -8px -8px 8px rgba(0, 0, 0, 0.6);
background-color: #5A3E85; }
section.twitch h1 {
margin-top: 10px;
font-size: 30px;
text-align: center; }
section.twitch p {
font-size: 16px; }
section.twitch .displayB {
display: block;
text-align: center; }
.button {
color: #5A3E85; }
section.webdesign {
width: calc(45% - 6px);
height: 53%;
box-shadow: 8px -8px 8px rgba(0, 0, 0, 0.6);
background-color: #1F843A; }
section.youtube {
position: absolute;
width: 95%;
height: 140%;
margin-right: 5px;
box-shadow: -8px 0 8px rgba(0, 0, 0, 0.6);
transition: opacity 1.5s ease-in-out;
background-color: #CC181E; }
<div class="home-wrap">
<div class="home-sections">
<div class="alignTop">
<section class="twitch">
<div class="flex flex--center displayB">
<h1>Twitch</h1>
<!-- <p>I've been livestreaming on Twitch since it's days as Justin.tv - I plan to pick it back up again once I can figure out a schedule</p> -->
</div>
</section>
<section class="webdesign">
<div class="flex flex--center">
<p>Web Design</p>
</div>
</section>
</div>
<div class="alignCenter">
<section class="youtube">
<div class="flex flex--center">
<P>YouTube</P>
</div>
</section>
<section class="about grown">
<div class="flex flex--center displayB">
<h1>What's Going on, Mike here, and Welcome to my Site!</h1>
<p>I'm your typical 26 year old nerd, who loves computers, video games, pretty much anything tech. Along with that, I have a ton of hobbies that range from playing music to stock investments. </p>
<p>I've always been interested in, and worked on my web design skills, but it wasn't until the past few months where I decided this is what I am passionate about.</p>
<p>With that said, click around the site to learn more about me. All panels are expandable clickable which will allow you to learn more about "Mike" and who I am!</p>
<div class="mike-faq">
<p>FAQ 1</p>
<p>FAQ 2 </p>
<p>FAQ 3</p>
<p>FAQ 4</p>
</div>
</div>
</section>
</div>
<div class="alignBottom">
<section class="setup">
<div class="flex flex--center">
<p>Setup</p>
</div>
</section>
<section class="social">
<div class="flex flex--center displayB">
<p>Social</p>
<div class="social-wrap">
<div class="twitter-logo"></div>
<div class="email-logo"></div>
<div class="facebook-logo"></div>
<div class="github-logo"></div>
</div>
</div>
</section>
</div>
</div>
1 - I have a wrapping div around the site content so I can control the flow and background of the back
2 - I have another wrapping div for each "Row" of Flexbox so I can have them align in different areas (Top is aligned Flex-Start, Center is aligned Flex-Center and Bottom is aligned Flex-Bottom)
3 - The 2 Center Flexboxes (YouTube and About) are set with Absolute position so I am able to have the "About" section grow out and overlap the top and bottom sections.
4 - I have all the fleboxes set with % height and width so they will scale with the window value.
5 - Inside of each FlexBox section, I have a container so that I can manipulate the content and move it around so it fits within their parent flexbox.
Now, I am not 100% sure if all the nesting and parent/child elements is the best way to handle what I am trying to do, but I haven't been able to visualize it any other way and get it work (outside of the way I am doing it).
So - to go over it again, inside of the "Twitch: panel I have a <p> section that when I uncomment, the flexbox will grow in height, rather than remain the same. However, in the "About" section, this doesn't happen. The only difference I am able to see is that the "About" section is position: absolute.
You can play around by giving alignTop, alignCenter and alignBottom heights.
http://codepen.io/anon/pen/GWEgMK : try commenting in and out what you said then find the adequates values for heights you are happy with.
.alignTop {
height:33%;}
.alignCenter {
height:25%;}
.alignBottom {
height:20%;}
Not sure that's exactly what you want but to be honnest there is way too much clutter in your codepen for us to really want to try :) Are the animations even relevant ?
rather than % heights you may want to let flexbox handle the heights for you, as in grow to the viewport as it is designed to do but then use a max-height with a vh unit rather than a % value (like max-height: 75vh instead of max-height:75%). vh uses the viewport to scale not the parent div.