How can I line up my html elements in an element? - html

I have a navigation bar with hyperlinks to other pages. I decided to use different divisions for each hyperlink because I couldn't get them to spread out. When I execute this on my browser, two of the hyperlinks(both the right ones) are slightly below the other ones. I don't know if that is because of my mac or if it's an error in the code. Could someone please tell me how I can make sure all hyperlinks are evenly lied up in 2 lines?
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.connectp1 {
text-align: left;
}
.connectp2 {
text-align: center;
}
.connectp3 {
text-align: right;
}
.connectp4 {
text-align: left;
}
.connectp5 {
text-align: center;
}
.connectp6 {
text-align: right;
}
<div class="navbar">
<div>
<div class="connectp1">
First Peoples
</div>
<div class="connectp2">
Natives And Newcomers
</div>
<div class="connectp3">
Provincial Centre
</div>
</div>
<div>
<div class="connectp4">
Industrializing City
</div>
<div class="connectp5">
Wars And Crises
</div>
<div class="connectp6">
The Modern Metropolis
</div>
</div>
</div>

You don't need extra layers to spread out. Inline elements like <a> are better for this kind of menus, so just keep it simple. The code bellow will split in two lines only if required.
.navbar {
padding: 15px;
background-color: #F64C72;
text-align: center;
font-size: 17px;
}
.menu {
display: inline-block;
margin: 10px auto;
white-space: nowrap;
}
nav a {
display: inline-block;
padding: 5px;
white-space: normal;
vertical-align: top;
}
<nav class="navbar">
<div class="menu">
First Peoples
Natives And Newcomers
Provincial Centre
</div>
<div class="menu">
Industrializing City
Wars And Crises
The Modern Metropolis
</div>
</nav>
However I recommend you considering some improvements in your design to help the menu look more tidy.

This looks like a perfect opportunity to use flexbox setting justify-content. We can just work with a div to hold all the nav and then a div for each row then the links directly.
flexbox handles the distribution of the a elements in our instance, while setting justify-content: space-between determines how the a elements are spaced.
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.navbar > div {
display:flex;
justify-content: space-between;
}
<div class="navbar">
<div>
First Peoples
Natives And Newcomers
Provincial Centre
</div>
<div>
Industrializing City
Wars And Crises
The Modern Metropolis
</div>
</div>
With IE 10 you will need to prefix with -ms- and it won't work at all with older versions of IE if you need to support IE 9 and earlier. See: https://css-tricks.com/almanac/properties/j/justify-content/

You would be much better off using unordered lists (ul) with list items (<li>), and then displaying the lists as table rows/table cells as in the snippet below, and vertically aligning to top. Btw, your current css includes duplication, there is no need to created 2 different classes to text-align to the right (e.g)
Feel free to adjust the snippet ( I reduced the huge font size! - so that the adjustments could be seen in the snippet)
* {
margin: 0px;
padding: 0px;
}
nav {
margin: auto;
top: 20px;
padding: 20px;
font-size: 13pt;
background-color: #F64C72;
text-align: center;
}
nav ul {
margin: 0px;
list-style-type: none;
vertical-align: top;
display: table-row;
}
ul li {
display:table-cell;
}
ul li a {
text-decoration: none;
}
<nav>
<ul>
<li>First Peoples </li>
<li>Natives And Newcomers</li>
<li>
Provincial Centre
</li>
</ul>
<ul>
<li class="">Industrializing City
</li>
<li class="">
Wars And Crises
</li>
<li class="">
The Modern Metropolis
</li>
</ul>
</nav>

Use HTML5 semantic elements when possible. In your case, the nav element is the proper tool for the job. MDN shows:
nav {
border-bottom: 1px solid black;
}
.crumbs ol {
list-style-type: none;
padding-left: 0;
}
.crumb {
display: inline-block;
}
<nav class="crumbs">
<ol>
<li class="crumb">Acme</li>
<li class="crumb">Foo</li>
<li class="crumb">Bar</li>
</ol>
</nav>
<h1>Jump Bike 3000</h1>
<p>This BMX bike is a solid step into the pro world. It looks as legit as it rides and is built to polish your skills.</p>

<div> elements are block-level elements, so take up 100% of the width of a 'row' by default. While you can correct this by simply changing their display to inline-block, I would recommend replacing them with <span> tags instead (which are inline-block by default):
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.connectp1 {
text-align: left;
}
.connectp2 {
text-align: center;
}
.connectp3 {
text-align: right;
}
.connectp4 {
text-align: left;
}
.connectp5 {
text-align: center;
}
.connectp6 {
text-align: right;
}
<div class="navbar">
<div>
<span class="connectp1">
First Peoples
</span>
<span class="connectp2">
Natives And Newcomers
</span>
<span class="connectp3">
Provincial Centre
</span>
</div>
<div>
<span class="connectp4">
Industrializing City
</span>
<span class="connectp5">
Wars And Crises
</span>
<span class="connectp6">
The Modern Metropolis
</span>
</div>
</div>
Note that you're also likely looking for float: left and float: right
rather than text-align: left and text-align: right, in order to separate out your elements. There's no float: center, though this isn't needed. You can also combine your selectors in this regard to save space, as can be seen in the following:
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.connectp1, .connectp4 {
float: left;
}
.connectp3, .connectp6 {
float: right;
}
<div class="navbar">
<div>
<span class="connectp1">
First Peoples
</span>
<span class="connectp2">
Natives And Newcomers
</span>
<span class="connectp3">
Provincial Centre
</span>
</div>
<div>
<span class="connectp4">
Industrializing City
</span>
<span class="connectp5">
Wars And Crises
</span>
<span class="connectp6">
The Modern Metropolis
</span>
</div>
</div>

Related

Bootstrap 4 align right in cell

I'm currently writing an interface for a ticket system that uses Bootstrap 4's grid system to position components about the system. As you can see from the screenshot below, the UI has two container-fluid divs stacked. The top div aligns perfectly, the second one I am struggling with.
I want it to render like this (without the pink - the pink is showing the two cols):
however it is rendering like this:
The code that renders this is as follows:
HTML:
<div class="container-fluid container-navbar">
<div class="row navbar">
<div class="col">
logo goes here
</div>
<div class="col text-center help-desk">
help desk.
</div>
<div class="col text-right">
<i aria-hidden="true" class="fa fa-bars" id="settings-menu" ></i>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row ticket-summary-navbar">
<div class="col text-right">
<div class="global-ticket-summary">
<ul>
<li >
<p class="ticketCount" >5</p>
<p class="nameLabel" >User1</p>
</li>
<li >
<p class="ticketCount" >3</p>
<p class="nameLabel" >User2</p>
</li>
<li >
<p class="ticketCount" >8</p>
<p class="nameLabel" >User3</p>
</li>
<li >
<p class="ticketCount" >6</p>
<p class="nameLabel" >User4</p>
</li>
<li >
<p class="ticketCount" >2</p>
<p class="nameLabel" >User5</p>
</li>
</ul>
</div>
</div>
<div class="col">
</div>
</div>
</div>
CSS:
body{
background-color: #ababab;
}
.navbar{
color: white;
background-color: rgba(58, 191, 195, 1);
height: 75px;
padding-left: 10px;
padding-right: 10px;
}
.container-navbar{
padding-left: 0px;
padding-right: 0px;
min-width: 490px;
}
.help-desk{
font-size: 30px;
font-family: 'Roboto', sans-serif;
font-weight: 300;
}
#settings-menu{
font-size: 25px;
cursor: pointer;
}
.ticket-summary-navbar{
background-color: #f7f7f7;
height: 90px;
}
.global-ticket-summary {
font-family: 'Roboto', sans-serif;
color: #1b1b1b;
font-weight: 200;
}
.global-ticket-summary ul {
list-style-type: none;
}
.global-ticket-summary ul li {
text-align: center;
float: left;
width: 100px;
}
.global-ticket-summary ul li .ticketCount {
font-size: 22pt;
margin-bottom: -4px;
cursor: pointer !important;
}
.global-ticket-summary ul li .nameLabel {
font-size: 11pt;
/*margin-bottom: 0;*/
color: #656565;
cursor: pointer !important;
}
As you can see it renders the <ul> in the middle, even though I have the text-right directive.
I can certainly get it working by adding "float:right;" to the UL - which positions correctly horizontally, however it then no longer aligns vertically correctly (it snaps to the top of the div). I have searched in many places for a solution, however all point to using the navbar for Bootstrap, which isn't relevant in this case.
Is there a way I can have the UL align right to its parent div without resorting to padding/margin CSS hacks?
Plunkr link also: https://next.plnkr.co/plunk/y4EYmtpgwRvHkjuI
Put the text align on the global-ticket-summary div, and if that doesn't work put it in the UL. Text align only works for the direct child elements I believe
You can use flexbox to align content. Just put this .flex-container class into your code to right align child elements.
.flex-container {
display: flex;
justify-content: flex-end;
align-items: center;
}
If you are new to css i will recommend you to take a look into flexbox.
You want to put ul in right side of col. Correct me! if i misunderstood your question.
So, you need to do the following in your style.css file,
just replace with following css code.
.global-ticket-summary ul {
list-style-type: none;
text-align: right!important;
}
.global-ticket-summary ul li {
float: left;
width: 100px;
}
Use flex utilities for bootstrap 4. Add following classes to the first column (which is having text-right): d-flex, justify-content-end.
...
<div class="container-fluid">
<div class="row ticket-summary-navbar">
<div class="col d-flex justify-content-end">
...
It is aligning as you want to the right.
For reference here is link to flex utility for bootstrap 4 : https://getbootstrap.com/docs/4.0/utilities/flex/

Why is my paragraph element displaying behind a background color

So im making a website for a school project and all was hunky dory until i tried to put a paragraph element in and it displays above the title text behind the background color
.container {
width: 80%;
margin: 0;
padding: 0;
}
#logotext {
float: left;
font-family: 'Doppio One';
margin-left: 25px;
}
nav {
float: right;
}
#nav {
list-style-type: none;
text-decoration: none;
margin-top: 35px;
}
ul li {
display: inline;
}
li a {
text-decoration: none;
color: white;
}
li a:hover {
color: #fc9516;
}
.darkwrap {
background-color: #414a4c;
position: fixed;
overflow: hidden;
}
.active {
color: #22cc25;
}
#clock {
position: absolute;
top: 0;
right: 0;
margin-top: 25px;
margin-right: 25px;
font-family: Rajdhani;
font-size: 30px;
}
<div class="container darkwrap">
<div id="logotext">
<h1>JF Web Design</h1>
</div>
<!-- Navigation Bar -->
<nav>
<ul id="nav">
<li> Page 1 </li>
<li> About </li>
<li> Page 3 </li>
</ul>
</nav>
</div>
</header>
<span id="clock"></span>
<p>
Hello
</p>
<footer></footer>
i usedchrome to highlight the faulty element so its clear whats happening here its literall positioned at the top behind the bg color
Console Highhlighted element
.darkwrap is position: fixed.
This takes it out of normal flow and locks its position relative to the viewport.
The rest of the content is laid out as normal as if the .darkwrap element didn't exist … so it ends up covered up by it.
You could use margins to compensate for the space covered up by .darkwrap when the viewport is scrolled to the top. I would simply avoid using position: fixed in the first place: The benefits of having the menu on screen all the time very rarely outweigh the drawback of using up all that vertical space all the time.
If you use float: left and float:right please remember to add clear:both to the next element on the website. Here is fixed code:
https://codepen.io/anon/pen/jKRqLz

alignment of links in footer

I am trying to clone google's home page.I Started from the footer of the page and got stuck at the alignment of the links in the footer.
my html code:
<div class="footer">
<hr >
<footer >
Advertising
Business
About
Privacy
Terms
Settings
</footer>
</div>
my css code :
.footer{
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
footer{
background-color: #F4F6F7;
height: 45px;
}
hr{
border-color: #CCD1D1;
margin-bottom: 0px;
}
.advertising, .business, .about, .privacy, .terms, .settings{
color: #909497;
font-size: 1.2em;
margin-top: 11px; //THIS LINE.
}
.advertising, .business, .about{
margin-left: 40px;
}
.privacy, .terms, .settings{
margin-right: 40px;
float: right;
}
can anyone tell me, why the line "margin-top : 11px" is not applied to the first 3 links in the footer(advertising,business,about). Screenshot of footer:
Although the above answer will work, a better solution is this:
.footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
footer {
background-color: #F4F6F7;
height: 45px;
}
hr {
border-color: #CCD1D1;
margin-bottom: 0px;
}
.align-left {
float: left;
}
.align-right {
float: right;
}
.footer-links {
list-style-type: none;
}
.footer-links li {
display: inline;
}
.footer-links li a {
color: #909497;
font-size: 1.2em;
margin: 11px 20px 0px;
}
<div class="footer">
<hr/>
<footer>
<ul class="footer-links align-left">
<li>Advertising</li>
<li>Business</li>
<li>About</li>
</ul>
<ul class="footer-links align-right">
<li>Privacy</li>
<li>Terms</li>
<li>Settings</li>
</ul>
</footer>
</div>
By putting the links into separate menus, it allows you to very quickly add and remove links in the future without messing around with CSS classes.
This fixes any margin errors you are having as well, as we're declaring that every anchor tag has a margin-top of 11px. You'll also notice instead of having 40px margin-left and margin-right, I've set each side to 20px which will give the same effect.
You can also use the .align-left and .align-right classes elsewhere in your HTML instead of declaring it in CSS for every class.
There's no need to give each link it's own class when they all have the same style. But if you wanted to highlight a particular link you'd naturally just add a .highlight class onto one of the anchor tags and specify the styling in CSS.
This method also gives full browser support. Flexbox is a little temperamental on IE as I write this.
Hope this helps!
You need to add float:left to your first three links, as you have applied float:right on the last three.
.advertising, .business, .about{
margin-left: 40px;
float:left;
}
I ran it through codepen,it worked when I applied the margin 11px to all elements using the footer as a selector
I also would recommend using flexbox, its alot easier to use, here is an example
`http://codepen.io/HTMLanto/pen/gmNedQ`
Cheers !

Nav bar buttons

I'm trying to create nav bar similar to that of Uber's site. Where there's a menu button on the left, logo in the center, and then log in and sign up are on the right.
I used and div container="pull-right" and still couldn't get the Title to be center. The buttons won't be stylized much more than what they are since they will be on a white background.
<div class="nav">
<div class="container">
<ul>
MENU</button></li>
TITLE</button></li>
SIGN UP</button></li>
LOG IN</button></li>
</ul>
</div>
</div>
.nav{
color: #5a5a5a;
font-size: 15px;
font-weight: normal;
padding: 15px 15px 5px 5px;
word-spacing: 3px;
}
.nav li {
display: inline;
}
.nav button {
background-color: Transparent;
background-repeat:no-repeat;
border: none;
cursor:pointer;
overflow: hidden;
outline: none;
}
.nav a{
color: inherit;
}
Here's my Jsfiddle: https://jsfiddle.net/tokyothekid/r19y23ep/1/
you can try this fiddle
demo
in this i have manage the structure of your li and as per your description i make a design i hope it may help you
.col1
{
margin:0;
padding:0;
float:left;
width:50%;
}
Quick answer
If you want something like the website for Uber, you probably need to separate the Menu from the buttons on the right side.
Other notes
Also, HTML5 has specified special tags so code is more readable and organized, such as the <nav> tag to hold your main menu. <div> doesn't communicate the purpose of the container.
To do what you want, here is a to-do list:
fix your bugs (<a href="somewhere"<li><button>foobar</button></li></a> actually is an error because of the lack of right bracket > at the end of your opening <a> tag)
separate your elements into a menu, a title, and a couple of user account buttons
The code
Here is a good example of how you could restructure your HTML:
<h2 class="top-title">Title</h2>
<nav>
<button id="toggle-menu">Menu</button>
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
</ul>
</nav>
<div class="user-buttons">
<button>Log in</button>
<button>Sign up</button>
</div>
This is a quickly hacked bit of CSS you might use to start with:
h2 {
display: inline-block;
width: 100vw;
text-align: center;
margin: 0;
position: absolute;
z-index: -1;
}
nav {
float: left;
}
nav ul {
list-style-type: none;
padding: none;
position: absolute;
}
nav ul a {
text-decoration: none;
text-transform: uppercase;
color: inherit;
}
div.user-buttons {
float: right;
}
Add some Javascript, and voila:
$(function() {
$("nav ul").hide();
$("#toggle-menu").click(function() {
$("nav ul").toggle();
});
});
JSFiddle example.

ListItem disc displaying at vertical bottom

I have a couple un-ordered lists on my page. Both lists use list-style: disc inside;. Each list's list-items have a couple div's inside them. The problem is that the list-item's content takes up multiple lines and the disc is appearing vertically, at the bottom of the multi-line list-item.
Here is a screenshot kind of showing the problem I am experiencing. Note that I stole the image from a similar question, it is not my HTML or CSS.
Here is a striped down version of my HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="billing_form">
<div id="purchase_items">
<h2>Your purchase</h2>
<h4>Items:</h4>
<div class="items">
<ul>
<li>
<div class="item">First Product - one year license</div>
<div class="price">$99.00 USD</div>
</li>
<li>
<div class="item">Second product & 3 year Product Plan</div>
<div class="price">$125.00 USD</div>
</li>
</ul>
</div>
<div class="subtotal">SUBTOTAL: $224.00 USD</div>
<h4>Discounts:</h4>
<div class="discount">
<ul>
<li>
<div class="item">A really long discount item name - with extra info on three lines!</div>
<div class="price">- $20.00 USD</div>
</li>
</ul>
</div>
<div class="total">TOTAL: $204.00 USD</div>
</div>
</div>
</body>
</html>
And here is the CSS, as small as I thought was relevant:
html
{
font-family: sans-serif;
}
#billing_form
{
width: 350px;
margin: 0 auto;
font-size: 14px;
background-color: #EEEEEE;
}
#billing_form .items
{
position:relative;
}
#billing_form .discount
{
position:relative;
color:#3665B0;
}
#billing_form ul
{
margin: 0;
padding: 0;
list-style: disc inside;
}
#billing_form .items .item,
#billing_form .discount .item
{
display: inline-block;
width: 190px;
}
#billing_form .price
{
float: right;
padding-left: 20px;
}
#billing_form .items,
#billing_form .discount,
#billing_form .subtotal,
#billing_form .total
{
width: 100%;
}
#billing_form .subtotal,
#billing_form .total
{
text-align: right;
margin-top: 5px;
border-top: 1px solid;
font-weight: bold;
}
#billing_form #purchase_items
{
margin: 10px 10px 10px;
}
I found a similar SO question. Unfortunately, the accepted (and only) answer to it states to try position: relative; and vertical-align: top; but it didn't work for me. I tried it with both #billing_form ul and #billing_form ul li and neither worked. They also mention a IE7 hack fix, but I don't think that is relevant to me because I am experiencing the problem in Firefox 3 & 4 and Google Chrome.
Does anyone know how I can make the list-item bullets (discs) appear at the top of each line item?
It looks like vertical-align: text-top; will do what you want (see spec). I believe the reason is that you are creating tall inline blocks that are aligning to the top of the box which is being pushed up by the tall inline box so aligning to top doesn't do what you want. However, I believe that using text-top will align it with the top of where the text is (and the bullet point).
http://jsfiddle.net/Yayuj/ is a fiddle that does what you want (I believe) and has primarily this updated section from your CSS:
#billing_form .discount .item
{
display: inline-block;
width: 190px;
vertical-align: text-top;
}
Any other differences to what you have pasted above should be cosmetic.