I have noticed when testing my page on my phone that the point where the two borders meet, an unidentified edge appears
I have also tried having a larger border bottom on my h1 element and a 0 border top for my nav ul element
And look what happens if the background color of the body is the same color as the border
This issue also appears while testing on Google Chromes responsive developer tool.
This is my code for this question
body {
width: 100%;
background-color: blue;
}
h1 {
font-size: 35px;
text-align: center;
color: yellow;
background-color: blue;
border:20px solid yellow;
border-bottom: 10px solid yellow;
margin: 2%;
margin-bottom: 0px;
padding-top: 10px;
padding-bottom: 10px;
}
nav ul {
background-color: blue;
display: flex;
justify-content: space-between;
list-style-position: inside;
padding: 0;
margin: 0;
border:20px solid yellow;
border-top: 10px solid yellow;
margin-left: 2%;
margin-right: 2%;
}
nav li {
font-size: 15px;
display: inline-block;
list-style-type: none;
background-color: blue;
color: yellow;
padding: 10px;
}
nav ul li a {
width: 67px;
display: inline-block;
text-align: center;
color: yellow;
text-decoration: none;
}
<header>
<h1>
SPACING
</h1>
</header>
<nav>
<ul>
<li>MARGIN</li>
<li>BORDER</li>
<li>PADDING</li>
</ul>
</nav>
I have disabled zoom by using <meta name="viewport" content="width=device-width, maximum-scale=2.0, user-scable=no"> in the head of my html.
I have also tried increasing the border-bottom of my h1 element by 1px and giving the nav ul element a margin-top of -1px which partially works, however this issue will still appear at differnt resolutions or orientation.
I am wondering if anybody knows why this happens and hopefully a solution.
Try using this, see if that's what you need :
https://jsfiddle.net/1r7hp15c/3/
CSS:
body {
width: 100%;
background-color: blue;
}
h1 {
font-size: 35px;
text-align: center;
color: yellow;
background-color: blue;
margin: 2%;
margin-bottom: 0px;
padding-top: 10px;
padding-bottom: 10px;
}
nav ul {
display: flex;
justify-content: space-between;
padding: 0;
margin: 0;
margin-left: 2%;
margin-right: 2%;
background:blue;
}
nav li {
font-size: 15px;
display: inline-block;
list-style-type: none;
background-color: blue;
color: yellow;
padding: 10px;
}
nav ul li a {
width: 67px;
display: inline-block;
text-align: center;
color: yellow;
text-decoration: none;
}
div{
padding: 20px;
background: yellow;
}
nav{
padding: 20px;
background: yellow;
margin-top: -1px;
}
HTML :
<header>
<div>
<h1>
SPACING
</h1>
</div>
</header>
<nav>
<ul>
<li>MARGIN</li>
<li>BORDER</li>
<li>PADDING</li>
</ul>
</nav>
Related
I'm trying to make a hover effect for my navbar links, in which when they're hovered, a border bottom line animates it's way in. I've tried using this:
li:hover a {
box-sizing: border-box;
width: 100%;
border: solid #F5F5F5 5px;
padding: 5px;
border-top: 0px;
border-left: 0px;
border-right: 0px;
}
This partially works, the bottom line appears when hovered (obviously with no animation cause I didn't do that part yet). The thing is that when they're hovered, not only a bottom border appears, but also al the options move, like if the border bottom causes the whole navbar to move each link a little in an opposite direction, like if they are trying to keep distance from each other. How can I fix this issue? I'll leave the HTML code of the navbar and some css code:
HTML:
<ul class="nav-links">
<li>HOME</a></li>
<li>PORTFOLIO</a></li>
<li>SUBMIT</a></li>
<li>CONTACT</a></li>
<li>ABOUT</a></li>
</ul>
CSS:
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
background-color: #900c3f;
}
img {
width: 130px;
margin-top: 20px;
margin-left: 20px;
margin-bottom: 20px;
}
nav {
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: #ff5733;
}
li:hover a {
box-sizing: border-box;
width: 100%;
border: solid #F5F5F5 5px;
padding: 5px;
border-top: 0px;
border-left: 0px;
border-right: 0px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 80%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
text-decoration: none;
font-family: Poppins;
color: #F5F5F5;
letter-spacing: 3px;
font-weight: bold;
font-size: 130%;
}
Are there any divs that should be added to the navbar? Or what I'm doing makes no sense? I'm still learning so it's possible that I'm making a mess.
Here's a screenshot just in case:
Screenshot of hovered navbar
Thanks SO community!
Is this what you asking? ( you have to view in full screen for good visualization)
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
background-color: #900c3f;
}
img {
width: 130px;
margin-top: 20px;
margin-left: 20px;
margin-bottom: 20px;
}
.nav-links {
display: flex;
justify-content: space-between;
width: 80%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
text-decoration: none;
font-family: Poppins;
color: #F5F5F5;
letter-spacing: 3px;
font-weight: bold;
font-size: 130%;
margin: 10px;
}
.nav-links li a:hover {
border-bottom: 5px solid white;
padding-bottom: 3px;
}
<ul class="nav-links">
<li>HOME</li>
<li>PORTFOLIO</li>
<li>SUBMIT</li>
<li>CONTACT</li>
<li>ABOUT</li>
</ul>
Add
li a {box-sizing: border-box;width: 100%;padding: 5px;border-top: 0px;border-bottom:0px;border-left: 0px;border-right: 0px;}
Note : when load, li a is showing. When hover, active li:hover a
I'm making an HTML web-page with Notepad++, but the navigation bar items won't adjust it's length to the screen. I could really need help with that.
Here is my code:
<head>
<style>
html {
height: 100%;
width: 100%;
}
body {
background-color: #FFE4E1;
font-family: jokerman, 'times new roman', serif;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
}
nav ul {
display: table;
width: 99, 5%;
height: 40px;
border: #F08080 4px solid;
list-style: none;
margin: 0;
padding: 0;
white-space: nowrap;
text-align: center;
}
nav ul li {
text-align: center;
float: left;
order: 1;
display: table-cell;
}
nav ul li a {
display: table-cell;
position: relative;
padding-left: 95.85px;
padding-right: 95.85px;
line-height: 41px;
border-right: #F08080 4px solid;
border-left: #F08080 4px solid;
text-decoration: none;
font-size: 20px;
color: #DAA520;
background-color: #CD5C5C;
}
inline li {
width: calc(100/5)
}
</style>
</head>
<body>
<div style="background-color: peachpuff">
<div id="Logo" style="background-color: darksalmon">
<img src="DragonaxeYT.jpg" alt="Logo" width="200">
<h1>DragonaxeYT.no</h1>
<nav>
<ul>
<li>Hjem</li>
<li>Kalender</li>
<li>Blogg</li>
<li>Om meg</li>
<li>Quizer</li>
</ul>
</nav>
</div>
</div>
</body>
Hope anyone knows how to fix it? I would like it to adjust itself so that the website would work well also on phones. Thanks in advance.
Update your nav ul li and nav ul li a with the following (I commented out code and added width style):
nav ul li{
text-align: center;
/*float: left;*/
order:1;
display: table-cell;
}
nav ul li a{
display: table-cell;
position: relative;
/*padding-left: 95.85px;*/
/*padding-right: 95.85px;*/
line-height: 41px;
border-right: #F08080 4px solid;
border-left: #F08080 4px solid;
text-decoration: none;
font-size: 20px;
color: #DAA520;
background-color: #CD5C5C;
// New style
width: 20vw;
}
View this is action in Codepen: https://codepen.io/Tiarhai/pen/WgGPbj
So I try to change li's vertical position but when I do the nav bar height is affected as well. What is the way to actually do that without affecting nav bar's height?
Here's the code:
body {
margin: 0px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
padding-left: 5px;
padding-top: 10px;
background-color: #333;
overflow: hidden;
}
li {
float: left;
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
What is your goal here? To have the content centered or...?
It may be better to use flexbox here rather than set the padding-left: 850px; on your ul (also on your ul you could've used display: block; margin: 0 auto; to center it.) If you'd like, you can give your ul a defined height and use align-items to specify how it should be aligned vertically.
body {
margin: 0;
}
nav {
background-color: #333;
display: flex;
justify-content: center;
}
nav ul {
display: flex;
justify-content: center;
list-style: none;
margin: 0;
padding: 0;
height: 50px;
align-items: center;
}
li {
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<body>
<nav>
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
</nav>
</body>
You can add position: relative; and a value for bottom or top- in my snippet bottom: 4px;:
This reserves the space originally taken by the element (without position: relative;), but moves the element according to the top/bottom/left/right settings, without affecting other elements.
body {
margin: 0px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
padding-left: 5px;
padding-top: 10px;
background-color: #333;
overflow: hidden;
}
li {
float: left;
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
position: relative;
bottom: 4px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
I have a pestering question I'd like an opinion on. I apologize if this has been answered. I have looked at similar questions, and tried the solutions, but I can't find the one that works for me.
I am working on a personal website right now and I have the home page how I like it, but I am trying to get the experience page to display correctly. Right now, I am trying to have 3-4 "cards" of content. The first two should show up in the main section side by side, and the third (and fourth if necessary) should show up below them as follows"
1 2
3 (centered, ideally the width of the first two items)
OR
1 2
3 4
Currently no matter what I try (clearing, changing the flex direction, etc) I am getting the following with the items squished together.
1 2 3...
I have attached my full styles.css (I apologize for the mess) so someone brighter than me can hopefully help me resolve the problem, and a snippet of my HTML so you can get an idea of how I am using this.
Thank you so much in advance!!!
Styles.css
/* Global Layout Set-up */
{
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
text-align: center;
font-family: 'Roboto', sans-serif;
color: #222;
background: #f7f5f0;
}
/* Link Styles */
a {
text-decoration: none;
color: #0499ff;
}
a:hover {
color: #6633ff;
}
/* Section Styles */
.main-nav {
width: 100%;
background: black;
min-height: 30px;
padding: 10px;
position: fixed;
text-align: center;
margin: auto;
}
.nav {
display: flex;
justify-content: space-around;
font-weight: 700;
list-style-type: none;
margin: 0 auto;
padding: 0;
}
.nav .name {
display: none;
}
.nav li {
padding: 5px 10px 5px 10px;
}
.nav a {
transition: all .5s;
}
.nav a:hover {
color: white
}
header {
text-align: center;
background: url('images/realrocket5.jpg') no-repeat top center ;
background-size: cover;
overflow: hidden;
padding-top: 60px;
}
header {
line-height: 1.5;
}
header .profile-image {
margin-top: 50px;
width: 150px;
height: 150px;
border-radius: 50%;
border: 3px solid black;
transition: all .5s;
}
header .profile-image:hover {
transform: scale(1.2) rotate(360deg);
}
.tag {
background-color: #efefef;
color: black;
padding: 10px;
border-radius: 5px;
display: table;
margin: 10px auto;
}
.location {
background-color: #222;
color: white;
}
.card {
float: left;
max-width: 40%;
margin: 30px;
padding: 20px 40px 20px;
text-align: left;
background: #fff;
border-bottom: 4px solid #ccc;
border-radius: 6px;
}
.card-below{
float: left;
margin: 30px;
padding: 20px 40px 40px;
text-align: left;
}
.card:hover {
border-color: #0399ff;
}
ul.skills {
padding: 0;
text-align: center;
}
.skills li {
border-radius: 6px;
display: inline-block;
background: #ff9904;
color: white;
padding: 5px 10px;
margin: 2px;
}
.skills li:nth-child(odd) {
background: #0399ff;
}
footer {
width: 100%;
min-height: 30px;
padding: 20px 0 40px 20px;
}
footer .copyright {
top: -8px;
margin-right: 20px;
font-size: .75em;
}
footer ul {
list-style-type: none;
margin: 0;
padding: 0;
}
footer ul li {
display: inline-block;
}
a.social {
display: inline-block;
text-indent: -9999px;
margin-left: 5px;
width: 30px;
height: 30px;
background-size: 30px 30px;
opacity: .5;
transition: all .25s;
}
a.twitter {
background-image: url(images/twitter.svg);
}
a.linkedin {
background-image: url(images/linkedin.svg);
}
a.github {
background-image: url(images/github.svg);
}
a.social:hover {
opacity: 1;
}
.clearfix {
clear: both;
}
/* Styles for larger screens */
#media screen and (min-width: 720px) {
.flex {
display: flex;
max-width: 1200px;
justify-content: space-around;
margin: 0 auto;
}
.flex-column {
flex-direction: column;
}
header {
min-height: 450px;
}
.nav {
max-width: 1200px;
}
.nav .name {
display: inline-block;
border: solid #2204ba 3px;
border-radius: 15px;
background-color: #222;
margin-right: auto;
margit-left: left;
text-align: center;
color: #0399ff;
}
.nav .navbar {
display: inline-block;
border: solid #2204ba 3px;
border-radius: 15px;
background-color: #222;
margin-right: 5px;
text-align: center;
color: #0399ff;
}
main {
padding-top: 50px;
}
main p {
line-height: 1.6em;
}
footer {
font-size: 1.3em;
max-width: 1200px;
margin: 40px auto;
}
}
h3 {
color: black;
letter-spacing: 0.5px;
}
.card-title {
text-align: center;
border: solid black 3px;
border-radius: 10px;
background-color: #222;
color: white;
}
HTML
<main class="flex">
<div class="card">
<h2 class="card-title">Card1</h2>
<p>Stuff goes here, up to 500px wide</p>
</div>
<div class="card">
<h2 class="card-title">Card2</h2>
<p>More stuff goes here up to 500px wide</p>
</div>
<div class="card">
<div class="flex-column">
<h2 class="card-title">Card3</h2>
<p>The problem card. This stuff needs to go below card one in its own card.</p>
</div>
</div>
</main>
If I only use two cards per page they appear side by side correctly. When trying to add a third, it just goes beside the last card and I can't for the life of me figure out how to make it go below. Ideally, if using 3 cards the first two would be centered side by side, then the third would be centered below the same width as the first two cards combined. If a 4th card is used, I'd like it to basically be a square. Thank you so much for any input!!!!
.wrap {
width: 500px;
background: gray;
margin: auto;
padding: 10px;
margin-bottom: 20px;
}
.row {
display: flex;
justify-content: center;
}
.box {
padding: 20px;
background: yellow;
min-width: 75px;
flex-grow: 1;
margin: 2px;
text-align: center;
}
<div class="wrap">
<div class="row">
<div class="box">
Box One
</div>
<div class="box">
Box Two
</div>
</div>
<div class="row">
<div class="box">
Box Three
</div>
</div>
</div>
<div class="wrap">
<div class="row">
<div class="box">
Box One
</div>
<div class="box">
Box Two
</div>
</div>
<div class="row">
<div class="box">
Box Three
</div>
<div class="box">
Box Four
</div>
</div>
</div>
So I'm building a website in html and css. I have made a navigation bar with the links, but when I zoom out, the links go underneath one another instead of inline. If someone can give me some pointers, that'd be great. Thanks
<html>
<head>
<link rel="stylesheet" href="style/style.css" />
</head>
<body>
<div class="wrap">
<div class="logo"><img src="img/logo.png"></div>
<div class="nav">
<ul>
<li>HOME</li>
<li>PRODUCTS</li>
<li>SHOPS</li>
<li>FAQ</li>
<li>ABOUT US</li>
</ul>
</div>
<div class="main">
</div>
</div>
</body>
</html>
body {
padding: 0;
margin: 0;
background: #1b1b1b url('../img/bg.jpg') no-repeat fixed top center;
}
.logo {
margin-bottom: 10px;
margin: auto;
width: 524px;
}
.wrap {
width: 960px;
margin: auto;
}
.nav {
height: 37px;
background-color: rgba(26,26,26,0.8);
border: 1px solid black;
margin-bottom: 10px;
}
ul {
margin: 0;
padding: 0;
text-align: center;
line-height: 38px;
}
ul li {
display: inline;
color: #828282;
padding: 2px 40px;
background: #595959;
border:1px solid #828282;
margin: 0 10px;
}
ul li a {
text-decoration: none;
color: white;
font-family: arial;
}
ul li a:hover {
}
.main {
min-height: 300px;
height: auto;
background-color: rgba(26,26,26,0.8);
border: 1px solid black;
}
"the links go underneath one another instead of inline"
To fix this, you will want to add the float: left; property to your li like so:
ul li {
display: inline-block;
float: left;
color: #828282;
padding: 2px 40px;
background: #595959;
border:1px solid #828282;
margin: 0 10px;
}