I added a button to my code, I wanted to make it transparent but then it made a huge gap at the top and I want the button to eb placed in the middle but I really have no idea on how to do it.
Here are some image examples
https://i.gyazo.com/3b6d5f86f5a6ec84ca61e499b2411079.jpg[^]
https://i.gyazo.com/d086228702c62d79bf5fdeb518089c7e.jpg[^]
as you can see in this picture I changed the background color to transparent
why is it making that huge gap at the top? The button is still there but since its a white background I cant see it and I would like to move the button down to the middle
}
button {
background-color: Transparent;
background-repeat:no-repeat;
cursor:pointer;
overflow: hidden;
outline:none;
height: 38px;
line-height: 40px;
border: 2px solid white;
display: inline-block;
float: none;
text-align: center;
width: 120px;
padding: 0px!important;
font-size: 14px;
color: #fff;
}
button:hover {
color: #fff;
background: rgba(255, 255, 255, 0.2);
}
/*Menu CSS*/
#sidebar {
background: #151718;
width: 200px;
height: 17%;
display: block;
position: absolute;
left: -200px;
top: 0px;
transition: left 0.3s linear;
z-index: 1000;
}
#sidebar.visible {
left: 0px;
transition: left 0.3s linear;
}
ul {
margin: 0;
padding: 0;
}
ul li {
list-style: none;
}
ul li a {
background: #1C1E1F;
color: #ccc;
border-bottom: 1px solid #111;
display: block;
width: 180px;
padding: 10px;
text-decoration: none;
}
#sidebar-btn {
display: inline-block;
vertical-align: middle;
width: 20px;
height: 150px;
cursor: pointer;
margin: 20px;
position: absolute;
top:0px;
right:-60px;
}
#sidebar-btn span {
height: 1px;
background:#ffffff;
margin-bottom: 5px;
display: block;
}
#sidebar-btn span:nth-child(2) {
width: 75%;
}
#sidebar-btn span:nth-child(3) {
width: 50%;
}
/*Menu CSS*/
</style>
</head>
<body>
<div id="sidebar">
<ul>
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
<div id="sidebar-btn">
<span></span>
<span></span>
<span></span>
</div>
</div>
<!-- Buttons for email subscriptions and stuff -->
<!-- Full Width Responsive Slider -->
<div class="container">
<div style="background-color: transparent; text-align: center; padding: 10px"><button>Contact Us</button></div>
<div class="cycle-slideshow">
<span class="cycle-prev">〈</span>
<span class="cycle-next">〉</span>
<span class="cycle-pager"></span>
<img src="images/wp5.jpg">
<img src="images/wp6.jpg">
<img src="images/wp7.jpg">
</div>
<!-- Full Width Responsive Slider -->
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#sidebar-btn').click(function(){
$('#sidebar').toggleClass('visible');
});
});
</script>
</body>
</html>
please you can add in
.button{
position:fixed;
top:40%
}
Here is the layout wanna to achieve. If there something you don't understand, you can ask.
I suggest try construct your css and your html.
Example
CSS
.centering{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
DEMO
Related
I'm creating a menu for my site and I don't know how to keep the selected item checked.
At the moment it keeps bouncing back to the first one.
nav {
margin: 27px auto 0;
position: relative;
width: 590px;
height: 50px;
background-color: #34495e;
border-radius: 8px;
font-size: 0;
}
nav a {
line-height: 50px;
height: 100%;
font-size: 15px;
display: inline-block;
position: relative;
z-index: 1;
text-decoration: none;
text-transform: uppercase;
text-align: center;
color: white;
cursor: pointer;
}
nav .animation {
position: absolute;
height: 100%;
top: 0;
z-index: 0;
transition: all .5s ease 0s;
border-radius: 8px;
}
a:nth-child(1) {
width: 100px;
}
a:nth-child(2) {
width: 110px;
}
nav .start-home, a:nth-child(1):hover~.animation {
width: 100px;
left: 0;
background-color: #1abc9c;
}
nav .start-about, a:nth-child(2):hover~.animation {
width: 110px;
left: 100px;
background-color: #e74c3c;
}
p {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
color: #ecf0f1;
font-family: 'Cherry Swash',cursive;
font-size: 16px;
}
span {
color: #2BD6B4;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main_menu.css">
</head>
<body>
<nav>
test
foo1
<div class="animation start-home"></div>
</nav>
</body>
</html>
Can someone help me to keep the clicked menu item selected. I don't want to have to use javascript. Is there a way to do this? I read something about an 'active' element.
Edit: Since #hackerfrosch thinks that the whole thing is easier with js, I tried that. But I don't know how I can assign a class to the buttons via js in my case. Can I specify the color that the button should have, since each button has a different color?
I searched a little further and completely remade the menu. The design is roughly the same and it works entirely without Javascript.
.slide-toggle{
display: none;
}
.slide-menu{
font-family: arial, sans-serif;
max-width: 600px;
margin: 50px auto;
overflow: hidden;
}
.slide-menu label{
width: 25%;
text-align: center;
display: block;
float: left;
}
.slide-menu label:hover{
cursor: pointer;
}
.slide-menu label span{
display: block;
padding: 20px 15px 15px;
color: white;
}
.slider{
width: 100%;
height: 100%;
display: block;
background: #415a75;
border-radius: 10px;
margin-top: 10px;
}
.slider .bar{
width: 25%;
height: 40px;
border-radius: 10px;
}
.slide-menu label, .slider .bar {
transition: all 500ms ease-in-out;
-webkit-transition: all 500ms ease-in-out;
-moz-transition: all 500ms ease-in-out;
}
.slide-menu .slide-toggle + label{
opacity: 1;
}
.slide-menu #slide-item-1:checked ~ .slider .bar{ margin-left: 0; background: #1abc9c }
.slide-menu #slide-item-2:checked ~ .slider .bar{ margin-left: 25%; background: #e74c3c }
.slide-menu #slide-item-3:checked ~ .slider .bar{ margin-left: 50%; background: #3498db }
.slide-menu #slide-item-4:checked ~ .slider .bar{ margin-left: 75%; background: #9b59b6 }
.slide-menu #slide-item-1:hover ~ .slider .bar{ margin-left: 0; background: #1abc9c }
.slide-menu #slide-item-2:hover ~ .slider .bar{ margin-left: 25%; background: #e74c3c }
.slide-menu #slide-item-3:hover ~ .slider .bar{ margin-left: 50%; background: #3498db }
.slide-menu #slide-item-4:hover ~ .slider .bar{ margin-left: 75%; background: #9b59b6 }
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main_menu.css">
<title></title>
</head>
<body>
<nav class="slide-menu">
<input onclick="location.href='#1'" type="radio" name="slideItem" id="slide-item-1" class="slide-toggle" checked/>
<label for="slide-item-1"><span>Home</span></label>
<input onclick="location.href='#2'" type="radio" name="slideItem" id="slide-item-2" class="slide-toggle"/>
<label for="slide-item-2"><span>About</span></label>
<input onclick="location.href='#3'" type="radio" name="slideItem" id="slide-item-3" class="slide-toggle"/>
<label for="slide-item-3"><span>Folio</span></label>
<input onclick="location.href='#4'" type="radio" name="slideItem" id="slide-item-4" class="slide-toggle"/>
<label for="slide-item-4"><span>Contact</span></label>
<div class="animation start-home"></div>
<div class="slider">
<div class="bar"></div>
</div>
</nav>
</body>
</html>
I have an html page which is using center aligned text. For some reason, the top title (#pageTitle id) is off by a bit, and looks like it has some added whitespace to the left of it. I tried to reproduce the problem here, but in the stack overflow editor, the formatting was completely wonky. Hopefully the scripts will be able to run on your machines. If anyone has any insight as to why this is happening I'd appreciate it. Thanks!
body {
padding: 0;
margin: 0;
}
/* center aligned vertically and horizontally*/
.totalCenter {
position: relative !important;
top: 50% !important;
left: 50% !important;
transform: translate(-50%, -50%) !important;
}
/* centered horizontally */
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
/* div for main page content */
#mainDiv {
width: 500px;
max-width: 500px;
}
.title {
padding: 0px;
margin: 0px;
margin-bottom: 15px;
}
/* login title */
#pageTitle {
font-size: 65px;
color: black;
margin-left: 0px;
padding-left: 0px;
}
#tagline {
font-size: 30px;
color: rgb(79, 79, 79);
margin-bottom: 22px;
}
/* input for email/password */
.infoInput {
text-align: center;
background-color: white;
border-radius: 8px;
margin-bottom: 10px;
outline-width: 0;
padding: 5px;
width: 100%;
height: 50px;
font-size: 22px;
}
/* login/register button */
.submitButton {
color: black;
background-color: rgb(255, 223, 0);
border: none;
border-radius: 4px;
border-bottom: 4px solid rgb(218, 189, 0);
cursor: pointer;
outline: none;
width: 100%;
height: 55px;
left: 10%;
font-size: 25px;
margin-top: 25px;
}
.submitButton:hover {
background: rgb(235, 204, 0);
transition: all 0.2s ease;
cursor: pointer;
}
.submitButton:active {
border: 0;
transition: all 0.2s ease;
}
.topBarButton {
border: none;
outline: none;
border-radius: 5px;
cursor: pointer;
width: 90px;
height: 40px;
margin: 10px;
font-size: 20px;
float: right;
}
#login {
color: black;
background-color: gold;
}
#register {
background-color: black;
color: gold;
}
#logo {
margin: 10px;
width: 40px;
height: 40px;
float: left;
}
<head>
<link href="/home/style/style.css" rel="stylesheet" />
</head>
<body>
<div id="topbar">
<img id="logo" src="/images/logo.png">
<button class="topBarButton" id="register">
Register
</button>
<button class="topBarButton" id="login">
Login
</button>
</div>
<div id="mainDiv" class="totalCenter">
<h1 id="pageTitle" class="title">title</h1>
<h2 id="tagline" class="title">page tagline</h2>
<input class="infoInput center" placeholder="Your Email..." id="email" name="email" type="email" required />
<button class="submitButton center">Next</button>
</div>
</body>
The title got padding because before you move it using left top and transform the logo image (which have float attribute) take a place at the left.
If you remove the top left and transform from the mainDiv you will see following:
This is where this whitespace come from.
You should add an element to clear:both under the toolbar (see snipped below)
body {
padding: 0;
margin: 0;
}
/* ADDED THIS*/
.clear{clear:both}
/* center aligned vertically and horizontally*/
.totalCenter {
position: relative !important;
top: 50% !important;
left: 50% !important;
transform: translate(-50%, 50%) !important;
}
/* centered horizontally */
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
/* div for main page content */
#mainDiv {
width: 500px;
max-width: 500px;
}
.title {
padding: 0px;
margin: 0px;
margin-bottom: 15px;
}
/* login title */
#pageTitle {
font-size: 65px;
color: black;
margin-left: 0px;
padding-left: 0px;
}
#tagline {
font-size: 30px;
color: rgb(79, 79, 79);
margin-bottom: 22px;
}
/* input for email/password */
.infoInput {
text-align: center;
background-color: white;
border-radius: 8px;
margin-bottom: 10px;
outline-width: 0;
padding: 5px;
width: 100%;
height: 50px;
font-size: 22px;
box-sizing:border-box;
}
/* login/register button */
.submitButton {
color: black;
background-color: rgb(255, 223, 0);
border: none;
border-radius: 4px;
border-bottom: 4px solid rgb(218, 189, 0);
cursor: pointer;
outline: none;
width: 100%;
height: 55px;
left: 10%;
font-size: 25px;
margin-top: 25px;
}
.submitButton:hover {
background: rgb(235, 204, 0);
transition: all 0.2s ease;
cursor: pointer;
}
.submitButton:active {
border: 0;
transition: all 0.2s ease;
}
.topBarButton {
border: none;
outline: none;
border-radius: 5px;
cursor: pointer;
width: 90px;
height: 40px;
margin: 10px;
font-size: 20px;
float: right;
}
#login {
color: black;
background-color: gold;
}
#register {
background-color: black;
color: gold;
}
#logo {
margin: 10px;
width: 40px;
height: 40px;
float: left;
}
<head>
<link href="/home/style/style.css" rel="stylesheet" />
</head>
<body>
<div id="topbar">
<img id="logo" src="/images/logo.png">
<button class="topBarButton" id="register">
Register
</button>
<button class="topBarButton" id="login">
Login
</button>
<div class="clear"></div><!-- ADDED THIS -->
</div>
<div id="mainDiv" class="totalCenter">
<h1 id="pageTitle" class="title">title</h1>
<h2 id="tagline" class="title">page tagline</h2>
<input class="infoInput center" placeholder="Your Email..." id="email" name="email" type="email" required />
<button class="submitButton center">Next</button>
</div>
</body>
You can use flex to align items which makes it easier:
body {
padding: 0;
margin: 0;
display: flex;
align-items: 'center';
justify-content: 'center';
}
.totalCenter {
display: flex;
justify-content: 'center';
}
When you set the display property to flex of a class you can use these properties:
align-items : aligns items vertically.
justify-content : alings items horizontally.
Flex is really cool if you cant to know more you can check out these two articles:
Aligning Items in a Flex Container
A Complete Guide to Flexbox
Please take a look at the following basic example:
html,
body {
height: 100%;
}
body {
margin: 0;
}
.sidebar {
height: 100%;
width: 300px;
background-color: pink;
float: left;
}
.students-list {
height: 100%;
width: 200px;
background-color: skyblue;
float: left;
}
<div class="sidebar">
Students List
</div>
<div class="students-list">
</div>
The pink div is a sidebar with a link. at first the second div which is the skyblue one, should be hidden, and when the user clicks on the link the whole div should slide smoothly from the left (From underneath the pink div).
Do any of you have a tip or can help me out how to achieve the animation?
EDIT: Is it possible to also use another button to slide out even a third div to the right of the second div?
Please check the below code
body {
font-family: "Roboto", sans-serif;
font-size: 18px;
overflow-x: hidden;
}
main {
padding: 40px 25px;
transition: .5s ease-in-out;
width: 100%;
}
nav {
background: #36a;
bottom: 0;
box-shadow: 0 0 5px #666;
height: 100%;
left: -17.5rem;
padding-top: 38px;
position: absolute;
top: 0;
transition: .5s ease-in-out;
width: 17rem;
user-select: none;
}
nav a {
color: #eee;
display: block;
padding: 12px 16px;
transition: .5s;
text-decoration: none;
-webkit-user-drag: none;
}
nav a:hover {
background-color: #39c;
}
#nav-collapse {
padding: 8px 12px;
position: absolute;
right: 0;
top: 0;
}
#nav-expand {
background-color: #333;
color: #eee;
display: block;
left: 0;
top: 0;
padding: 8px 12px;
position: absolute;
text-decoration: none;
transition: .5s linear;
user-select: none;
-webkit-user-drag: none;
}
#nav-expand:focus {
opacity: 0;
}
#nav-expand:focus ~ main {
margin-left: 17rem;
transition-delay: .25s;
}
#nav-expand:focus ~ nav {
left: 0;
transition-delay: .25s;
}
#nav-expand:hover {
background-color: #369;
color: #fff;
}
.icon {
display: inline-block;
background-position: center;
background-repeat: no-repeat;
height: 12px;
width: 12px;
}
.icon-cross {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAAABHNCSVQICAgIfAhkiAAAAPdJREFUGJV1jz9LhWAYxc+9rVZDQ+DcEI0NLU19gxr6Ci3tuvjnA+gggSBt4qzzO90b5FBubkHgEM1CBL5K93Ia8jWv4G88/A7PeQAArusekXwRQpiGYSzQ4/v+Gcn3OI6vMRJf+cdWFXrxs8+bOI5vkCTJLckf/rMtiuJhJJIk67oWAIA0Te8mhR2klGvbtg/UvNlC27ZPSlwquaqqZwA1dmGe56uu676HxPO8U5IfMyuGp+fEt+nTQghzqWnaMYBDdUVKuXYc5yLLsnsAmz5e6Lp+AgCIouiK5FfTNCvLsvanT5dl+Wia5t6wOwiC87GoCMPwUom/I2EVwEqOzwUAAAAASUVORK5CYII=');
}
.icon-menu {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAABHNCSVQICAgIfAhkiAAAAB5JREFUKJFj/P///38GEgATKYoHKWAc9TQRgGRPAwD0IAv+FT8LPwAAAABJRU5ErkJggg==');
}
<a id="nav-expand" href="#">
<span class="icon icon-menu"></span>
Menu
</a>
<nav>
<a id="nav-collapse" href="#">
<span class="icon icon-cross"></span>
</a>
Link1
Link2
Link3
Link4
</nav>
<main>
<h2>Push Sidebar Exmaple</h2>
<p>Please click on menu button.</p>
</main>
I am currently creating a website that is vertically scroll-able and has a navbar on the top as shown in the image. The navbar gets bigger when the user is not on the very top and this is implemented as:
if (window.scrollY == nav.offsetTop) {
document.querySelector('.nav').classList.add("largerNavbar");
} else {
document.querySelector('.nav').classList.remove("largerNavbar");
}
In javascript, so, it just adds a new class that has larger height to the navbar. But the problem is, it hides the content of the 2nd row. The 2nd row's style looks like:
div#firstRow {
padding: 10px;
width: 100%;
//position: relative;
margin:0 auto;
line-height: 1.4em;
background-color: green;
}
I commented out the position: relative because then the 2nd row will hide the navbar.
What is the problem here?
EDIT:
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
height: 100%;
font: 100% $font-stack;
color: $primary-color;
margin: 0px;
.largerNavbar .nav{
font-size: 20px;
height: 90px;
}
.largerNavbar #firstRow {
font-size: 20px;
height: 90px;
}
.onSection {
background-color: gray;
}
.nav{
color: white;
//vertical center
display: flex;
align-items: center;
font-size: 12px;
height: 70px;
overflow: hidden;
background-color: #333;
transition:all 1s;
-webkit-transition:all 1s;
.menus {
position: absolute;
right: 0px;
padding: 10px;
}
.logo {
position: absolute;
left: 0px;
padding: 10px;
}
}
.stationary {
position: fixed;
top: 0;
width: 100%;
}
.nav a {
color: white;
float: left;
display: block;
text-align: center;
padding: 14px;
text-decoration: none;
}
div#firstRow {
padding: 10px;
width: 100%;
//position: relative;
margin:0 auto;
line-height: 1.4em;
background-color: green;
}
div#secondRow {
padding: 10px;
//position: relative;
margin:0 auto;
line-height: 1.4em;
background-color: blue;
}
div#thirdRow {
padding: 10px;
//position: relative;
margin:0 auto;
line-height: 1.4em;
background-color: yellow;
}
div#lastRow {
height: 100px;
background-color: black;
}
}
<div class="logo">
HOME
</div>
<div class="menus">
<span>About</span>
<span>Archive</span>
<span>Projects</span>
<span>Contact</span>
</div>
</div>
<div id="firstRow">
<a id="about" class="smooth"></a>
</div>
<div id="secondRow">
<a id="history"></a>
</div>
<div id="thirdRow">
<a id="contact"></a>
</div>
<div id="fourthRow">
<a id="contact"></a>
</div>
<div id="lastRow">
<a id="footer"></a>
footer goes here
</div>
<script src="bundle.js" type="text/javascript"></script>
I'm guessing that you gave the navbar either absolute or fixed positioning.
If that's the case, I would try adding that largerNavbar class to an element that is a parent to both your navbar and your green container there, and then have some CSS selectors that alter both the navbar's height property and the green container's padding-top property at the same time.
So something like this:
.largerNavbar .nav {
...
height: 120px; // Use the same height for both
}
.largerNavbar #firstRow {
...
padding-top: 120px // Use the same height for both
}
Add some CSS transitions and it should look great. Good luck!
I wanted to create a navigation bar like this, " Artist News HH Blog Contact " With HH being the title of the page. I want the navigation alongside the heading. I attempted it but it isn't right and its very untidy.
<div id="heading">
<header>
<section class="main-nav index-nav">
<nav>
<ul>
<li>Artists</li>
<li>News</li>
<h1>HH</h1>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</section>
<!--section-->
</header>
</div>
heres my code
There's a few things wrong with your code, mainly the invalid html around the <h1>HH</h1> bit.
I updated your CSS as well to position the HH properly in between the other links. I change your h1 css as well as .main-nav h1.
Also if you remove the width: 10%; from the h1 css it will fix the border on the heading.
h1 {
text-align: center;
font-size: 50px;
padding-bottom: 1px;
margin-top: 0px;
border-bottom: 6px solid black;
}
#heading {
position: fixed;
z-index: 1;
width: 100%;
height: 134px;
text-align: left;
padding: 1em 0;
border-bottom: 2px solid black;
top: 0;
background-color: #f6f6f6;
}
/*================================================================================================================================*/
/* navigation styles*/
.main-nav-scrolled {
width: 100%;
position: fixed;
top: 0;
}
.main-nav a {
text-decoration: none;
color: Black;
text-transform: uppercase;
font-weight: 600;
display: block;
padding: 10px 10px;
opacity: 1;
}
.main-nav h1 {
font-weight: normal;
}
nav {
width: 100%;
margin: 0 auto;
position: relative;
}
nav ul {
display: inline-block;
list-style: none;
position: absolute;
text-align: center;
vertical-align: middle;
width: 100%;
margin-top: -1.7%;
margin-left: -5%;
}
nav ul li {
display: inline-block;
margin-left: 6%;
padding: 3px
}
.main-nav h1 a {
position: relative;
color: #000;
text-decoration: none;
}
/* navigation hover styles*/
/* nav ul */
nav ul a {
position: relative;
color: black;
text-decoration: none;
}
nav ul a:hover {
color: #000;
}
nav ul a:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
top: -3px;
left: 0;
background-color: black;
visibility: hidden;
-webkit-transform: scaleX (0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
nav ul a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
/*================================================================================================================================*/
<div id="heading">
<header>
<section class="main-nav index-nav">
<nav>
<ul>
<li>Artists
</li>
<li>News
</li>
<li>
<h1>HH</h1>
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</nav>
</section>
<!--section-->
</header>
</div>
Move the <h1> element into a <li> and remove some of the css. Here is what my final looks like, and it works.
h1{
text-align: center;
font-size: 50px;
padding-bottom:1px;
margin-top:0%;
border-bottom: 6px solid black;
}
<ul>
<li>Artists</li>
<li>News</li>
<li><h1>HH</h1></li>
<li>About</li>
<li>Contact</li>
</ul>
I would not use h1 at all. Use
<li id=hs>HH </li>
In css use
#hs
Font-size:16;
Or something that fits your need. Sorry for layout I am writing on phone.
One thing is that you're putting your <h1>HH</h1> in there illegally. You've got your <ul>, so you need to make your header a list element by doing <li><h1>HH</h1></li>.
You can delete your margin-left: 44%; from your h1 in your css now. That should clean it up a bit.