I would like to have my navigation bar elements centered.
As of now, I have got three <li> elements inside <ul>.
Two based on images and one is text
Can anyone help me get this centered or point out why it is not working for me ?
I have ignored the JavaScript as my focus is on indentation.
<div class = "navigationBar">
<ul>
<li><button id="back" onclick="myFunction()"><img src="./img/previous.png"></button> </li>
<li><div id ="currentFileString"> <h2>2/4<h2></div></li>
<li><button id="next"><img src="./img/next.png"></button></li>
</ul>
</div>
CSS:
#header{
font-family: "Al Bayan";
}
.jumbotron{
padding-top: 10px;
padding-bottom: 0px;
text-align: center;
}
.navigationBar{
height: 80px;
padding-bottom: 10px;
align-content: center;
margin : 0 auto;
display: inline;
text-align: center;
vertical-align: center;
}
button{
border: none;
background: none;}
ul {
display: inline;
margin: 0 auto;
/*text-align: center;*/
list-style-type: none;
padding: 10px;
text-align: center;
}
li {
display: inline-block;
text-align:center;
}
.table-striped
{
width: 60%;
}
#tableLeft{
float :left;
width: 40%;
}
#tableright{
float: right;
width: 40%;
}
The answer below. Try this
#header{
font-family: "Al Bayan";
}
.jumbotron{
padding-top: 10px;
padding-bottom: 0px;
text-align: center;
}
.navigationBar{
height: 80px;
padding-bottom: 10px;
align-content: center;
margin : 0 auto;
/*display: inline;*/
text-align: center;
vertical-align: center;
}
button {
border: none;
background: none;}
ul {
display: inline;
margin: 0 auto;
/*text-align: center;*/
list-style-type: none;
padding: 10px;
text-align: center;
}
li {
display: inline-block;
text-align:center;
}
.table-striped
{
width: 60%;
}
#tableLeft{
float :left;
width: 40%;
}
#tableright{
float: right;
width: 40%;
}
<div class = "navigationBar">
<ul>
<li><button id="back" onclick="myFunction()"><img src="https://cdn4.iconfinder.com/data/icons/flat-black/128/prev.png" width="20"></button> </li>
<li><div id ="currentFileString"> <h2>2/4<h2></div></li>
<li><button id="next"><img src="https://cdn4.iconfinder.com/data/icons/flat-black/512/next.png" width="20"></button></li>
</ul>
</div>
Related
I am trying to practice designing an online shop landing page, and I am taking inspiration from Urban Outfitters. I am trying to get the orange promo part to look the same as Urban Outfitters.
I have tried justify-content: center and space-around, or also using padding but that is not very responsive.
Codepen here.
*{
margin: 0px;
padding: 0px;
border-sizing: border-box;
}
#promo{
background-color: #F5C793;
display: flex;
align-items: center;
min-height: 50px;
justify-content: space-around;
}
.promo-link{
color: #222;
text-decoration-color: #222;
}
nav{
display: flex;
border-bottom: 0.3px solid #d3d3d3;
min-height: 40px;
align-items: center;
justify-content: center;
}
.nav-links{
display: flex;
list-style: none;
padding-left: 20px;
}
.nav-links li{
padding-left: 15px;
padding-right: 15px;
}
nav a{
text-decoration: none;
color: #767676;
}
nav a:hover{
color: #b2b2b2;
border-bottom: 1px solid black;
}
.logo{
color: #30336b;
text-transform: uppercase;
padding-left: 50px;
}
.landing-body{
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
display:inline;
}
.landing-page{
display: grid;
grid-template-columns: 49% 2% 49%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
.three-div{
display: grid;
grid-template-columns: 32% 2% 32% 2% 32%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
img{
display: inline;
opacity: 1.0;
padding-top: 10px;
width: 100%;
}
img:hover{
opacity: 0.8;
}
<div id="promo">
<p>everything you love, all in one place.</p>
<h3 class="center">MOST ♥ LIKED </h3>
<p>shop</p>
</div>
<nav>
<div class="logo">
<h2>Giants & Dwarfs</h2>
</div>
<ul class="nav-links">
<li id="about">About</li>
<li id="womens">Women's</li>
<li id="mens">Men's</li>
<li id="sale">Sale</li>
</ul>
</nav>
<div class="landing-page">
<img src="https://images.ctfassets.net/q602vtcuu3w3/7rnjSHqBEcgbtJ2pZqZarm/c32a5cbe533a8aab72aee54689ddb7e3/190617-WK3-WGW-4-Update.jpg">
<a></a>
<img src="https://images.ctfassets.net/q602vtcuu3w3/6vo26Ry1p3rcvSURCYBoJH/2fdc52ccb0ee69352d8e02ff905d592a/190603-WK1-LGW-1.jpg">
</div>
<div class="three-div">
<a href="#">
<img src="https://images.ctfassets.net/q602vtcuu3w3/7btvNrhUWJrd5UWYSRHtJr/43f9ce8f23d39c839f9b0e34991d97cc/190603-WK1-MGW-5.jpg">
</a>
<a></a>
<a href="#">
<img src="https://images.ctfassets.net/q602vtcuu3w3/5674zBs4G9hFqVyg2ceT6y/83fd495152f58a7bd12e64d68e541dcd/190617-WK3-HGW-7.jpg">
</a>
<a></a>
<a href="#">
<img src="https://images.ctfassets.net/q602vtcuu3w3/3Rz4KD78yXurQYIyqx6oyC/be018c5eeecd2df0a81471bb81177d8d/190617-WK3-WGW-7.jpg">
</a>
</div>
<div class="exclusives">
</div>
Trying to replicate this, top orange section
I am not a CSS expert by any stretch, but I have played around a bit with it. Have you tried using the following options?
padding-right: 15px;
padding-left: 15px;
margin-left: 1%;
Padding adds space to the left or to the right of your object. Margin adds space around your object. Either can be expressed as pixels or percentage. I have often found percentages to be more reliable for expected output than pixels, but again, I am not an expert so it could be my own unfamiliarity at work there.
For more detail: https://www.w3schools.com/cssref/pr_padding.asp
Hope this helps - happy coding to you!
You can use margins with flexbox, pretty much like align-self with much more control.
#promo {
background-color: #F5C793;
display: flex;
align-items: center;
min-height: 50px;
}
.left {
margin-left: auto;
}
.center {
margin: 0 20px;
}
.right {
margin-right: auto;
}
<div id="promo">
<p class="left">everything you love, all in one place.</p>
<h3 class="center">MOST ♥ LIKED </h3>
<p class="right">shop</p>
</div>
Force your inner elements to display as inline block, add some padding to your center element and flip your promo class from flex to block.
in the below example there are 2 new class (sideMe and sideMeCenter) and a mod to your display property in promo
add the classes to the contained promo elements and should be good to go
.sideMe {
display: inline-block;
margin:10px
}
.sideMeCenter {
padding: 0 40px;
}
*{
margin: 0px;
padding: 0px;
border-sizing: border-box;
}
#promo{
background-color: #F5C793;
display: block;
align-items: center;
min-height: 50px;
justify-content: space-around;
text-align:center;
}
.promo-link{
color: #222;
text-decoration-color: #222;
}
nav{
display: flex;
border-bottom: 0.3px solid #d3d3d3;
min-height: 40px;
align-items: center;
justify-content: center;
}
.nav-links{
display: flex;
list-style: none;
padding-left: 20px;
}
.nav-links li{
padding-left: 15px;
padding-right: 15px;
}
nav a{
text-decoration: none;
color: #767676;
}
nav a:hover{
color: #b2b2b2;
border-bottom: 1px solid black;
}
.logo{
color: #30336b;
text-transform: uppercase;
padding-left: 50px;
}
.landing-body{
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
display:inline;
}
.landing-page{
display: grid;
grid-template-columns: 49% 2% 49%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
.three-div{
display: grid;
grid-template-columns: 32% 2% 32% 2% 32%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
img{
display: inline;
opacity: 1.0;
padding-top: 10px;
width: 100%;
}
img:hover{
opacity: 0.8;
}
.exclusives-title{
padding-top: 20px;
text-align: center;
display: grid;
}
.exclusives-title h2{
font-weight: 100;
padding-bottom: 5px;
}
.exclusives{
grid-template-columns: 14% 3.2% 14% 3.2% 14% 3.2% 14% 3.2% 14% 3.2% 14%;
overflow: hidden;
margin-left: 20px;
margin-right: 20px;
}
<div id="promo">
<p class ="sideMe">everything you love, all in one place.</p>
<h3 class="center sideMe sideMeCenter">MOST ♥ LIKED </h3>
<p class="sideMe">shop</p>
</div>
bob i {font-size: 10px} shows a neat horizontal block, and the name titles are aligned. When I increase the font-size for bob i to 30px, then the two spans are not neatly horizontally aligned anymore. The icon is not that big so why does it make the bob span block blow up? Is it possible to have bob i {font-size: 40px} and keep everything neatly horizontally aligned?
.joe span
{
display: block;
padding: 20px;
text-align: left;
}
.pete
{
width: 30%;
float: left;
background-color: green;
}
.bob
{
width: 10%;
float: left;
background-color: blue;
}
.bob i {
font-size: 30px;
padding-left: 10%;
}
<div class="wrapper"><div class="joe"><span class="pete">Pete</span>
<span class="bob">Bob<i class="icon">#</i></span>
</div></div>
Just change these class property
.joe span {
display: flex;
align-items: center;
padding: 20px;
}
.bob i {
font-size: 40px;
padding-left: 10%;
line-height: 0;
}
.joe span {
display: flex;
align-items: center;
padding: 20px;
}
.pete
{
width: 30%;
float: left;
background-color: green;
}
.bob
{
width: 10%;
float: left;
background-color: blue;
}
.bob i {
font-size: 40px;
padding-left: 10%;
line-height: 0;
}
<div class="wrapper"><div class="joe"><span class="pete">Pete</span>
<span class="bob">Bob<i class="icon">#</i></span>
</div></div>
I am using an inline list as a nav menu, and I would like the hyperlink/list item to take up the full height of the container with the label vertically positioned in the center of the container. Here is what I have:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {} #top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>
Any other suggestions you have with any of this is greatly appreciated.
You need to add both height and line-height to the links, and also make sure they are either display: block or display: inline-block. Note that inline-block would be preferred:
#top-nav-container li a {
height: 50px;
line-height: 50px;
display: inline-block;
}
Note that on small screens, the Stuff Here... div would get cut off due to having a current width of 250px. Simply turn this down to say 50px (or however wide your container would actually be):
#top-nav-container .nav-right {
width: 50px;
}
I've created a fiddle showing this here.
Hope this helps! :)
You need to modify your CSS a little, see the following snippet:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {
/* all below rules were added*/
position: absolute;
line-height: 50px;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
#top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
/* all below rules were added*/
height: 50px;
line-height: 50px;
display: inline-block;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>
I'm creating a match list using ul and li tags. However i want to set some spans to a fixed width and then apply rest of the spans to the equal rest width. In my example there are 3 spans with a width 10px. I want the first team and second team classes to fill the rest of the width how can i do this using percentages?
.match-list {
padding: 0;
list-style-type: none;
}
.list-item {
list-style: none;
margin-bottom: 9px;
}
.list-item .image-col {
width: 50px;
float: left;
}
.list-item .empty-col {
width: 50px;
text-align: right;
float: left;
}
.list-item .time-col {
width: 50px;
text-align: center;
float: left;
}
.list-item .first-team {
text-align: right;
float: left;
}
.list-item .second-team {
float: left;
text-align: left;
}
<div>
<ul class="match-list">
<li class="list-item">
<span class="image-col">img</span>
<span class="first-team">First team</span>
<span class="time-col">12:00</span>
<span class="second-team">Second team</span>
<span class="empty-col">empty</span>
</li>
</ul>
</div>
You could use flexbox
CSS
.list-item {
list-style: none;
margin-bottom: 9px;
display:flex;
direction:row;
}
.list-item .first-team {
order:1;
flex-grow:2;
text-align: right;
float: left;
background:#d7d7d7;
text-align:center;
}
.list-item .second-team {
order:2;
flex-grow:2;
float: left;
text-align: left;
background:#a7a7a7;
text-align:center;
}
Check it on Codepen
If you can remove those float properties, you could use some table tricks on your layout, like this:
.match-list {
padding: 0;
list-style-type: none;
}
.list-item {
list-style: none;
margin-bottom: 9px;
}
/*added stuff*/
.list-item {
display: table;
width: 100%;
}
.list-item > span {
display: table-cell;
}
.list-item .image-col {
width: 50px;
}
.list-item .empty-col {
width: 50px;
text-align: right;
}
.list-item .time-col {
width: 50px;
text-align: center;
}
.list-item .first-team {
text-align: center;
}
.list-item .second-team {
text-align: center;
}
<div>
<ul class="match-list">
<li class="list-item">
<span class="image-col">img</span>
<span class="first-team">First team</span>
<span class="time-col">12:00</span>
<span class="second-team">Second team</span>
<span class="empty-col">empty</span>
</li>
</ul>
</div>
you can do this with css calc():
.list-item .first-team {
width: calc(50% - 150px);
text-align: right;
float: left;
}
.list-item .second-team {
width: calc(50% - 150px);
float: left;
text-align: left;
}
example: http://jsfiddle.net/qqu2448n/
I have a div that's inside a float:left div and it doesn't want to vertically align. I thought I could completely fill the floated div with the inner div and set that one to display: table-cell, but it doesn't seem to want to both FILL the div and allow this display?
JSFiddle Here
<div id="tabs-3" aria-labelledby="ui-id-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="true" aria-hidden="false" style="">
<div id="DivToCenter">
<div id="ButtonContainer">
<ul>
<li><div class="TemplateButton">Report an Issue</div></li>
<li><div class="TemplateButton">Report an Issue</div></li>
<li><div class="TemplateButton">Report an Issue</div></li>
<li><div class="TemplateButton">Report an Issue</div></li>
</ul>
</div>
</div>
</div>
Styling:
#tabs-3 { /* Tab Content Panel (Right Panel)*/
float: left;
min-height: 300px; /* How tall is our tab box, minimum?*/
text-align: center;
background-color: pink;
}
#DivToCenter {
width: 100%;
height: 100%;
background: red;
display: table-cell;
vertical-align: middle;
text-align: center;
}
#ButtonContainer {
width: 100%;
overflow: auto;
padding-top: 10px;
padding-bottom: 10px;
background: green;
display: table-cell;
vertical-align: middle;
text-align: center;
}
#ButtonContainer > ul {
padding: 0;
margin: 0;
display: inline-block;
}
#ButtonContainer > ul > li {
display: inline-block; /*Puts the buttons in a line*/
}
.TemplateButton {
padding-left: 5px;
padding-right: 5px;
}
.ui-tabs-panel.ui-widget-content .TemplateButton > a {
/* SHAPE */
width: 119px;
height: 119px;
padding: 15px;
margin-left: 3px;
margin-right: 3px;
border: 1px solid white;
border-radius: 15px;
-moz-border-radius: 15px;
/* ALIGNMENT */
display: table-cell;
vertical-align: middle;
text-align: center;
/* STYLING */
font-weight: bold;
font-size: 1.25em;
color: white;
background-color: #0c428f;
}
.ui-tabs-panel.ui-widget-content .TemplateButton > a:hover {
background-color: #6795bb;
}
Just add display: table; to #tabs-3
Updated Demo