How to position buttons in css without this happening? [duplicate] - html

This question already has answers here:
Why does position:relative; appear to change the z-index?
(2 answers)
Closed 1 year ago.
Here is the CSS and HTML code, the problem is told below.
* {
box-sizing: border-box;
font-family: Georgia, 'Times New Roman', Times, serif;
}
body {
margin: 0;
font-family: Georgia, 'Times New Roman', Times, serif;
}
.topnav {
overflow: hidden;
background-color: #F5CB5C;
list-style-type: none;
text-align: center;
margin: 0;
padding: 0;
position: fixed;
top: 0;
width: 100%;
}
.topnav li {
display: inline-block;
font-size: 20px;
padding: 20px;
}
.topnav a {
color: #242423;
text-align: center;
text-decoration: none;
}
.topnav li:hover {
background-color: #E8EDDF;
color: black;
}
.topnav li:active {
background-color: #E8EDDF;
color: black;
}
/* ITEM ABOVE DOES NOT WORK, FIX ASAP! */
.content {
background-color: #242423;
padding: 10px;
color: #E8EDDF;
}
.footer {
background-color: #F5CB5C;
padding: 10px;
color: #242423;
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width: 20em;
border-radius: 10px;
border-color: #FFFFFF;
max-width: 100%;
height: auto;
object-fit: cover;
margin: 1em;
}
.card-button {
background-color: #ddd;
position: relative;
border: none;
color: black;
padding: .5em 1em;
text-align: center;
text-decoration: none;
float: right;
left: .5em;
bottom: .5em;
cursor: pointer;
border-radius: 16px;
font-size: 16px;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.container {
padding: 2px 16px;
}
.card img {
border-radius: 10px 10px 0 0;
}
.text-center {
text-align: center;
}
.center {
right: 50%;
}
.title {
margin-top: 2em;
text-align: center;
}
.grid-gallery {
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.spacer {
width: 100%;
height: 2em;
}
and here is HTML,
<div class="card">
<img src="https://d3vjn2zm46gms2.cloudfront.net/blogs/2016/05/27005442/Roman-cup_w1280px_h720px.png" alt="Silver Cup" style="width:100%">
<div class="container">
<h4><b>Roman Silver Cup</b></h4>
<button class="card-button">Buy Now</button>
<p>$89.99</p>
</div>
</div>
and here is the problem the buttons are showing over the fixed navigation bar. Can anyone explain why?

I would look into the CSS z-index property, which allows you to specify that some item (such as the top nav bar) should always be above other items (or that other items should be below the top nav bar).
https://www.w3schools.com/cssref/pr_pos_z-index.asp

I think you're searching for z-index.
It allows you to set the z-order of a positioned element (meaning that you need to provide a position to your element otherwise it won't work).
You can find more information here.
So in your case, you should add something like z-index: 999;.

This is happening because your button has position: relative; property. Use z-index property. Add z-index: 1000; to your class .topnav. So that navbar stays at top of all.
.topnav {
// other
z-index: 1000;
}
Or add z-index: -1; to your .card-button class.
.card-button {
// other
z-index: -1;
}

Related

HTML element set to visible but still invisible

I am currently working on a website and I have an element that I have explicitly declared: display: inline-block and visibility: visible however, the element is still invisible. This is only occurring on mobile devices. The invisible element is <div id="clock">.
#font-face {
font-family: 'bitwise';
src: url('bitwise.ttf');
font-display: swap;
}
* {
font-family: 'bitwise', monospace;
margin: 0;
padding: 0;
outline: 0;
}
:root {
background-color: #008080;
}
body,
html,
.wrapper {
width: 100%;
height: 100%;
}
span {
color: #FFFFFF;
font-size: 18pt;
text-align: center;
display: inline-block;
}
h1 {
color: #FFFFFF;
text-align: center;
display: inline-block;
}
input {
font-family: 'bitwise', monospace;
background-color: #535353;
color: #FFFFFF;
font-size: 18pt;
overflow: hidden;
text-align: center;
line-height: inherit;
height: inherit;
}
img:not(.noresize) {
width: 35%;
height: 35%;
}
video {
width: 35%;
height: 35%;
}
a:link {
color: #EFCF7C;
}
a:visited {
color: #105733;
}
button {
background-color: #105733;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 18px;
margin: 4px 2px;
}
#back {
background-color: #660000;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 18px;
margin: 4px 2px;
}
#taskbar {
position: absolute;
overflow: hidden;
bottom: 0;
width: 100%;
height: 27px;
background-color: silver;
box-shadow: inset 0px 1px #dfdfdf, inset 0px 2px #ffffff;
}
.center {
display: flex;
flex-wrap: wrap;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
text-align: center;
align-items: center;
justify-content: center;
}
#start {
float: left;
}
#clock {
float: right;
position: relative;
text-align: center;
}
#clocktime {
font-family: 'Arial', serif;
font-size: 13px;
color: #000000;
position: relative;
bottom: 23px;
left: 17px;
}
#icons {
padding-top: 8px;
}
#content {
padding-top: 10px;
}
.break {
flex-basis: 100%;
height: 0;
}
#content {
width: 675px;
height: 300px;
}
#media screen and (max-width: 1079px) {
html,
body {
overflow: hidden;
}
#clock {
float: right;
position: relative;
bottom: 100px;
text-align: center;
display: inline-block;
visibility: visible;
}
#clocktime {
font-family: 'Arial', serif;
font-size: 13px;
color: #000000;
position: relative;
bottom: 23px;
left: 17px;
}
}
<div id="taskbar">
<div id="start"><img class="noresize" src="/assets/start.png"></div>
<div id="clock"><img class="noresize" src="/assets/clock.png">
<div id="clocktime"></div>
</div>
</div>
<div id="icons"><img class="noresize" src="/assets/icons.png"></div>
<div class="center"><img class="noresize" src="/assets/ie.png"></div>
<div class="center" id="content">
Content here.
</div>
Screenshot 1 - What the page should look like. Note the clock in the lower-right corner.
Screenshot 2 - What the page actually looks like on mobile.
Screenshot 3 - Chrome DevTools showing the element as being in a visible spot, but still not being visible.
I see that that css is only appliable when max-width is equal to 1079px.
Try to increase that number in inspector element to see what happens.
So it turns out I had overflow: hidden set on #taskbar and this means that any children inside of the taskbar will not display, even if they are in a "visible" area. Adding bottom: 32px to set it inside of the taskbar worked.
Updated CSS:
#taskbar {
position: absolute;
overflow: hidden;
bottom: 0;
width: 100%;
height: 27px;
background-color: silver;
box-shadow: inset 0px 1px #dfdfdf, inset 0px 2px #ffffff;
}
<snip>
#media screen and (max-width: 1079px) {
#clock {
bottom: 32px;
}
}

Why has my website got a horizontal scroll bar? [duplicate]

This question already has an answer here:
Why do I have scroll bars on my website when there shouldn't be?
(1 answer)
Closed 1 year ago.
I'm making a discord server website for people to find discord servers to join and make
friends but, I dont know why my web page has a horizontal scroll bar. It also had a vertical scroll
bar but I got rid of that,
anyway here is my HTML and CSS
html {
font-family: Arial, Helvetica, sans-serif;
background-color: #414141;
text-decoration: none;
}
body {
background-color: #414141;
}
:root {
--navbar-height: 4rem;
--header-height: 14rem;
--main-min-height: 240rem;
}
body {
height: 100vh;
min-width: 480;
margin: 0;
padding: 0;
font-family: Helvetica;
display: grid;
grid-template-rows: minmax(var(--navbar-height), auto) minmax(var(--main-min-height) 1fr) auto;
}
.topnav {
overflow: hidden;
padding: 0px 15px;
height: var(--navbar-height);
color: white;
}
.topnav a {
font-size: 20;
float: left;
color: #f2f2f2;
text-align: center;
padding: 22px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
color: #788ce2;
}
.topnav-right {
float: right;
}
.row::after {
clear: both;
display: table;
}
.copyright {
position: absolute;
bottom: 1%;
right: 1%;
font-size: 15px;
}
.copyright-text {
color: white;
}
.footer-links {
position: absolute;
bottom: 5%;
}
.link-text {
position: absolute;
bottom: 10%;
color: white;
text-decoration: none;
}
.container {
padding: 0;
margin: 0;
}
li {
position: relative;
left: 100%;
}
footer {
position: absolute;
bottom: 0%;
height: 300px;
width: 100%;
color: #fff;
background: #2c2c2c;
}
.welcome {
margin-top: -2.5rem;
width: 100%;
height: 35.5rem;
line-height: 1.8em;
margin-bottom: .4em;
padding: 0;
font-family: Helvetica;
font-weight: 600;
font-size: 1.5em;
color: #ffff;
text-transform: uppercase;
}
.centered-text {
position: relative;
margin-left: 25%;
display: flex;
align-items: center;
padding: 0 1.5rem;
}
.discord-logo {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
display: inline-block;
padding: .6em 0;
background: url(images/Discord-Wordmark-White.png) center no-repeat;
background-size: contain;
font-size: 1em;
}
.head {
margin-bottom: .4em;
padding: 0;
line-height: 1.4;
font-weight: 600;
font-size: 2em;
}
.body {
position: relative;
margin-left: 24.5%;
margin: 0 auto 1em;
text-transform: inherit;
opacity: 85%;
}
.search-box {
position: absolute;
top: 90%;
left: 18%;
background: #2c2c2c;
height: 40px;
border-radius: 40px;
padding: 10px;
}
.search-box:hover>.search-txt {
width: 260px;
padding: 0 6px;
}
.search-btn {
color: white;
float: right;
width: 40px;
height: 40px;
border-radius: 100%;
background: black;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
}
.search-box:hover>.search-btn {
background: white;
color: black;
}
.search-txt {
border: none;
background: none;
outline: none;
float: left;
padding: 0;
color: white;
font-size: 16px;
transition: 0.4s;
line-height: 40px;
width: 0px;
}
.navbar-servers {
color: white;
float: right;
}
.title-right {
position: absolute;
right: 25%;
}
body {
color: #e6e6e6;
font-size: 1em;
font-weight: 400;
line-height: 1.5;
}
h1 {
position: absolute;
left: 42%;
top: 10%;
}
.last-modified {
position: absolute;
left: 40.6%;
top: 17%;
}
.terms-of-service-align {
position: absolute;
left: 1%;
top: 25%;
}
.site-footer .site-footer--container,
.site-footer .site-footer--extra {
max-width: 1264px;
width: 100%;
margin: 0 auto;
padding: 32px 12px 12px 12px;
display: flex;
flex-flow: row wrap;
}
.site-footer--container,
.site-footer--extra {
max-width: 1264px;
}
.site-footer,
.site-footer *,
.site-footer *:before,
.site-footer *:after {
box-sizing: border-box;
}
h5,
h6 {
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
}
.site-footer {
background-color: #242729;
background-image: none;
background-position: top left;
background-repeat: no-repeat;
border-top: 0;
background-size: auto;
color: #6a737c;
padding-top: 0;
padding-bottom: 0;
}
.discord {
color: #788ce2;
font-weight: 800;
}
.guidelines {
color: #788ce2;
font-weight: 800;
}
.hidden {
position: absolute;
top: 520%;
height: 0px;
opacity: 0%;
}
.main-header {
position: absolute;
left: 41%;
}
.all {
position: relative;
top: 10%;
left: 28%;
}
<nav class="topnav">
<div>
<h2 class="title-right">
OnTop Servers
</h2>
</div>
</nav>
<div class="main-container">
<h1 class="main-header">
Guidelines</h1>
<p class="last-modified">
Last Modified: 2020-11-22
</p>
<div class="all">
In order to keep a safe community, there are some guidelines which need to be followed by you<br> By using DISBOARD, you agree to the following guidelines:<br><br> The use of swear words, dirty words or NSFW (sexual content) to our discretion in a
server's meta (title,<br> description and picture), review or other content that may be seen by other users in DISBOARD is not<br> allowed. This will lead to the removal of the content, however, you'll be able to repost the content with a<br> proper
language.<br>
<Br> You may not violate any laws or regulations in your country of residence or promote the violation of them.<br><br> Servers violating <a class="discord" href="https://discord.com/guidelines">Discord Community Guidelines</a> are not allowed.<br><br> The use of bots or other scripts to automatically do actions in DISBOARD such as bumping a server ("auto-<br> bump") is not allowed. Bumping, creating reviews and etc. must be done manually.<br><br> You may not list servers which serve for the sole
purpose of redirecting or advertising other servers or have<br> no content (To our discretion).<br><br> You may not reward or force users to do actions in DISBOARD. For instance, you may not reward your users<br> for posting a nice review on a server
or force them to bump a server.<br><br> You may not create multiple Discord accounts to submit multiple reviews. Please just post 1 review per<br> person.
<br><br> All servers which are mainly based on NSFW (sexual content to our discretion) must be marked as "NSFW"<br> in DISBOARD.<br><br>
<div class="TOS">
See also our <a class="discord" href="termsofservice.html">Term of Services</a>
</div>
</div>
How do I fix, please help me with this...
I dont know what to do, I gone through almost everything on the page, I don know.
position: relative; left:28% pushes the element beyond the window width creating an overflow to the right.
.all {
position: relative;
top: 10%;
left: 28%;
}
you can try using padding or margin instead
Instead of putting left: 28% for your div, use padding-left: 28%. It should be a little fix.

My dropdown content won't show but it did before I moved my header

I had a simple website and everything worked perfectly but I wanted to make it more modern but I don't know what I changed that made my dropdown menu stop working.
I am new to coding btw and I use Visual Studio Code.
I haven't tried anything because I don't want to screw up my website.
My HTML and CSS code (see also jsfiddle):
<div class="header" id="header">
<span id="header-title">Nellfin Solutions</span>
<div class="dropdown">
<span id="menu">&#9776 Menu</span>
<div class="dropdown-content">
Home
Services
Products
About Us
Contact Us
</div>
</div>
</div>
#import url(http://fonts.googleapis.com/css?family=Monstserrat:400,700);
body {
background-image: url("backround.jpg");
background-repeat:no-repeat;
background-size:cover;
color: #555;
margin: 0;
font-family: 'Montserrat', sans-serif;
background-color: rgba(255, 255, 255, 0.979);
}
.header {
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
#header {
background-color: white;
height: 50px;
line-height: 50px;
position: fixed;
margin-top: 20px;
width: 80%;
transform: translate(12%, 0%)
}
#header-title {
float: right;
margin-right: 50px;
font-size: 20px;
color: orange;
}
.dropdown {
position: relative;
display: inline-block;
background-color: white;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #555;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
text-align: left;
overflow: auto;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
color: orange;
background-color: #6F6F6F;
}
#menu {
text-transform: uppercase;
letter-spacing: 0.1em;
margin: 10px;
margin-top: 0px;
color: orange;
font-weight: bold;
position: relative;
}
.body h1 {
position: relative;
padding-top: 100px;
padding-left: 200px;
text-transform: uppercase;
color: orange;
}
Because of the relative position in .body h1, it changes the z-index position. You can decrease the position of your .body h1 to below 0.
.body h1 {
z-index: -1;
}
Or you can remove the position for h1.
.body h1 {
position: relative(no need to use this css line)
}
Hover for dropdown doesn't work because you put body in front of it (you can use inspector to see that). so bring header to front by:
.header {
z-index: 1000;
}
Fiddle: fiddle

text stuckt to the header? [duplicate]

This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Closed 4 years ago.
I’m trying to move my text to the middle of my header on the image but as soon as I move it the whole header follows. Could someone try to help me solve this issue? As you see I’m trying to make it using margin-top but when I implement this the header follows. I have closed all the divs that affects the image.
html, body {
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
body {
font-family: 'Josefin Sans', sans-serif;
text-align: center;
}
header {
width: 100%;
height: 400px;
background: url(/assets/image/tjanst.jpg) no-repeat 50% 50%;
background-size: cover;
}
.content {
width: 94%;
margin: 4em auto;
font-size: 20px;
line-height: 30px;
text-align: justify;
}
.logo {
line-height: 60px;
position: fixed;
float: left;
margin: 16px 46px;
color: #fff;
font-weight: bold;
font-size: 20px;
letter-spacing: 2px;
}
nav {
position: fixed;
width: 100%;
line-height: 60px;
z-index: 10;
}
nav ul {
line-height: 60px;
list-style: none;
background: rgba(0, 0, 0, 0);
overflow: hidden;
color: #fff;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
nav.black ul {
background: #000;
padding: 16px 40px;
}
nav ul li {
display: inline-block;
padding: 16px 40px;
}
.move-down h3{
margin-top: 200px;
max-width: 400px;
}
nav ul li a {
font-family: 'Josefin Sans', sans-serif;
font-size: 14px;
color: #fff;
font-weight: 600;
text-transform: uppercase;
text-decoration: none;
}
a {
color: #fff;
text-decoration: none;
}
.menu-icon {
line-height: 60px;
width: 100%;
background: #000;
text-align: right;
box-sizing: border-box;
padding: 15px 24px;
cursor: pointer;
color: #fff;
display: none;
}
#media(max-width: 786px) {
.logo {
position: fixed;
top: 0;
margin-top: 16px;
}
nav ul {
max-height: 20px;
background: #000;
}
nav.black ul {
background: #000;
}
.showing {
max-height: 34em;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 24px;
text-align: center;
}
.menu-icon {
display: block;
}
}
<header>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo wow tada">
</div>
<div class="menu">
<ul>
<li>START</li>
<li>TJÄNSTER</li>
<li>OM OSS</li>
<li>KONTAKT</li>
</ul>
</div>
</nav>
<div class="move-down wow fadeInUp"><h3> VILL GÖRA KUNDEN NÖJD</h3>
<h3> tel: 070719763 </h3></div>
</header>
how it looks now
https://i.stack.imgur.com/vOQGa.png
Well remove 'margin-top: 200px;' in the '.move-down h3' and add 'padding: 200px 0px 0px 0px;' or 'padding-top: 200px;'
Yes, Simple solution is.
Add this CSS
h3{
maring:0;
}
Hope this helps.
Instead of adding margin-top add top value to relatively positioned element.
.move-down h3 {
max-width: 400px;
position: relative;
top: 205px;
}
https://jsfiddle.net/6uedrb89/12/

Element after other Element higher on page?

I can't get an element to go where I want it to. I am only having this problem because of the way I did my header. I applied position: absolute. You can see an example here: http://jacobgasser.com and you can find all the code on there, or you can read down a little farther and I put it there.
I want the text in the top left of the page to be on the white part of the page
Here is the index.html
<body onload="loadUp();">
<div class="menu">
<a href="https://github.com/jacobgasser" target="_blank"><div
class="menuItem">Projects</div></a>
</div>
<div class="titleBG">
<h1 class="title" onmouseover="coolThing();"onmouseout="notCoolThing();">Jacob Gasser</h1>
</div>
<div class="article">
<div class="articleHead">Who am I?</div>
</div>
<script src="scripts/main.js"></script>
</body>
Here is main.css
body {
margin:0;
padding:0;
}
.title {
color: white;
text-align: center;
font-size: 1000%;
opacity: 0;
-webkit-transition: 0.2s;
}
a {
text-decoration: none;
color: inherit;
}
.article {
font-family: "Arial";
display: inline-block;
padding: 5px 10px 5px 10px;
margin: 5px 10px 5px 10px;
text-align: center;
position: relative;
}
.articleHead {
display: inline-block;
padding: 5px 10px 5px 10px;
margin: 5px 10px 5px 10px;
}
.menu {
display: block;
color: white;
float: right;
margin-right: 10px;
margin-top: 5px;
opacity: 0;
}
.menuItem {
font-size: 400%;
display: block;
padding-left: 20px;
padding-right: 20px;
-webkit-transition: 0.2s;
border-radius: 5px;
}
.menuItem:hover {
background-color: white;
color: black;
cursor: pointer;
-webkit-transition: 0.2s;
}
.titleBG {
background-color: #23272A;
display: block;
width: 100%;
z-index: -1;
position: fixed;
top: 0;
}
::selection {
color: #23272A;
background-color: white;
}
::-moz-selection {
color: #23272A;
background-color: white;
}
#font-face {
font-family: lemon;
src: url("fonts/LemonMilk.otf");
}
#font-face {
font-family: cavs;
src: url("fonts/CaviarDreams.ttf");
}
A simple solution to this issue is to remove the position: fixed; top: 0; and adjust the margin-top and margin-bottom of the page. Just change the CSS for .titleBG and .title to be the following:
.titleBG {
background-color: #23272A;
display: block;
width: 100%;
z-index: -1;
}
.title {
color: white;
text-align: center;
font-size: 1000%;
opacity: 0;
-webkit-transition: 0.2s;
margin: 0 /* You can add a margin-left or margin-right if you want, or even margin-bottom, just keep the margin-top at 0*/;
}
This will give you the following result: