aligning the bottom bar elements - html

Hi I am trying to align the bottombar elements so that they are in 2 columns on the side of 102. I was wondering if there is a way to fix it as they are all floating on the right at the moment. I am a beginner html css programmer and I am not very experienced yet. Ill appreciate any help you can give me!
CSS
/*bottom navbar*/
.bottomnav{
width: 100%;
background-color: rgb(248, 138, 180);
display: flex;
flex-direction: row;
}
.navbarlogo2{
display: block;
margin-left: auto;
margin-right: auto;
width: 10%;
text-decoration: none;
}
/*bottombar*/
.nav {
display: flex;
flex-direction: row;
}
.left, .right {
flex: 1;
}
HTML
<div class="bottomnav">
<ul class="bottomlogo">
<li class="navbarimg2"><img class="navbarlogo2" src="img/LOGO.png"></li>
</ul>
<div class='nav'>
<div class='left'>
<ul>
<li>About Us</li>
<li>Affiliates</li>
</ul>
</div>
<div class='right'>
<ul>
<li>TOS</li>
</ul>
</div>
</div>
</div>
END RESULT
WANTED RESULT

I made things like that. CSS Grid is one of the new HTML5 standard you should take a look. In your case, use a grid is better choice against flex because you're looking for a table-like structure.
I choosed to split your needs in 2 parts:
Center your logo
Make a 2 columns grid for your links
Centering your logo
We need to center an element and prevent it to interfere with our incoming links grid. So we'll set our container with a position: relative and place the img tag in position: absolute. Note the image's top right bottom left properties are now relative to the first parent positioned as relative.
And so we only need to make some simple maths. Note the calc() function, we don't want to center the top left corner of your logo but the center. So we need to remove the half of the defined logo's width.
navbarlogo2 {
left: calc(50% - 60px);
}
Make a 2 columns grid for your links
In order make a grid, you have to display your container as grid and set its grid-template-columns to 1fr 1fr. You can translate fr with the word fraction. So here, we're asking for a row split in 2 fractions.
Because we want a place for our logo, we're adding a gap (grid-cap) in out container to make some space between our 2 columns.
Learn more about the fr unit here.
body {
margin:0
}
.bottomnav {
width: 100%;
background-color: rgb(248, 138, 180);
position: relative;
}
.navbarlogo2 {
display: block;
margin-left: auto;
margin-right: auto;
width: 120px;
text-decoration: none;
position: absolute;
filter: brightness(10);
top: 15px;
left: calc(50% - 60px) /*center top left corner then remove half logo width (120px)*/
}
/*bottombar*/
.nav {
display: grid;
grid-gap: 120px;
grid-template-columns: 1fr 1fr;
}
.nav ul {
padding-left: 0;
}
.nav ul li {
list-style: none;
text-align: center;
padding-left: 0;
}
.left,
.right {
flex: 1;
}
<div class="bottomnav">
<div class="bottomlogo">
<img class="navbarlogo2" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.svg">
</div>
<div class='nav'>
<div class='left'>
<ul>
<li>About Us</li>
<li>Affiliates</li>
</ul>
</div>
<div class='right'>
<ul>
<li>TOS</li>
<li>Fourth </li>
</ul>
</div>
</div>
</div>

Related

Center one div and have 2 other divs stay by it? [duplicate]

This question already has answers here:
Align 3 unequal blocks left, center and right
(4 answers)
Closed last month.
I have 3 divs that contain text. The text has different lengths, meaning that if I put these three divs into another div, if I justify-content: center this div, the middle one out of the three divs won't be in the center of the page.
What I want to achieve is to have the middle div in the center of the webpage and the first div to be to left of it and the third one to the right, with no space between (except padding).
Edit: I don't know if I maybe was unclear about what I am asking: I want to center .container-footer-3 but .footer-company ("Center") should be in the center of the page, not in the center of the div.
-> In other words, how do I center the parent div, containing all these 3 divs but not the center of the div to the center page, instead "Center" div to the center of the page?
.container-footer-3 .nav {
display: inline-table;
padding: 0 20px 0 20px;
}
.footer-nav {
display: flex;
justify-content: center;
}
.footer-company{
position: absolute;
left: 50%;
margin-left: -50px;
width: 100px;
height: 100px}
<div class="footer-nav">
<div class="container-footer-3">
<div class="footer-explore nav">
<h20>Left</h20>
<ul>
</ul>
</div>
<div class="footer-company nav">
<h20>Center</h20>
<ul>
</ul>
</div>
<div class="footer-socials nav">
<h20>RightRightRightRight</h20>
<ul>
</ul>
</div>
</div>
</div>
If you want to use flex, then you can make all three divs share the same width by adding flex-basis: 100% to the children within the flex container. I simplified your HTML to better show how it can be done. 100% just states that they are all equally treated. It's not like 100% of width.
You will then need to add an extra div inside .footer-explore if you want to align it to the right.
Do note, I added the outline to make the alignments more clear.
.footer-nav {
display: flex;
justify-content: center;
align-items: top;
}
.nav {
padding: 0 20px 0 20px;
flex-basis: 100%;
}
* {
outline: 1px solid grey;
}
<div class="footer-nav">
<div class="footer-explore nav">
<h20>Left</h20>
</div>
<div class="footer-company nav">
<h20>Center</h20>
</div>
<div class="footer-socials nav">
<h20>RightRightRightRight RightRightRightRight</h20>
</div>
</div>
You can also use a grid, and set the middle column to adapt to it's content, and the two divs on the side to fill up the rest of the space (using 1fr). Again, you need to add an extra div inside .footer-explore if you want to align it to the right. I added an outline here too for clarity.
.footer-nav {
display: grid;
grid-template-columns: 1fr min-content 1fr;
}
.nav {
padding: 0 20px 0 20px;
}
* {
outline: 1px solid grey;
}
<div class="footer-nav">
<div class="footer-explore nav">
<h20>Left</h20>
</div>
<div class="footer-company nav">
<h20>Center</h20>
</div>
<div class="footer-socials nav">
<h20>RightRightRightRight RightRightRightRight</h20>
</div>
</div>
There's already a lot of answers, but I figured I'd give my 2 cents seeing as none of the answers actually show an example where the leftmost and rightmost columns aren't expanded to full width.
In a grid-layout, you can define the 3 columns with:
grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
The first and the last column (left and right) will have their column stretch to fit its content width, while the layout stays a 3-column layout.
The middle column will just have a value of auto.
You can then specify each grid-item's positioning with justify-self, which works in both flex- and grid-layouts - I used flex in my example.
This solution isn't fully responsive, but you can specify e.g. a max-width-value on the grid-items which will make it responsive for most screens, not small screens such as mobile devices though.
.container-footer-3 {
display: grid;
grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
justify-items: center;
grid-gap: 40px;
}
.nav {
padding: 0 20px 0 20px;
border: 1px solid black;
display: flex;
flex-direction: column;
max-width: 150px;
}
.footer-explore {
justify-self: right;
}
.footer-company {
justify-self: center;
}
.footer-socials {
justify-self: left;
}
<div class="footer-nav">
<div class="container-footer-3">
<div class="footer-explore nav">
<h20>Left</h20>
<ul>
</ul>
</div>
<div class="footer-company nav">
<h20>Center</h20>
<ul>
</ul>
</div>
<div class="footer-socials nav">
<h20>RightRightRightRight</h20>
<ul>
</ul>
</div>
</div>
</div>
<div class="footer-nav">
<div class="container-footer-3">
<div class="footer-explore nav">
<h20>Left Left Left Left Left</h20>
<ul>
</ul>
</div>
<div class="footer-company nav">
<h20>Center Center Center</h20>
<ul>
</ul>
</div>
<div class="footer-socials nav">
<h20>Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right Right </h20>
<ul>
</ul>
</div>
</div>
</div>
#grid {
display: grid;
grid-template-rows: 1fr;
grid-template-columns: 1fr 1fr 1fr;
gap: 10px;
width: 100vw;
height: 100vh;
}
#div1 {
grid-area: 1 / 1 / 2 / 2;
background-color: rgba(29, 240, 35, 0.5);
}
#div2 {
grid-area: 1 / 2 / 2 / 3;
background-color: rgba(213, 209, 50, 0.5);
}
#div3 {
grid-area: 1 / 3 / 2 / 4;
background-color: rgba(158, 43, 127, 0.5);
}
<div id="grid">
<div id="div1">div1</div>
<div id="div2">div2</div>
<div id="div3">div3</div>
</div>
I don't know if that correspond exactly to what you are looking, but css grid could be your answer
A flex box solution is as follows:
The left and right div are allowed to grow using flex-grow:1; The center is given a flex-grow of 0 so it shrinks. If we set the left and right divs with a flex-basis of 100% then they'll expand to equal size. I've put a red line where the center of the screen is so you can see the center div is actually centered.
.container-footer-3 {
display: flex;
gap: 0.5rem;
}
.container-footer-3 > div {
flex-grow:1;
outline:1px solid blue;
flex-basis:100%;
}
.container-footer-3 > div:first-child {
text-align:right;
}
.container-footer-3 > div:nth-child(2) {
flex-grow:0;
flex-basis:0;
}
.centerline {
border:1px solid red;
height:50px;
width:0px;
position:absolute;
left:50%;
top:0;
}
<div class="footer-nav">
<div class="container-footer-3">
<div class="footer-explore nav">
<h20>Left</h20>
</div>
<div class="footer-company nav">
<h20>Center</h20>
</div>
<div class="footer-socials nav">
<h20>RightRightRightRight</h20>
</div>
</div>
</div>
<div class='centerline'></div>

Adding an image to a navbar using html and css

I'm trying to make an image fit to the left side of a navbar using only pure html and css. So far, I haven't made the actual nav li links but here's what I have:
.container {
max-width: 1100px;
margin: 0 auto;
overflow: auto;
padding: 0 40px;
}
img {
width: 100%;
}
.nav_class {
height: 80px;
}
<header id="header">
<div class="container nav_class">
<img id="header-img" src="https://odysseeservice.com/wp-content/uploads/2016/12/Microsoft-Dynamics-NAV-Logo.png" alt="">
<nav id="nav-bar">
<ul>
<li class="nav-link"></li>
<li class="nav-link"></li>
<li class="nav-link"></li>
</ul>
</nav>
</div>
</header>
I wouldn't like it to be more than 80px in height. Just the image on the left and 3 nav one-word nav links on the right.
I understand how to create the nav links and get all of the container children to be side by side but I cant figure out how to get the image to be smaller and on a fixed position in the navbar.
Guess what I'm basically asking is how to get the image fit the container and how to even make a proper container for it.
Thank you!
If the container of the img is 80px, then setting the img to have height: 100% will give it 80px of height and it will automatically scaling it.
Then you can use flexbox to help you with the positioning. Something like this:
#nav-bar{
height: 80px;
display: flex;
justify-content: space-between;
}
#nav-bar img{
height: 100%;
}
.nav-links{
display: flex;
}
.nav-links li{
width: 100px;
}
<header id="header">
<nav id="nav-bar">
<img id="header-img" src="https://odysseeservice.com/wp-content/uploads/2016/12/Microsoft-Dynamics-NAV-Logo.png" alt="">
<ul class="nav-links">
<li>A</li>
<li>A</li>
<li>A</li>
</ul>
</nav>
</header>
You can use object-fit property for this. Just give a full height and width to your image and force the image to contain its parent.
img {
width: 100%;
height: 100%;
object-fit: contain;
}
EDIT: You can learn more about this property on this page.
https://www.w3schools.com/css/css3_object-fit.asp
.container {
max-width: 1100px;
margin: 0 auto;
/* overflow: ; */
padding: 0 40px;
display:flex;
flex-direction: row;
justify-content: space-between ;
}
/* that will make image fit */
img {
width: 25%;
}
/* make the navbar and take every thing inside */
.nav_class {
height: 80px;
overflow: hidden;
}
#nav-bar ul{
margin: 0;
padding:0;
display:flex;
justify-content: space-between;
}
I added to your CSS code:
.container { display: grid; grid-template-columns: min-content auto; }
Those 2 lines change the header container to a grid where the logo will use up as much space as needed without changing the size format. The navbar will take up all remaining space.
Then I delted your CSS code for the image and replaced it with the header-img id to not influence other images:
#header-img { max-height: 80px; }
This will ensure that the logo will not use up more then 80px height and will take as much width as needed without changign the size ratio.
.container {
max-width: 1100px;
margin: 0 auto;
overflow: auto;
padding: 0 40px;
display: grid;
grid-template-columns: min-content auto;
}
#header-img {
max-height:80px;
}
.nav_class {
height: 80px;
}
<header id="header">
<div class="container nav_class">
<img id="header-img" src="https://odysseeservice.com/wp-content/uploads/2016/12/Microsoft-Dynamics-NAV-Logo.png" alt="">
<nav id="nav-bar">
<ul>
<li class="nav-link"></li>
<li class="nav-link"></li>
<li class="nav-link"></li>
</ul>
</nav>
</div>
</header>

how to dispay 3 divs inline

i have 3 divs, i want for a navbar, i need the navbar to be responsive
They cant stay inline on a width less than 800px, what im i doing wrong
.logo {
width: 18%;
min-width: 120px;
display: inline-block;
}
.middle {
width: 60%;
display: inline-block;
}
.user {
width: 18%;
min-width: 100px;
display: inline-block;
}
<div class="navbar">
<div class="logo"> LOGO </div>
<div class="middle"> About, contact </div>
<div class="user"> signin </div>
</div>
Use display: flex; in .navbar
The default flex direction is row so that should align your 3 divs horizontally .
And remove display properties from the child divs.
Give them flex-basis for respective widths

How can I make my nav bar span the width of the entire div

EDIT: I did manage to figure it out in flex! But the links still aren't quite taking up the entire top row:
enter image description here
there's still some extra space to the right and left. Is there any way to force the flex to use all the available space?
I'd like the nav bar to automatically adjust width based on how many links there are.
.top-container {
text-align: center;
display: flex;
}
.top-content-box {
width: 90%;
height: 30%;
margin: 30px auto;
background: #fff;
box-shadow: 0px 0px 10px #000;
justify-content: center;
display: flex;
flex-direction: column;
}
.news-and-twitter {
display: flex;
flex-direction: row;
flex-grow: 1;
}
.twitter-min {
width: 300px;
}
.news-box {
text-align: left;
vertical-align: middle;
padding: 30px;
flex-grow: 2;
}
.nav-bar {
text-align: center;
flex-grow: 1;
}
ul.link-list {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
display: inline-block;
}
<div class="top-container">
<div class="top-content-box">
<div class="nav-bar">
<ul class="link-list">
<li class="link-list"><a class="nav-list" href="default.asp">home</a></li>
<li class="link-list"><a class="nav-list" href="news.asp">about</a></li>
<li class="link-list"><a class="nav-list" href="contact.asp">projects</a></li>
<li class="link-list"><a class="nav-list" href="about.asp">portfolio</a></li>
<li class="link-list"><a class="nav-list" href="about.asp">commissions</a></li>
<li class="link-list"><a class="nav-list" href="about.asp">patreon</a></li>
</ul>
</div>
<div class="news-and-twitter">
<div class="news-box">
<h1>current project</h1>
Arena Circus ch 4 | Inserting voices into The Pretenders Guild
<h1>Current Events</h1>
<ul>
<li>The Pretenders Guild voice update is coming 7/15/19!
</li>
<li>Check the 1 year anniversary special offer here!</li>
</ul>
</div>
<div class="twitter-min">
<a class="twitter-timeline" data-width="300" data-height="450" data-theme="light" data-link-color="#343584" href="https://twitter.com/CapMinyan?ref_src=twsrc%5Etfw">Tweets by CapMinyan</a>
<script async src="https://platform.twitter.com/widgets.js"
charset="utf-8"></script>
</div>
</div>
</div>
</div>
screenshot
You have to make the parent element of the list (ul.link-list) a flex and make the children (li.link-list) have flex-grow of 1
.top-container{
text-align:center;
}
.top-content-box {
width: 90%;
height:30%;
margin:30px auto;
background: #fff;
box-shadow: 0px 0px 10px #000;
}
.news-and-twitter{
display:flex;
flex-direction:row;
flex-grow:1;
}
.twitter-min{
width:300px;
}
.news-box{
text-align:left;
vertical-align: middle;
padding:30px;
flex-grow:2;
}
Some may say "use flex box" but I really prefer not to do such methods!
So my suggestion would be position the nav bar left:50%;
And then give it a margin-left: -100px then change -100px to half of the nav's width, so lets say it has a width of 526px you put it to -263px.
And it may change it's width depending on the device's screen size, so I'd add some Javascript to change that when the page loads, so basically check what the width of the nav is then divide it by 2 and put a "-" in front of it then a "px" after it...
I understand if that sounds too complicated for such a simple task but I like using JavaScript to do my, things
Also many would say this is dumb to do, because the less Javascript the better but I strongly disagree, but that's my opinion... Other than the fact that a lot of Javascript will make the page slower, and a few other things...
Alternatively try doing margin: 0 auto could fix the problem, worth a shot!
Hope this helps!

how to properly align list items vertically?

I wanted to create a list of items by displaying a name, a list of properties and an image. Although this seems like quite a common and easy problem, I am struggling to get it right.
After having changed the markup a dozen of times, I chose to represent the list by a ul in which each li consists of a h3(name), a ul(properties) and a img(image).
In order to make it fill the page a bit more, I used CSS's flexbox in order to put the image and the properties next to each other in a responsive way.
img {
max-width: 100px;
}
#example > ul > li {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-around;
justify-content: space-around;
-webkit-align-items: center;
align-items: center;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
h3 {
width: 100%;
text-align: center;
}
div > ul {
border-left: 2px solid red;
}
<section id="example">
<ul>
<li>
<h3>Bulbasaur</h3>
<div>
<span>Properties</span>
<ul>
<li>green</li>
<li>seed</li>
<li>grass</li>
<li>poison</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/2/21/001Bulbasaur.png" />
</li>
<li>
<h3>Charmander</h3>
<div>
<span>Properties</span>
<ul>
<li>orange or some kind of red, I am not completely sure</li>
<li>lizard</li>
<li>fire</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/7/73/004Charmander.png" />
</li>
<li>
<h3>Squirtle</h3>
<div>
<span>Properties</span>
<ul>
<li>blue</li>
<li>tiny turtle</li>
<li>water</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/3/39/007Squirtle.png" />
</li>
</ul>
</section>
This looks pretty nice when the properties for all elements are equally long, but it kind of looks messy when this is not the case (the property-lists are not properly aligned as indicated by the red lines in the above snippet). I know I could get all the content in a table, causing every table element to be aligned nicely under each other, but then I don't know how I can have my names in a different line than the properties and the image...
My question could thus be formulated as:
How can I align the properties nicely under each other in such a way that they are displayed next to the image (to fill the space on the screen)? Additionally I would like that the image is displayed under the properties when the screen becomes too small (i.e. responsive design) and a separate line for the name.
Any help will be greatly appreciated
Update:
As it turned out that my question is not that clear, I tried to make it more clear by adding the vertical red lines in the snippet. I manage to get the desired result when using a table, but then I have to omit the names (as shown in the attached image) and the responsiveness...
You can just create a simple item element, something like this:
HTML
<li class="item">
<h2>Charmander</h2>
<div class="content">
<h3>Properties</h3>
<ul>
<li>orange or some kind of red, I am not completely sure</li>
<li>lizard</li>
<li>fire</li>
</ul>
</div>
<div class="image">
<img src="http://cdn.bulbagarden.net/upload/7/73/004Charmander.png" />
</div>
</li>
I simply divided the element in three main sections: title, properties and the image.
As you can see the properties are still inside a <ul> because they are used like a enumeration.
CSS
#example > ul {
padding: 0;
}
.item {
width: 100%;
background: #CCC;
padding: 20px;
box-sizing: border-box;
/* Padding will be inside the element (will not affect the width/height) */
margin: 20px 0;
overflow: hidden;
/* Used to keep the floated element inside the flow */
}
.item h2 {
text-align: center;
}
.item .content {
width: 60%;
float: left;
padding-left: 20px;
box-sizing: border-box;
}
.item .image {
width: 200px;
float: left;
}
.item img {
width: 100%;
}
.item .content ul {
border-left: 2px solid red;
margin-bottom: 20px;
}
With the first selector (#example > ul) I reset the default padding it has.
The text of the properties will just start on a new-line if it is too long (you can test this by resizing the window).
You can just edit the padding-left of the .content element, to move the properties a little bit more to the right or to the left.
Example JsFiddle
This is just to give you an example of how you want to approach this.
Hope it was helpful!
I have just been so stupid. As an alternative to the helpful answer of nkmol, it could also be as simple as changing the justify-content property to space-between and correct it by setting width and auto-margins.
img {
max-width: 100px;
}
#example > ul > li {
width: 80%;
margin: auto;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
-webkit-align-items: center;
align-items: center;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
h3 {
width: 100%;
text-align: center;
}
li > div > ul {
border-left: 2px solid red;
}
<section id="example">
<ul>
<li>
<h3>Bulbasaur</h3>
<div>
<span>Properties</span>
<ul>
<li>green</li>
<li>seed</li>
<li>grass</li>
<li>poison</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/2/21/001Bulbasaur.png" />
</li>
<li>
<h3>Charmander</h3>
<div>
<span>Properties</span>
<ul>
<li>orange or some kind of red, I am not completely sure</li>
<li>lizard</li>
<li>fire</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/7/73/004Charmander.png" />
</li>
<li>
<h3>Squirtle</h3>
<div>
<span>Properties</span>
<ul>
<li>blue</li>
<li>tiny turtle</li>
<li>water</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/3/39/007Squirtle.png" />
</li>
</ul>
</section>
PS: I'm sorry for my awful question...
You need to break out your items from the primary UL
You can think of it as though you were building a table, but instead, use divs and then use a UL just to list the properties. This way, you can style each of the individual elements as needed.
look here: https://jsfiddle.net/oq04f6pm/2/
<section id="example">
<div class="section-title">Bulbasaur</div>
<div class="section-list">
<span>Properties</span>
<ul>
<li>green</li>
<li>seed</li>
<li>grass</li>
<li>poison</li>
</ul>
</div>
<div class="section-image">
<img src="http://cdn.bulbagarden.net/upload/2/21/001Bulbasaur.png" />
</div>
</section>
img {
max-width: 100px;
}
.section-title {
width: 100%;
text-align: center;
font-weight: bold;
}
.section-list, .section-image {
width: 50%;
float: left;
}
.section-image {
text-align: center;
}
#media screen and (max-width: 400px) {
.section-list, .section-image {
width: 100%;
}
.section-image {
text-align: left;
}
}