So basically I want my navigation bar to be fixed when I scroll the page down. But by changing its position from absolute to fixed, the links seem to overlap each other. Margin and Padding aren't working. How can I make them fixed and give some gap between each link? If there is something wrong with my code please correct me.
HTML
.container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: repeat(12, 1fr);
width: 500px;
height: 500px;
grid-gap: 10px;
background-color: white;
width: 100%;
height: 1500px;
justify-content: center;
}
span {
font-size: 30px;
cursor: pointer;
}
#elem_1 {
background-color: #F7F7F7;
grid-column: 1 / -1;
grid-row: 1 / 2;
width: 100%;
}
#elem_1>img {
width: 2.3vw;
height: 4vh;
position: relative;
left: 220px;
bottom: 9px;
}
#elem_1>h1 {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: #505050;
position: relative;
left: 120px;
top: 30px;
}
nav a {
position: sticky;
right: 200px;
float: left;
margin-left: 20px;
text-decoration: none;
text-transform: uppercase;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-weight: 800;
color: grey;
}
#list_item_1 {
margin: 20px;
padding: 20px;
}
#nav_bar {
font-size: 20px;
}
nav a:hover {
background-color: pink;
}
nav {
display: block;
position: absolute;
bottom: 910px;
left: 1500px;
width: 100%;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
margin-bottom: 5px;
margin: 12px;
}
#three_bars {
display: none;
}
#three_bars:checked~nav {
display: block;
}
#three_bars_label {
position: fixed;
right: 35px;
top: 35px;
}
#elem_2 {
background-color: greenyellow;
grid-column: 1 / -1;
grid-row: 2 / 3;
}
#elem_3 {
background-color: aliceblue;
grid-column: 1 / 9;
grid-row: 3 / 12;
}
#elem_4 {
background-color: antiquewhite;
grid-column: 9 / -1;
grid-row: 3 / 12;
}
#elem_5 {
background-color: aquamarine;
grid-column: 1 / -1;
grid-row: 12 / -1;
}
<div class="container">
<div id="elem_1">
<h1>RDMC</h1>
<img src="./Images/HeartBeat.png">
<input type="checkbox" id="three_bars">
<nav>
<ul><span id="nav_bar">
<li class="list_item_1">Home</li>
<li class="list_item">Donate</li>
<li class="list_item">About us</li>
<li class="list_item">Contact</li></span>
</ul>
</nav>
<label for="three_bars" id="three_bars_label">
<span><i class="fas fa-bars"></i></span>
</label>
</div>
<div id="elem_2">Content</div>
<div id="elem_3">Payment</div>
<div id="elem_4">Address</div>
<div id="elem_5">Contact</div>
</div>
The main problem I could see with your css was the bottom:910px; and left:1500px positioning : you don't know how big the user's screen is going to be (I couldn't see the nav initially! ) I commented them out for a start, moved your margin for the list items into the list_item_1 css (shorthand for margin order is top right bottom left - clockwise - so I wrote it shorthand integrating the margin-bottom of 5px). Also, I added a display:inline-block; to your nav li.
Another (important) point to mention is that I moved your nav a code to AFTER your nav/ nav ul/nav li/ css, as css is read in the order it is written. As such, you should keep your css in logical order.
Hope this helps
.container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: repeat(12, 1fr);
width: 500px;
height: 500px;
grid-gap: 10px;
background-color: white;
width: 100%;
height: 1500px;
justify-content: center;
}
span {
font-size: 30px;
cursor: pointer;
}
#elem_1 {
background-color: #F7F7F7;
grid-column: 1 / -1;
grid-row: 1 / 2;
width: 100%;
}
#elem_1>img {
width: 2.3vw;
height: 4vh;
position: relative;
left: 220px;
bottom: 9px;
}
#elem_1>h1 {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: #505050;
position: relative;
left: 120px;
top: 30px;
}
#nav_bar {
font-size: 20px;
}
nav {
display: inline-block;
position: sticky;
/* bottom: 910px;*/
/*left: 1500px;*/
width: 100%;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
.list_item_1 {
margin: 12px 12px 5px 12px;
padding: 10px;
}
nav li {
display:inline-block;
/* margin: 12px 12px 5px 12px;*/
}
nav a {
display:inline-block;
float: left;
margin-left: 20px;
text-decoration: none;
text-transform: uppercase;
font-family: "Verdana", BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Open Sans, Helvetica Neue, sans-serif;
font-weight: 800;
color:#000000;
}
nav a:hover {
background-color: pink;
}
#three_bars {
display: none;
}
#three_bars:checked~nav {
display: block;
}
#three_bars_label {
position: fixed;
right: 35px;
top: 35px;
}
#elem_2 {
background-color: greenyellow;
grid-column: 1 / -1;
grid-row: 2 / 3;
}
#elem_3 {
background-color: aliceblue;
grid-column: 1 / 9;
grid-row: 3 / 12;
}
#elem_4 {
background-color: antiquewhite;
grid-column: 9 / -1;
grid-row: 3 / 12;
}
#elem_5 {
background-color: aquamarine;
grid-column: 1 / -1;
grid-row: 12 / -1;
}
<div class="container">
<div id="elem_1">
<h1>RDMC</h1>
<img src="./Images/HeartBeat.png">
<input type="checkbox" id="three_bars">
<nav>
<ul id="nav_bar">
<li class="list_item_1">Home</li>
<li class="list_item_1">Donate</li>
<li class="list_item_1">About us</li>
<li class="list_item_1">Contact</li>
</ul>
</nav>
<label for="three_bars" id="three_bars_label">
<span><i class="fas fa-bars"></i></span>
</label>
</div>
<div id="elem_2">Content</div>
<div id="elem_3">Payment</div>
<div id="elem_4">Address</div>
<div id="elem_5">Contact</div>
</div>
Related
I have a webpage where the css for the small and medium size work and display fine. my problem is with the large, everything is formatted correctly except that the page picture won't display. How do I fix this? Attached is the page layout and the full css. The error should be under the #media(min-width: 1024px)
header {
background-color: #002171;
color: #FFFFFF;
background-position: right;
background-repeat: no-repeat;
}
header a:link {
color: #FFFFFF;
text-decoration-line: none;
}
header a:visited {
color: #FFFFFF;
text-decoration-line: none;
}
header a:hover {
color: #90C7E3;
}
h1 {
margin-top: 0;
margin-bottom: 0;
text-align: center;
font-family: Georgia, serif;
letter-spacing: 0.25em;
padding-top: 0.5em;
padding-bottom: 0.5em;
}
* {
box-sizing: border-box;
}
nav {
font-weight: bold;
font-size: 120%;
padding: 0;
text-align: center;
}
nav li {
border-bottom: none;
}
nav a {
text-decoration: none;
}
section {
padding-left: 2em;
padding-right: 2em;
}
h2 {
color: #1976D2;
font-family: Georgia, serif;
text-shadow: 1px 1px 1px #CCCCCC;
}
h3 {
color: #000033;
font-family: Georgia, serif;
}
#media(min-width: 600px) {
nav ul {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
justify-content: space-around;
}
.content main {
display: grid;
grid-template-rows: auto;
grid-template-columns: 1fr 1fr 1fr;
}
h2 {
grid-row: 1 / 2;
grid-column: 1 / 5;
}
section {
grid-row: 2 / 3;
grid-column: auto;
}
#special {
grid-row: auto;
grid-column: 1 / 5;
}
footer {
grid-row: auto;
grid-column: 1 / 5;
}
}
#media(min-width: 1024px) {
nav ul {
flex-direction: column;
padding-top: 1em;
}
nav {
text-align: left;
padding-left: 1em;
padding-right: 1em;
grid-row: 2/3;
grid-column: 1/2;
}
main {
grid-row: 2/3;
grid-column: 2/3;
}
footer {
grid-row: 3/4;
grid-column: 2/4;
}
header {
grid-row: 1/2;
grid-column: 1/4;
}
#wrapper {
margin: auto;
width: 80%;
border: #00008B;
box-shadow: 1px 1px 1px;
display: grid;
grid-row: 3/3;
grid-column: 2/2;
}
}
}
main ul {
list-style-image: url('marker.gif');
font-family: Georgia, serif;
}
nav ul {
list-style: none;
margin: 0;
padding-left: 0;
font-size: 1.2em;
}
nav a:link {
color: #5C7FA3;
}
nav a:visited {
color: #344873;
}
nav a:hover {
color: #A52A2A;
}
body {
font-family: Helvetica;
background-color: #EAEAEA;
color: #666666;
}
main {
background-color: #FFFFFF;
padding-top: 1px;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 30px;
overflow: auto;
display: block;
}
dt {
color: #002171;
}
#wrapper {
background-color: #90C7E3;
background-image: linear-gradient(#FFFFFF, #90C7E3);
}
#homehero {
background-image: url('coast2.jpg');
height: 300px;
background-size: 100% 100%;
background-repeat: no-repeat;
}
#yurthero {
background-image: url('yurt.jpg');
height: 300px;
background-size: 100% 100%;
background-repeat: no-repeat;
}
#trailhero {
background-image: url('trail.jpg');
height: 300px;
background-size: 100% 100%;
background-repeat: no-repeat;
}
.resort {
font-weight: bold;
color: #1976D2;
}
footer {
background-color: #FFFFFF;
font-family: Georgia, serif;
font-size: 75%;
font-style: italic;
text-align: center;
padding: 2em;
}
#contact {
font-size: 90%;
}
<div id="wrapper">
<header>
<h1>Pacific Trails Resort</h1>
</header>
<nav>
<ul>
<li>Home</li>
<li>Yurts</li>
<li>Activities</li>
<li>Reservations</li>
</ul>
</nav>
<div id="homehero">
</div>
<main>
<h2>Enjoy Nature in Luxury</h2>
<p><span class="resort">Pacific Trails Resort</span> offers a special lodging experience on the California North Coast with panoramic views of the Pacific Ocean. Your stay at Pacific Trails Resort includes a sumptuously appointed private yurt and a cooked-to-order
breakfast each morning.</p>
<ul>
<li>Unwind in the heated outdoor pool and whirlpool</li>
<li>Explore the coast on your own or join our guided tours</li>
<li>Relax in our lodge while enjoying complimentary appetizers and beverages</li>
<li>Savor nightly fine dining with an ocean view</li>
</ul>
<div id="contact">
<span class="resort">Pacific Trails Resort</span><br> 12010 Pacific Trails Road <br> Zephyr, CA 95555<br>
<br> 888-555-5555
<br>
</div>
</main>
<footer>
Copyright © 2020 Pacific Trails Resort<br>
freed.nm#rhodesstate.edu
</footer>
</div>
From what I understand your image does not appear when the screen size is greater than 1024px. I made some changes to the code and got it to work as you wish, I think ...
I hope that's what you want
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pacific Trails Resort</title>
<!-- <link rel="stylesheet" href="pacific.css"> -->
<meta charset="utf-8">
<style>
header {
background-color: #002171;
color: #FFFFFF;
background-position: right;
background-repeat: no-repeat;
}
header a:link {
color: #FFFFFF;
text-decoration-line: none;
}
header a:visited {
color: #FFFFFF;
text-decoration-line: none;
}
header a:hover {
color: #90C7E3;
}
h1 {
margin-top: 0;
margin-bottom: 0;
text-align: center;
font-family: Georgia, serif;
letter-spacing: 0.25em;
padding-top: 0.5em;
padding-bottom: 0.5em;
}
* {
box-sizing: border-box;
}
nav {
font-weight: bold;
font-size: 120%;
padding: 0;
text-align: center;
}
nav li {
border-bottom: none;
}
nav a {
text-decoration: none;
}
section {
padding-left: 2em;
padding-right: 2em;
}
h2 {
color: #1976D2;
font-family: Georgia, serif;
text-shadow: 1px 1px 1px #CCCCCC;
}
h3 {
color: #000033;
font-family: Georgia, serif;
}
#media(min-width: 600px) {
nav ul {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
justify-content: space-around;
}
.content main {
display: grid;
grid-template-rows: auto;
grid-template-columns: 1fr 1fr 1fr;
}
h2 {
grid-row: 1 / 2;
grid-column: 1 / 5;
}
section {
grid-row: 2 / 3;
grid-column: auto;
}
#special {
grid-row: auto;
grid-column: 1 / 5;
}
footer {
grid-row: auto;
grid-column: 1 / 5;
}
}
#media(min-width: 1024px) {
nav ul {
flex-direction: column;
padding-top: 1em;
}
nav {
text-align: left;
padding-left: 1em;
padding-right: 1em;
grid-row: 2/3;
grid-column: 1/2;
}
main {
grid-row: 2/3;
grid-column: 2/3;
}
footer {
grid-row: 3/4;
grid-column: 2/4;
}
header {
grid-row: 1/2;
grid-column: 1/4;
}
#wrapper {
margin: auto;
width: 80%;
border: #00008B;
box-shadow: 1px 1px 1px;
display: grid;
grid-row: 3/3;
grid-column: 2/2;
}
}
}
main ul {
list-style-image: url('marker.gif');
font-family: Georgia, serif;
}
nav ul {
list-style: none;
margin: 0;
padding-left: 0;
font-size: 1.2em;
}
nav a:link {
color: #5C7FA3;
}
nav a:visited {
color: #344873;
}
nav a:hover {
color: #A52A2A;
}
body {
font-family: Helvetica;
background-color: #EAEAEA;
color: #666666;
}
main {
background-color: #90C7E3;
padding-top: 1px;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 30px;
overflow: auto;
display: block;
}
dt {
color: #002171;
}
#wrapper {
background-color: #90C7E3;
background-image: linear-gradient(#FFFFFF, #90C7E3);
}
#homehero {
height: 300px;
background-size: 100% 100%;
background-repeat: no-repeat;
}
#yurthero {
background-image: url('yurt.jpg');
height: 300px;
background-size: 100% 100%;
background-repeat: no-repeat;
}
#trailhero {
background-image: url('trail.jpg');
height: 300px;
background-size: 100% 100%;
background-repeat: no-repeat;
}
.resort {
font-weight: bold;
color: #1976D2;
}
footer {
background-color: #EAEAEA;
font-family: Georgia, serif;
width: 100%;
font-size: 75%;
font-style: italic;
text-align: center;
padding: 22px;
}
#contact {
font-size: 90%;
}
.details {
padding: 20px;
}
</style>
</head>
<body>
<div id="wrapper">
<header>
<h1>Pacific Trails Resort</h1>
</header>
<nav>
<ul>
<li>Home</li>
<li>Yurts</li>
<li>Activities</li>
<li>Reservations</li>
</ul>
</nav>
<div id="homehero">
<img src="coast2.jpg" alt="Coast2 Image">
</div>
<hr>
<div class="wrap">
<main>
<h2>Enjoy Nature in Luxury</h2>
<p><span class="resort">Pacific Trails Resort</span> offers a special lodging experience on the
California
North Coast with panoramic views of the Pacific Ocean. Your stay at Pacific Trails Resort includes a
sumptuously appointed private yurt and a cooked-to-order breakfast each morning.</p>
<ul>
<li>Unwind in the heated outdoor pool and whirlpool</li>
<li>Explore the coast on your own or join our guided tours</li>
<li>Relax in our lodge while enjoying complimentary appetizers and beverages</li>
<li>Savor nightly fine dining with an ocean view</li>
</ul>
<div id="contact">
<span class="resort">Pacific Trails Resort</span><br>
12010 Pacific Trails Road <br>
Zephyr, CA 95555<br>
<br>
888-555-5555<br>
</div>
</main>
</div>
<!-- <footer>
Copyright © 2020 Pacific Trails Resort<br>
freed.nm#rhodesstate.edu
</footer> -->
<div class="details">
<h2>Details</h2>
<ul>
<li>Dedicated</li>
<li>Fast</li>
<li>Secure</li>
</ul>
<br><br>
<h2>Social Networks</h2>
<ul>
<li>Facebook</li>
<li>Instagram</li>
<li>Twitter</li>
</ul>
<br><br>
<h2>Details</h2>
<ul>
<li>Dedicated</li>
<li>Fast</li>
<li>Secure</li>
</ul>
<br><br>
<h2>Social Networks</h2>
<ul>
<li>Facebook</li>
<li>Instagram</li>
<li>Twitter</li>
</ul>
<br><br>
</div>
</div>
<br><br>
<footer>
Copyright © 2020 Pacific Trails Resort<br>
freed.nm#rhodesstate.edu
</footer>
</body>
</html>
Please leave any comments if any problems arise, I would like to help
A section consists of a navigation group with elements floated to the sides, a center text group, and a background image. The section height was not manually set to fit the background image.
How do I go about vertically centering the text group? It is div.h1-container.
Plunkr: https://plnkr.co/edit/rSWgdfPQEbIeXbPh4wO1?p=preview
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
/* Global */
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
.clear {
clear: both;
}
ul {
margin: 0;
padding: 0;
}
section h2 {
line-height: 1.0;
}
.button_1 {
height: 34px;
background: tomato;
border: 0;
padding-left: 20px;
padding-right: 20px;
color: #ffffff;
width: 200px;
}
.showcase-nav a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
.showcase-nav {
padding-top: 30px;
margin-top: 10px;
float: right;
}
.showcase-nav li.social i {
padding: 0 4px;
}
.showcase-nav li {
display: inline;
padding: 0 20px 0 20px;
}
.showcase-branding {
float: left;
}
.showcase-branding h1 {
font-size: 26px;
margin: 0;
padding-top: 30px;
color: #fff;
}
.showcase-branding .highlight {
color: #e8491d;
font-weight: bold;
}
.showcase-nav a:hover {
color: #cccccc;
font-weight: bold;
}
.h1-container {
width: 70%;
margin: auto;
}
.h1-container h1 {
text-transform: uppercase;
text-align: center;
color: #fff;
}
.h1-container p {
width: 81%;
background: tomato;
margin: auto;
border-radius: 10px;
text-align: center;
color: #fff;
}
/* Showcase */
#showcase {
background: url('http://i68.tinypic.com/2j5jho4.png') no-repeat;
background-size: contain;
width: 100%;
display: inline-block;
position: relative;
margin: 0 auto;
}
#showcase:after {
padding-top: 51.46%;
display: block;
content: '';
}
#showcase .container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#showcase .h1-container h1 {
font-size: 55px;
margin-bottom: 10px;
}
#showcase p {
font-size: 20px;
padding: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<section id="showcase">
<div class="container">
<div class="showcase-branding">
<h1>Title</h1>
</div>
<nav class="showcase-nav">
<ul>
<li class="current">About</li>
<li>Contact</li>
<li class="social"><i class="fa fa-linkedin-square"></i><i class="fa fa-facebook-official"></i><i class="fa fa-twitter"></i></li>
</ul>
</nav>
<div class="clear"></div>
<div class="h1-container">
<h1>Text on line 1<br>text on line 2</h1>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum <i class="fa fa-caret-right"></i></p>
</div>
</div>
</section>
Given the current context there are two simple ways to go about this.
One way would be to give .h1-container display: flex, flex-direction: column, and justify-content: center.
Here is a jsfiddle.
However, if you were to do it this way, each element and every new element placed in .h1-container will end up being stacked vertically and centered vertically in relation to .h1-container, so it will appear as if the children elements are not centered if .h1-container is not properly centered.
Also remember that justify-content always positions the children elements relative to the direction of the flex-box. Therefore, if your flex-box direction is not explicitly set, and since the default is flex-direction: row, justify-content would position the children horizontally. align-items will always be the opposite of the flex-box's direction property.
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
/* Global */
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
.clear {
clear: both;
}
ul {
margin: 0;
padding: 0;
}
section h2 {
line-height: 1.0;
}
.button_1 {
height: 34px;
background: tomato;
border: 0;
padding-left: 20px;
padding-right: 20px;
color: #ffffff;
width: 200px;
}
.showcase-nav a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
.showcase-nav {
padding-top: 30px;
margin-top: 10px;
float: right;
}
.showcase-nav li.social i {
padding: 0 4px;
}
.showcase-nav li {
display: inline;
padding: 0 20px 0 20px;
}
.showcase-branding {
float: left;
}
.showcase-branding h1 {
font-size: 26px;
margin: 0;
padding-top: 30px;
color: #fff;
}
.showcase-branding .highlight {
color: #e8491d;
font-weight: bold;
}
.showcase-nav a:hover {
color: #cccccc;
font-weight: bold;
}
.h1-container {
width: 70%;
margin: auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.h1-container h1 {
text-transform: uppercase;
text-align: center;
color: #fff;
}
.h1-container p {
width: 81%;
background: tomato;
margin: auto;
border-radius: 10px;
text-align: center;
color: #fff;
}
/* Showcase */
#showcase {
background: url('http://i68.tinypic.com/2j5jho4.png') no-repeat;
background-size: contain;
width: 100%;
display: inline-block;
position: relative;
margin: 0 auto;
}
#showcase:after {
padding-top: 51.46%;
display: block;
content: '';
}
#showcase .container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#showcase .h1-container h1 {
font-size: 55px;
margin-bottom: 10px;
}
#showcase p {
font-size: 20px;
padding: 5px;
}
<body>
<section id="showcase">
<div class="container">
<div class="showcase-branding">
<h1>Title</h1>
</div>
<nav class="showcase-nav">
<ul>
<li class="current">About</li>
<li>Contact</li>
<li class="social"><i class="fa fa-linkedin-square"></i><i class="fa fa-facebook-official"></i><i class="fa fa-twitter"></i></li>
</ul>
</nav>
<div class="clear"></div>
<div class="h1-container">
<h1>Text on line 1<br>text on line 2</h1>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum <i class="fa fa-caret-right"></i></p>
</div>
</div>
</section>
</body>
The other way would be to give .container position: relative, and then give .h1-container position: absolute, top: 50%, and transform: translateY(-50%).
Positioning .container as relative allows you to absolutely position .h1-container in relation to .container as opposed to the entire document.
.container {
position: relative;
}
.h1-container {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Here is a jsfiddle.
The following is an inline version which won't display properly due to the dimensions of everything, but it has at least centered the .h1-container.
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
/* Global */
.container {
width: 80%;
margin: auto;
overflow: hidden;
position: relative;
}
.clear {
clear: both;
}
ul {
margin: 0;
padding: 0;
}
section h2 {
line-height: 1.0;
}
.button_1 {
height: 34px;
background: tomato;
border: 0;
padding-left: 20px;
padding-right: 20px;
color: #ffffff;
width: 200px;
}
.showcase-nav a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
.showcase-nav {
padding-top: 30px;
margin-top: 10px;
float: right;
}
.showcase-nav li.social i {
padding: 0 4px;
}
.showcase-nav li {
display: inline;
padding: 0 20px 0 20px;
}
.showcase-branding {
float: left;
}
.showcase-branding h1 {
font-size: 26px;
margin: 0;
padding-top: 30px;
color: #fff;
}
.showcase-branding .highlight {
color: #e8491d;
font-weight: bold;
}
.showcase-nav a:hover {
color: #cccccc;
font-weight: bold;
}
.h1-container {
width: 70%;
margin: auto;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.h1-container h1 {
text-transform: uppercase;
text-align: center;
color: #fff;
}
.h1-container p {
width: 81%;
background: tomato;
margin: auto;
border-radius: 10px;
text-align: center;
color: #fff;
}
/* Showcase */
#showcase {
background: url('http://i68.tinypic.com/2j5jho4.png') no-repeat;
background-size: contain;
width: 100%;
display: inline-block;
position: relative;
margin: 0 auto;
}
#showcase:after {
padding-top: 51.46%;
display: block;
content: '';
}
#showcase .container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#showcase .h1-container h1 {
font-size: 55px;
margin-bottom: 10px;
}
#showcase p {
font-size: 20px;
padding: 5px;
}
<body>
<section id="showcase">
<div class="container">
<div class="showcase-branding">
<h1>Title</h1>
</div>
<nav class="showcase-nav">
<ul>
<li class="current">About</li>
<li>Contact</li>
<li class="social"><i class="fa fa-linkedin-square"></i><i class="fa fa-facebook-official"></i><i class="fa fa-twitter"></i></li>
</ul>
</nav>
<div class="clear"></div>
<div class="h1-container">
<h1>Text on line 1<br>text on line 2</h1>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum <i class="fa fa-caret-right"></i></p>
</div>
</div>
</section>
</body>
Flexbox isn't working in Chrome or Safari but works fine in Firefox. The vertical images are expanding to not fit within their container, but in Firefox they're behaving as I want them to. Here is the code, any idea? Thanks.
body{ max-width: 1970px;
margin: 0 auto;
padding: 0 2%;
box-sizing: border-box;
padding-top: 100px;
}
a {
text-decoration: none;
font-family: 'Karla', sans-serif;
font-size: 1em;
letter-spacing: -0.03em;
}
img {
max-width: 100%;
}
/***********************************
HEADING
************************************/
header {
float: left;
position:fixed;
top:0;
width: 100%;
z-index: 99;
background-color: white;
}
h1 {
font-family: 'Giorgio Sans Web', sans-serif;
margin: 0 auto;
font-size:4.5em;
font-weight: 700;
font-style: normal;
font-stretch: normal;
}
h2 {
font-family: 'Giorgio Sans Web', sans-serif;
margin: 0 auto;
font-size:4em;
font-weight: 700;
font-style: normal;
font-stretch: normal;
line-height: 3em;
}
h3 {
font-family: 'Karla', sans-serif;
font-weight: 400;
font-size:1.3em;
margin: 0 0 1em 0;
}
h4 {
font-family: 'Giorgio Sans Web', sans-serif;
margin: 0 auto;
font-size:2.5em;
font-weight: 700;
letter-spacing:0.0625em;
font-style: normal;
font-stretch: normal;
}
h5 {
font-family: 'Karla', sans-serif;
font-weight: 700;
font-size: 0.75em;
line-height: 1.2em;
}
p {
font-family: 'Karla', sans-serif;
line-height: 1.5em;
font-size: 1.2em;
letter-spacing: -0.03em;
}
/***********************************
NAVIGATION
************************************/
nav {
/*text-align: center;
margin: 0 2%;
box-sizing: border-box;*/
background-color: white;
}
#nav-parent {
height:;
display:flex;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
padding: 10px 3%;
margin: 0 auto;
}
.nav-icon {
flex-basis:auto;
}
#logo {
flex-basis:auto;
box-sizing: border-box;
padding-left: 20px;
}
.contact-button {
flex-basis:auto;
}
nav li a {
padding:0;
}
/***********************************
SIDE NAV
************************************/
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 100;
top: 0;
left: 0;
background-color: #F3F3F3;
overflow-x: hidden;
transition: 0.5s;
padding-top: 20px;
}
#sidenav-content {
margin-left: 13px;
}
.sidenav a {
text-decoration: none;
color: #000;
display: block;
transition: 0.3s;
}
.sidenav a h4 {
overflow: hidden;
white-space: nowrap;
padding: 16px 8px 0px 6px;
color: #000;
display: block;
transition: 0.1s;
}
.sidenav p {
padding: 0px 8px 8px 26px;
font-size: 16px;
color: #000;
display: block;
transition: 0.3s;
width: 250px;
}
.slide-nav-link {
margin-top: 10px;
padding: 8px 8px 8px 26px;
line-height: 2.2em;
}
.slide-nav-social {
width: 150px;
height:50px;
margin-top: 20px;
margin-left: 26px;
}
.slide-nav-social a {
width:20px;
padding: 0 15px 0 0;
display: inline-block;
}
.sidenav a:hover, .offcanvas a:focus{
color: #6B00FF;
}
.sidenav .closebtn {
padding: 15px 8px 8px 26px;
font-size: 30px;
margin-left: 0px;
}
.closebtn a:hover {
color: #000;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
/***********************************
FOOTER
************************************/
footer {
font-size: 0.75em;
text-align: center;
clear: both;
padding-top: 50px;
color: #ccc;
}
.social-icon {
width:20px;
height: 20px;
margin: 0 5px;
}
/***********************************
PAGE: PORTFOLIO
************************************/
.gallery{
margin: 0 auto;
list-style: none;
padding-left: 0;
}
.gallery figure {
overflow: hidden;
float: left;
width: 48%;
margin: 1%;
z-index: 97;
position: relative;
float: left;
}
.gallery figcaption {
background: rgba(255,255,255,0.97);
display : flex;
align-items : center;
text-align: center;
color: white;
float: left;
position: absolute;
left: 0;
opacity: 0;
right: 0;
top: 0;
height:100%;
z-index: 98;
-webkit-transition: all 300ms;
-moz-transition: all 300ms;
transition: all 300ms;
-webkit-transition-delay: 100ms;
-moz-transition-delay: 100ms;
transition-delay: 100ms;
}
.gallery figcaption h3 {
width:100%;
text-align: center;
color:#000;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
.gallery li:hover figcaption {
opacity: 1;
}
/***********************************
PAGE: Project
************************************/
.project-gallery{
margin: 0 auto;
padding: 0 1.5%;
list-style: none;
}
.project-gallery img{
max-width: 100%;
margin: 1.5% 0;
}
.project-gallery hr {
margin: 40px 0;
border: none;
height: 3px;
background-color: #000;
}
.project-title {
max-width: 100%;
text-align: center;
padding-top: 40px;
}
.description-text {
display:inline;
}
.left-column-text {
width:30%;
margin-left: 5%;
margin-top: 8px;
display:inline-block;
vertical-align: top;
}
.left-column-text p {
margin: 10px 0 25px 0;
}
.left-column-text h5 {
margin-bottom: -5px;
}
.right-column-text {
width:50%;
margin: 0 5% 0 8%;
display:inline-block;
vertical-align: top;
}
.vertical-imgs {
display: -webkit-flex; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-flex; /* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display:flex;
justify-content: space-between;
margin: 1% 0;
}
.vertical-img-left {
box-sizing: border-box;
padding-right: 3%;
}
.vertical-img-right {
box-sizing: border-box;
}
.prev-next-buttons {
margin-right: -3.7%;
}
.prev-next-buttons a {
display: inline-block;
margin: 0;
box-sizing: border-box;
padding: 20px 5%;
}
.prev-button {
width:48%;
}
.next-button {
text-align: right;
width:48%;
}
/***********************************
PAGE: About
************************************/
.profile-photo {
display: block;
max-width: 150px;
margin: 0 auto 30px;
border-radius: 100%;
}
/***********************************
PAGE: CONTACT
************************************/
.contact-info {
list-style: none;
padding: 0;
margin: 0;
font-size: 0.9em;
}
.contact-info a {
display: block;
min-height: 20px;
background-repeat: no-repeat;
background-size: 20px 20px;
padding: 0 0 0 30px;
margin: 0 0 10px;
}
.contact-info li.mail a {
background-image: url('../img/mail.png')
}
.contact-info li.twitter a {
background-image: url('../img/twitter.png')
}
.contact-info li.phone a {
background-image: url('../img/phone.png')
}
/***********************************
COLORS
************************************/
/* site body */
body {
background-color: #fff;
color:#000;
}
/*green header
header {
background: #6ab47b;
border-color: #599a68;
}*/
/*nav background on mobile
nav {
background: #599a68;
}*/
/*logo text */
h1 {
color: #000;
}
/*link color*/
a {
color:#000
}
/*nav link colors*/
nav a, nav a:visited {
color: #000;
}
/* selected nav link colors*/
nav a.selected, nav a:hover {
color: #5513FE
}
/* selected prev next link colors*/
a h1.selected, a h1:hover {
color: #5513FE
}
a h4.selected, a h4:hover {
color: #5513FE
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cari Sekendur - MHG Modern Classic</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="fonts/1606-HQIULX.css">
<link href="https://fonts.googleapis.com/css?family=Karla:400,400i,700,700i" rel="stylesheet">
<link rel="stylesheet" href="css/main1.css">
<link rel="stylesheet" href="css/responsive.css">
<meta name="viewport" content= "width=device-width, initial-scale=1.0">
</head>
<body>
<header>
<nav>
<ul id="nav-parent">
<li class="nav-icon">
<span style="cursor:pointer" onclick="openNav()"
</span>
<img src="img/nav-icon.svg" class="nav-icon">
</li>
<li id="nav-icon">
<a href="index.html" id="logo">
<h1>CARI</h1>
</a>
</li>
<li class="nav-icon">
Contact
</li>
</ul>
</nav>
</header>
<div id="mySidenav" class="sidenav">
<div id="sidenav-content">
<img src="img/nav-icon-open.svg" class="nav-icon">
<div class= "slide-nav-link">
Work
About
Contact
</div>
<div class= "slide-nav-text">
<a href="index.html" id="logo">
<h4>CARI SEKENDUR</h4>
</a>
<p>Creating visual experiences that make the complex clear and the average exceptional.</p>
</div>
<div class= "slide-nav-social">
<img src="img/WNWlogo.svg">
<img src="img/linkedin-black.svg">
<img src="img/pinterest-black.svg">
</div>
</div>
</div>
<!--Click on the element below to open the side navigation menu.-->
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "350px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
<div class="wrapper">
<section class="project-gallery">
<div class="horiztonal-img">
<img src="img/mhg-zine/CARI_MHG_ZINE_1.gif" alt="">
</div>
<div class="project-title">
<h2>MORGANS HOTEL GROUP - MODERN CLASSIC ZINE</h2>
</div>
<hr>
<div class="description-text">
<div class="left-column-text">
<h5>STUDIO</h5>
<p>LMNOP Creative</p>
<h5>CREATIVE DIRECTION</h5>
<p>Leigh Nelson</p>
<h5>DESIGN</h5>
<p>Cari Sekendur, Leigh Nelson, Heidi Chisholm</p>
</div>
<div class="right-column-text">
<p> Morgans Hotel Group launched the global phenomenon of boutique hotels 20 years ago, and to celebrate their rich history they put together a campaign called The Modern Classic. Each of Morgans' properties has a design aesthetic that is unlike anything you've seen before, awe-inspiring and always over-the-top. So, to capture the essence of Morgans' brand, we concepted, designed, and printed a zine for them to distribute to hotel guests. This project was a print designer's dream, complete with gold-holographic foil, gold staples, fluorescent Pantone inks, collage, illustration, a tear-out poster, and even a little pack of temporary tattoos.
</p>
</div>
<hr>
</div>
<div class="horiztonal-img">
<img src="img/mhg-zine/CARI_MHG_ZINE_2.jpg" alt="">
</div>
<div class="vertical-imgs">
<img src="img/mhg-zine/CARI_MHG_ZINE_8.jpg" alt="" class="vertical-img-left">
<img src="img/mhg-zine/CARI_MHG_ZINE_5.jpg" alt="" class="vertical-img-right">
</div>
<div class="horiztonal-img">
<img src="img/mhg-zine/CARI_MHG_ZINE_7.jpg" alt="">
</div>
<div class="prev-next-buttons">
<a href="#" class="prev-button">
<h2>PREVIOUS</h2>
</a>
<a href="#" class="next-button">
<h2>NEXT</h2>
</a>
</div>
<hr class="bottom-hr" style="margin-top: 0px;">
</section>
<footer>
<p></p>
</footer>
</div>
</body>
</html>
use :
#nav-parent {
display:flex;
display: -webkit-flex;
-webkit-flex-flow: initial;
flex-flow: initial;
justify-content: space-between;
align-items: center;
padding: 10px 3%;
margin: 0 auto;
}
I have been having trouble centering the .content div in any device. In some devices, the .content is exactly centered but not in others. I use padding-top to push the .content down so it could be placed on the center of any device. What should I do to center the .content in any device using padding-top? Should I use Javascript in this kind of situation?
body {
margin: 0;
}
.whole {
height: 100vh;
background: #d44949;
}
header:after {
content: '';
display: table;
clear: both;
}
.logo {
font: 1.4em 'Open Sans',sans-serif;
color: #fcfcfc;
text-transform: uppercase;
float: left;
margin-left: 15px;
}
.logo > span {
font-style: italic;
color: #d8d8d8;
}
.header-nav {
float: right;
margin: 20px 15px 0 0;
}
.header-nav > a {
color: #fafafa;
text-decoration: none;
font: 1em 'Open Sans',sans-serif;
font-weight: 300;
}
.header-nav > a:not(:first-child) {
margin-left: 15px;
}
.header-nav > a:hover {
color: yellow;
}
.content {
display: flex;
flex-direction: column;
padding-top: calc(100vh / 2);
}
.content > img {
width: 200px;
height: 200px;
border-radius: 50%;
margin: auto;
}
.content-nav {
margin: auto;
padding-top: 20px;
}
.content-nav > a {
color: #fafafa;
text-decoration: none;
font: 1em 'Open Sans',sans-serif;
font-weight: 300;
}
.content-nav > a:not(:first-child) {
margin-left: 10px;
}
<div class="whole">
<header>
<h1 class="logo">Max<span>&</span>Spoon</h1>
<div class="header-nav">
Download
Docs
Tutorial
Reference
</div>
</header>
<div class="content">
<img src="http://emblemsbf.com/img/36593.jpg" alt="logo">
<div class="content-nav">
Home
Blog
Forum
Stuff
</div>
</div>
</div>
As you are already using flex you could remove the padding-top and add align-items: center; to your .content.
So your CSS for .content becomes:
.content {
display: flex;
flex-direction: column;
align-items: center;
}
Here's the updated snippet.
body {
margin: 0;
}
.whole {
height: 100vh;
background: #d44949;
}
header:after {
content: '';
display: table;
clear: both;
}
.logo {
font: 1.4em'Open Sans', sans-serif;
color: #fcfcfc;
text-transform: uppercase;
float: left;
margin-left: 15px;
}
.logo > span {
font-style: italic;
color: #d8d8d8;
}
.header-nav {
float: right;
margin: 20px 15px 0 0;
}
.header-nav > a {
color: #fafafa;
text-decoration: none;
font: 1em'Open Sans', sans-serif;
font-weight: 300;
}
.header-nav > a:not(:first-child) {
margin-left: 15px;
}
.header-nav > a:hover {
color: yellow;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
}
.content > img {
width: 200px;
height: 200px;
border-radius: 50%;
margin: auto;
}
.content-nav {
margin: auto;
padding-top: 20px;
}
.content-nav > a {
color: #fafafa;
text-decoration: none;
font: 1em'Open Sans', sans-serif;
font-weight: 300;
}
.content-nav > a:not(:first-child) {
margin-left: 10px;
}
<div class="whole">
<header>
<h1 class="logo">Max<span>&</span>Spoon</h1>
<div class="header-nav">
Download
Docs
Tutorial
Reference
</div>
</header>
<div class="content">
<img src="http://emblemsbf.com/img/36593.jpg" alt="logo">
<div class="content-nav">
Home
Blog
Forum
Stuff
</div>
</div>
</div>
I want to add a list item but it is deleted because I added in my css file display: inline-block, however I cant change this since this is crucial in aligning my content the way that I want. I tried alot of things, but it just won't show :L, anyone got any ideas? Here is the Fiddle:
http://jsfiddle.net/rupsdino1997/gtxe6ojo/1/
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
hr { /* taken from http://css-tricks.com/examples/hrs/ */
height: 30px;
border-style: solid;
border-color: black;
border-width: 1px 0 0 0;
border-radius: 20px;
}
hr:before { /* taken from http://css-tricks.com/examples/hrs/ */
display: block;
content: "";
height: 30px;
margin-top: -31px;
border-style: solid;
border-color: black;
border-width: 0 0 1px 0;
border-radius: 20px;
}
ul.listing {
list-style:armenian;
}
body {
margin: 0px;
color: #151515;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
background-color: #EFF5F8;
}
#slideshow {
position:relative;
right: 280px;
}
#slideshow IMG {
position:absolute;
top:0;
left:0;
z-index:8;
}
#slideshow IMG.active {
z-index:10;
}
#slideshow IMG.last-active {
z-index:9;
}
#wrapper {
width: 100%;
min-width: 740px;
max-width: 1000px;
margin-left: auto;
margin-right: auto;
border:#6627C9;
background-color:#E2CFAF;
padding-left: 17px;
padding-right: 17px;
}
#slideshow img {
min-width: 740px;
min-height: 400px;
}
#top {
overflow: hidden;
}
h1 {
font-size: 65px;
margin-top: 0px;
margin-bottom: 14px;
color: #3399DD;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
max-width: 100%;
text-align: center;
}
#mainimg img {
max-width: 100%;
padding-top: 2px;
padding-bottom: 2px;
}
h1{
color: #3399CC;
font-weight: 600;
font-size: 36px;
}
.centered {
margin-left: auto;
margin-right: auto;
}
footer {
padding-top: 2px;
padding-bottom: 2px;
padding-left: 2%;
background-color: #43a6cb;
color: #FFFFFF;
position: relative;
bottom: 0px;
}
a {
font-weight: bold;
text-decoration: none;
}
a:link {
color: #FF6600;
}
a:visited {
color: #FF944C;
}
#mainnav a:hover ,#mainnav a:active,#mainnav a:focus , #mainnav a.thispage{
color: #FFFFFF;
text-decoration: none;
background-color: #43A6CB;
}
#mainnav ul {
list-style-type: none;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#mainnav a {
width: 20%;
background-color: #4D4D4D;
text-align: center;
text-transform: uppercase;
color: #FFFFFF;
padding-top: 6px;
padding-bottom: 6px;
display: block;
float: left;
}
#wrapper #main .horizontal img {
height: 250px;
width: 200px;
margin-top: 15px;
}
#wrapper #main ul.horizontal li {
display: inline-block;
font-size: 16px;
padding: 1em;
text-align: justify;
vertical-align: top;
width: 50%;
}
ul.horizontal {
list-style:circle;
margin: 0;
padding: 0;
font-size: 0;
}
img{
display: block;
}
*
{
box-sizing: border-box;
}
#main {
padding-left: 10px;
paddin-right: 10px;
}
.listing {
display:list-item;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="wrapper">
<header id="top">
<h1 style="font-size:60px">L'Auberge De Napoleon III</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Features</li>
<li>Activities</li>
<li>Contact US</li>
<li>Pricing</li>
</ul>
</nav>
</header>
<article id="main">
<ul class="horizontal" style=" padding:0">
<li>
<div style="position:relative; left: 10px">
<p style="padding-bottom: 0pt; padding-top: 0pt; font-family:Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight:100px; position:relative; top:8px; color:#3D2E16; font-size:15px;">
<ul class="listing" style="padding-left:0px">
<li>Living Room</li>
<li>Library</li>
<li>oo</li>
<li>ff</li>
<li>ff</li>
<li>ff</li>
<li>ff</li>
<li>ff</li>
</ul>
</p>
</div>
</li>
<li>
<div id="slideshow">
<img src="http://upload.wikimedia.org/wikipedia/commons/1/1e/Stonehenge.jpg" width="1000">
<img src="http://upload.wikimedia.org/wikipedia/commons/1/1e/Stonehenge.jpg">
<img src="http://upload.wikimedia.org/wikipedia/commons/1/1e/Stonehenge.jpg" class="active">
</div>
</li>
</ul>
<hr width="80%">
<p style="margin: 0px 16px 30px 17px; font-family:Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight:100px; position:relative; left: 10px; color:#3D2E16; font-size:15px; padding-right: 20px; text-align:justify"> The house has been entirely renovated with respect for the original elements like stone walls, and wooden beams. This 5 bedroom house (sleeps 8) is a well equipped property. Situated in one of the most sunny regions of France it profits from a sunny, sheltered court yard and garage in the basement.
This comfortable property is based in the Languedoc-Roussillon region, famous for its recreational activities as here in Cathar country history meets nature. From the village you can reach famous historic towns such as Perpignan, Carcassonne and Narbonne within an hour. Felines is also close to the medieval village of Lagrasse, one of the “les plus beaux villages de France”. A drive to the sea or Spain equally takes you about an hour. Take advantage of your stay and visit some vintners, as Felines-Termenes is on the “Route des 20”, a local initiative of the wine growers of the Corbieres. With your family or with friends, you will appreciate the calm of this 180 sq.m. property. </p>
</article>
<footer>Powered By Ruben © 2015 </footer>
</div>