How to centralize elements inside an <ul>? - html

Well, I have a site and it's happening something that I just can't fix.
I have a code like this:
aside {
font-size: 150%;
font-family: fantasy;
font-variant: small-caps;
line-height: 2em;
background: rgba(187,219,136,0.75);
width: 90%;
height: 50px;
text-align: center;
}
aside {
margin: auto;
margin-top: 20px;
}
aside li {
float: left;
padding: 0 2%;
font-size: 100%;
}
<aside>
<ul>
<li id="matematica">Matemática</li>
<li>Geografia</li>
<li>Física</li>
<li>História</li>
<li>Português</li>
<li id="quimica">Química</li>
</ul>
</aside>
So, the problem is that I want to centralize the li elements inside the ul, and I can't use text align because li is not text!
Can anyone help me?

is this what you want?
aside {
font-size: 150%;
font-family: fantasy;
font-variant: small-caps;
line-height: 2em;
background: rgba(187,219,136,0.75);
width: 90%;
height: 100px;
text-align: center;
}
aside{
margin: auto;
margin-top: 20px;
}
aside li{
display: inline-block;
padding: 0 2%;
font-size: 100%;
}
<aside>
<ul>
<li id="matematica">Matemática</li>
<li>Geografia</li>
<li>Física</li>
<li>História</li>
<li>Português</li>
<li id="quimica">Química</li>
</ul>
</aside>

try to :
aside li{
display:inline-block;
padding: 0 2%;
font-size: 100%;
}
remove the float too ;

If I understood correctly what you want to achieve, you may try changing:
aside li{
float: left;
padding: 0 2%;
font-size: 100%;
}
to
aside li{
display: inline;
padding: 0 2%;
font-size: 100%;
}
See it on JSFiddle and, also, check the attribute list-style-type for your <ul> tag.

I don't think you can select that circle because it's not an element. You can see it yourself. Just go to inspect and try to find that element.
But you can make a custom list.
<center><div id="b">
<div class="a"><span></span> List 1</div>
<div class="a"><span></span> List 2</div>
<div class="a"><span></span> List 3</div>
</div></center>
<style>
span {
background:black;
height:10px;
width:10px;
border-radius:30px;
display:inline-block;}
</style>

Related

How do I add corner logos into Footer using Html & CSS?

So for one of my school projects, we have to design a website using Html & CSS and I've encountered a problem where I don't know how to fit 2 logos (left & right) into the corners of my footer. I've tried to change the position, float, width etc and it doesn't seem to work, the logo always seems to not go in the place I want it to be. Sorry if this sounds amateur as I've only started doing Html & CSS a few weeks ago.
This is the current image where the logo is below my ul's and is in the incorrect position. -
This is what I want the footer to look like, it would be great to have the text on the left "Sponsored by HP omen gaming" to be a image as I may swap it out with another logo in the future. -
Thanks to anyone in advance who may be able to solve this problem for me, below would be my html & CSS code.
.footer {
background-color: #035642;
margin-top: 10px;
height: 60px;
color: #efe5d0;
text-align: center;
padding: 15px;
font-size: 100%;
font-family: Arial;
display: block;
}
.footer ul {
padding: 5px;
list-style-type: none;
text-align: center;
margin: 10px;
overflow: hidden;
}
.footer li {
text-decoration: none;
text-align: center;
font-family: arial;
font-weight: bold;
list-style-type: none;
display: inline-block;
}
.footer ul li {
display: inline-block;
}
.footer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #efe5d0;
background-color: #5c755e;
text-align: center;
font-family: arial;
font-weight: bold;
}
.footer ul li a:hover {
color: #000;
background-color: #fff;
}
#footer-right {
height: 50px;
width: auto;
position: fixed;
float: right;
}
<div class="footer">
<li>WBHS ESPORTS</li>
<ul>
<li>Facebook</li>
<li>|</li>
<li>YouTube</li>
<li>|</li>
<li>Twitch</li>
</ul>
<img src="hp-omen-logo.png" id="footer-right">
</div>
Try look into flexbox. Here's a quick template to do what you want.
.footer {
display: flex;
justify-content: space-between;
}
.center {
text-align: center;
}
<div class="footer">
<p>Left</p>
<div class="center">
<p>Some text</p>
<p>Your list</p>
</div>
<p>Right</p>
</div>
I think a solution can be the use of display:flex
And to be more clean try to use also the widgets, you can see in this example how it works.
.footer {
background-color: #035642;
margin-top: 10px;
height: 60px;
color: #efe5d0;
text-align: center;
padding: 15px;
font-size: 100%;
font-family: Arial;
display: block;
}
.footer ul {
padding: 5px;
list-style-type: none;
text-align: center;
margin: 10px;
overflow: hidden;
}
.footer li {
text-decoration: none;
text-align: center;
font-family: arial;
font-weight: bold;
list-style-type: none;
display: inline-block;
}
.footer ul li {
display: inline-block;
}
.footer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #efe5d0;
background-color: #5c755e;
text-align: center;
font-family: arial;
font-weight: bold;
}
.footer ul li a:hover {
color: #000;
background-color: #fff;
}
#footer-right {
height: 50px;
width: auto;
position: fixed;
float: right;
}
/*my-edit*/
#the-footer{
display:flex;
flex-wrap:wrap;
justify-content:space-between;
align-items:center;
height: auto;
margin: 0;
padding: 10px;
}
#the-footer .widget{
width: 30%;
}
#the-footer .widget.left{
text-align: left;
}
#the-footer .widget.right{
text-align: right;
}
#the-footer .widget.center{
text-align: center;
}
#the-footer .widget .title{
font-weight: bold;
letter-spacing: 2px;
}
#the-footer .widget .logo-link{
color:#fff;
display: inline-block;
text-decoration: none;
max-width:150px;
}
#the-footer .widget .logo-link:hover{
color:#000;
}
<div class="footer" id="the-footer">
<div class="widget left">
<a class="logo-link" href="#" target="_blank">Sponsored by HP omen gaming</a>
</div>
<div class="widget center">
<div class="title">WBHS ESPORTS</div>
<ul class="footer-nav">
<li>Facebook</li>
<li>|</li>
<li>YouTube</li>
<li>|</li>
<li>Twitch</li>
</ul>
</div>
<div class="widget right">
<a class="logo-link" href="#" target="_blank"><img class="logo-footer" src="https://via.placeholder.com/60" alt="logo"></a>
</div>
</div>
You can use the display: grid property so you can separate your footer into 3 parts
You can learn about the grid property here: https://www.w3schools.com/css/css_grid.asp

How to position links on the right side of text?

I am a beginner, and I am trying to get this to work.
How do I position the link to the right side of the connect text?
I want the text links to be inline but to the right.
.footer {
grid-area: footer;
margin-top: 38px;
margin-left: 100px;
margin-right: 100px;
height: 700px;
}
.footer-text {
padding: 200px 100px;
font-family: "Khula", sans-serif;
font-size: 80px;
color: #222222;
}
.footer-contact {
font-family: "Khula", sans-serif;
font-size: 35px;
color: #222222;
letter-spacing: -1px;
text-decoration: none;
padding: 100px 60px;
}
ul {
list-style-type: none;
text-decoration: none;
}
<div class="footer-text">Contact</div>
<ul>
<li>Email</li>
<li>LinkedIn</li>
<li>Instagram</li>
</ul>
You can add this to the .footer-text:
display:flex;
justify-content: right;
Note that this will apply to all childs of the .footer-text div.
Please update this two class properties as like the following code:
.footer-text {
padding: 200px 100px;
font-family: "Khula", sans-serif;
font-size: 80px;
color: #222222;
display: inline-block;
}
ul {
list-style-type: none;
text-decoration: none;
display: inline-block;
}
This can be solved easily by using a wrapper div. like so,
.wrapper {
overflow: auto;
}
.footer-text {
float: left;
}
.ul {
float: right;
}
<div class="wrapper">
<div class="footer-text">Contact</div>
<ul class="ul">
<li>Email</li>
<li>LinkedIn</li>
<li>Instagram</li>
</ul>
</div>

A white gap between two div elements [duplicate]

This question already has answers here:
How to disable margin-collapsing?
(12 answers)
Closed 5 years ago.
Here is the HTML code (the white gap started appearing as soon as I added h3 to the last div):
body {
margin: 0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #343434;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style-type: none;
}
nav li {
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover {
color: yellow;
}
.welcome {
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3 {
text-align: center;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
I am fairly new to web development and stackoverflow. So I am sorry for any inconveniences. Any help is appreciated. Thank you.
Set margin: 0px; on h3 tag to resolve this issue. Check updated Snippet below..
body{
margin:0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container{
width: 80%;
margin : 0 auto;
}
header{
background: #343434;
}
header::after{
content: '';
display: table;
clear:both;
}
.logo{
float: left;
padding:10px;
}
nav{
float:right;
}
nav ul{
margin: 0;
padding: 0;
list-style-type: none;
}
nav li{
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a{
text-decoration: none;
color:white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover{
color:yellow;
}
.welcome{
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3{
text-align: center;
margin: 0px;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
Just remove the margin from h3 like
.welcome h3 {
text-align: center;
margin:0;
}
body {
margin: 0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #343434;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style-type: none;
}
nav li {
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover {
color: yellow;
}
.welcome {
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3 {
text-align: center;
margin:0;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
This is due to collapsing margins
Remove the margin on the h3. Replace it with padding if you want to create space between the header and maintain the background colour.
body {
margin: 0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #343434;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style-type: none;
}
nav li {
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover {
color: yellow;
}
.welcome {
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3 {
text-align: center;
margin-top: 0;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
You can try adding style="display: inline; margin:0px; padding:0px;" to your <h3> Tag.
Another way is to apply a rule of overflow: auto to the .welcome div... thus creating a new block formatting context and avoiding the collapsing margins.
Edit: Let's add a little more context. In the spec, you can read that adjoining margins will collapse under certain circumstances. In particular, the margins need to belong to block-level boxes participating in the same block formatting context.
Even though .welcome and h3 are block-level boxes in your example, neither automatically establishes a new block formatting context (meaning they participate in the same block formatting context, meaning their margins collapse). Looking at the spec again, we see that some of the ways to establish a new block formatting context is to have a float, an absolutely positioned element, or a block box with the property of overflow set to something else than visible.
That's why the suggestions regarding overflow: auto or floating one of the elements work. My understanding is that if we make .welcome establish a new block formatting context, the context it participates in is different from the one it establishes itself. Removing the margin (possibly replacing it with padding) is another way to get around the problem.
Either apply margin-top:0 for H3-Tag
or
apply a float:left for .welcome
Both will fix your issue

HTML Align navbar to the right, image fitting page

I'm starting ton code and I have some struggles with this website. First, I made the header with a nabber in it but I can't align it to the right, if I try it with float:right it switches the links. And underneath all that I want a big picture but auto height and width doesn't work if I make the page bigger.
<!DOCTYPE html>
<style>
header{ background-color: white;
margin-left: 20px;
margin-top: 30px;
}
img.logo{ width: 200px;
height: 30px;
}
li{ display: inline;
}
ul{ position: fixed;
top: 20px;
}
a{ font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
}
img.picvp{margin-top: 20px;
width: auto;
height: auto;
}
</style>
<header>
<img class="logo" src="#">
<ul>
<li style="float:right;">Projecten</li>
<li style="float:right;">over</li>
<li style="float:right;"><a href='#'>Contact</a></li>
</ul>
</header>
<sec>
<img class="picvp" src="https://lh4.googleusercontent.com/G3M2vxtCatAm1yxWxUA0VVLZjtePu32ziMPd6TLL3wQhk53s4mokl5v_7Rx0crGBp_2Q6iZJnRU-lzQ=w1262-h905">
</sec>
Thank you!
Using display:flex will help with this.
.header{
background-color: white;
align-items: center;
display: flex;
margin-left: 20px;
margin-top: 30px;
}
.logo{
background-color: #0f0;
width: 200px;
height: 30px;
}
.nav {
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
margin-left: auto;
}
.nav li{ display: inline-block; }
.nav a {
border-left: solid 1px;
display: block;
padding: 1em;
}
img.picvp{
margin-top: 20px;
width: auto;
height: auto;
}
<header class="header">
<img class="logo" src="#">
<ul class="nav">
<li>Projecten</li>
<li>over</li>
<li><a href='#'>Contact</a></li>
</ul>
</header>
<sec>
<img class="picvp" src="https://lh4.googleusercontent.com/G3M2vxtCatAm1yxWxUA0VVLZjtePu32ziMPd6TLL3wQhk53s4mokl5v_7Rx0crGBp_2Q6iZJnRU-lzQ=w1262-h905">
</sec>
Here is a link to the solution: Fiddle N1
You just needed to add: width: 100%; to the class img.picvp.
Another thing is that you should've set your ul elements like that:
ul{
position: relative;
display: inline;
text-align:right;
}
text-align:right automatically pulls the elements to the right side of the parent div. Also use relative positioning rather than fixed one. I have made some changes to the width of the background image as well. Compare the changes to the code so you can see what exactly has been changed.
hii i modify some of code but impornant i use parent and child an example in your i use as parent and as child see example as follow
(dont forgot to change img src)
header{ background-color: white;
margin-left: 20px;
margin-top: 30px;
}
img.logo{
width: 1100px;
height: 130px;
}
ul,li{ display: inline;
text-decoration:none;
}
a,li{
display: inline;
}
a{ font-family: 'Open Sans', sans-serif;
text-decoration:none;
display: inline;
}
img.picvp{margin-top: 20px;
width: auto;
height: auto;
}
<img class="logo" src="nows.jpg">
<ul>
<li style="float:right;">Projecten</li>
<li style="float:right;">over</li>
<li style="float:right;"><a href='#'>Contact</a></li>
</ul>

HTML and CSS navigation bar next to logo

I'm new to programming and I'm trying to make a website but I have a big problem. I want a navigation bar next to my logo and sticking to the top when i scroll, but I can't get it to work. The text is on top of each other and I don't know how to make it work.
<!DOCTYPE html>
<html>
<head>
<style>
body{ background-color: black}
img.logo{ margin-left: 20px;
margin-top: 10px;}
li{ display: inline}
a{ position: fixed;
width: auto;
height: 50px;
margin-left: 50px;
margin-top: 60px;
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px
margin: 0px;
padding: px;}
</style>
</head>
<body>
<header>
<img class="logo" src="https://lh4.googleusercontent.com/7zZpeNiaANxK7CqDKwE2PdemWJFKoskKGKelsSmQSNmZQOBpKwMkOST3ucML162QIf3k5_ZclpFT_PE=w998-h1006" style="height: auto; width: 300px" >
<li>Projecten</li>
<li>over</li>
</header>
</body>
</html>
Welcome to the world of web development!
The first order of business is to fix your CSS so it is valid. We'll also tidy it up a little.
Add a semicolon after letter-spacing: 0.5px
You don't have any value assigned to padding: px; so just remove that line
It's not necessarily invalid, but I would remove the declarations for margin-left and margin-top on the a element because you are overriding them with margin: 0px; later on.
With that done, the CSS should look like this:
body {
background-color: black;
}
img.logo {
margin-left: 20px;
margin-top: 10px;
}
li {
display: inline;
}
a {
position: fixed;
width: auto;
height: 50px;
margin-left: 50px;
margin-top: 60px;
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
}
Now, lets make the HTML valid and tidy it up, as well.
You can't have <li> elements directly under <header>. They only go inside <ol> or <ul> elements. <ul> (unordered list) makes the most sense here, so let's use that.
It's a good idea to place a value in the href attribute of your <a> element. If you're just prototyping and don't have a URL to use, yet, people typically use #.
The HTML now looks like this:
<header>
<img class="logo" src="https://lh4.googleusercontent.com/7zZpeNiaANxK7CqDKwE2PdemWJFKoskKGKelsSmQSNmZQOBpKwMkOST3ucML162QIf3k5_ZclpFT_PE=w998-h1006" style="height: auto; width: 300px" >
<ul>
<li>Projecten</li>
<li>over</li>
</ul>
</header>
Now, one issue is that you are applying a fixed position to each of your <a> elements separately. What you actually want to do is apply a fixed position to the whole navbar (the whole <ul>). So change your CSS like so:
ul {
position: fixed;
}
a {
width: auto;
height: 50px;
margin-left: 50px;
margin-top: 60px;
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
}
This is just an excerpt. But notice that I moved position: fixed; from a to ul. Really, that is all that's needed. If you want to fine tune where the navbar appears, go ahead and use top and left like so:
ul {
position: fixed;
top: 5px;
left: 10px;
}
The whole page now looks like this:
body {
background-color: black;
color: white;
}
img.logo {
margin-left: 20px;
margin-top: 10px;
}
li {
display: inline;
}
ul {
position: fixed;
top: 5px;
left: 10px;
}
a {
width: auto;
height: 50px;
margin-left: 50px;
margin-top: 60px;
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
}
<header>
<img class="logo" src="https://lh4.googleusercontent.com/7zZpeNiaANxK7CqDKwE2PdemWJFKoskKGKelsSmQSNmZQOBpKwMkOST3ucML162QIf3k5_ZclpFT_PE=w998-h1006" style="height: auto; width: 300px" >
<ul>
<li>Projecten</li>
<li>over</li>
</ul>
</header>
<li> elements should be in a <ul> or <ol>
In the example below, I used flexboxes for the layout. Please have a look here to learn about flexboxes.
body {
background-color: black
}
header {
display: flex;
align-items: center;
}
ul {
padding: 0;
margin: 0;
list-style: none;
display: flex;
}
img.logo {
margin-left: 20px;
margin-top: 10px;
}
li {
margin-left: 1em;
}
a {
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px margin: 0px;
}
<header>
<img class="logo" src="http://placehold.it/300x100">
<ul>
<li>Projecten</li>
<li>over</li>
</ul>
</header>
Change the position to relative and add "vertical-align:top" to the anchor.
body{ background-color: black}
img.logo{ margin-left: 20px;
margin-top: 10px;}
li{ display: inline}
a{ position: relative;
width: auto;
height: 50px;
margin-left: 50px;
margin-top: 60px;
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
vertical-align:top;
margin: 0px;
padding: px;}
<img class="logo" src="http://lorempixel.com/300/100" style="height: auto; width: 300px" >
<li>Projecten</li>
<li>over</li>
I think having <li> tags for horizontal links is a bit to complicated for nothing. You could simply use <a> tags without the <li>. Here is an exemple of how I think would be the best.
Codepen demo
If you want the content to be scrollable with the navbar on top (without it being fixed), you need to wrap it into a <div> too. This also has the very nice effect of allowing you a simple footer, should you eventually want one.
Since you didn't specify any browser support, I took the liberty of using flex to do so.
Put your li in a ul, display li inline-block, then float both the logo and the ul left, or float the ul right and put a margin-right on it if that is what you would prefer.
Make your header fixed and the logo and nav remain at the top while scrolling.
<style>
body{ background-color: black}
header#header {
position: fixed;
width: 100%;
}
div.logo {
margin-left: 20px;
margin-top: 10px;
float: left;
}
ul#nav {
float: left;
}
ul#nav li {
display: inline-block;
}
ul#nav li a {
margin-left: 50px;
margin-top: 60px;
color: #DFDD7D;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: 300;
letter-spacing: 0.5px;
}
</style>
<header id="header">
<div class="logo">
<img class="logo" src="https://lh4.googleusercontent.com/7zZpeNiaANxK7CqDKwE2PdemWJFKoskKGKelsSmQSNmZQOBpKwMkOST3ucML162QIf3k5_ZclpFT_PE=w998-h1006" style="height: auto; width: 300px" >
</div>
<nav id="main_nav">
<ul id="nav">
<li>Projecten</li>
<li>over</li>
</ul>
</nav>
</header>