I need to center buttons in the middle of page, one under another.
I've used code below, but the result was that buttons still appear next to each other.
header {
text-align: center;
.btn {
#include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
}
.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
}
<header>
Button A
Button B
</header>
Thank you
you can use "flexbox" for this
header {
display: flex;
flex-direction: column;
align-items: center;
.btn {
#include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
}
.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
}
<header>
a
b
</header>
Without flexbox
.btn {
#include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
float: left;
clear: both;
width: calc(100% - 40px);
box-sizing: border-box;
text-align: center;
}
.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
<header>
a
b
</header>
Update check new fiddle
https://jsfiddle.net/bimbonkens/fa7s3ypj/
you needed only the
display:block
on your buttons.
also your css syntax is wrong for vanilla css(no preprocessors)
header {
.btn {}
}
should be this
header { }
.btn { }
and if you need context:
header {}
header .btn {}
You need to use
margin: 0 auto;
for block elements, because
text-align:center;
works only on inline and inline-block
one way to go could be the following:
header {
text-align: center;
}
header .btn {
border-radius: 7px;
padding: 5px 10px;
border: none;
display: block;
width: 100px;
margin: auto;
}
.btn-green {
color: #fff;
background-color: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background-color: grey;
margin: 20px;
}
<header>
Button A
Button B
</header>
Do you want something like this:-
header {
text-align: center;
.btn {
#include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
}
.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
}
<header>
Button A<br>
Button B
</header>
Related
I am creating a website for my school coding class using Adobe Dreamweaver, but I have run into an issue.
I have two articles and am trying to get them inline. They are both set to block, and I know that they should be inline-block elements, but setting it to that causes a problem.
I have a navigation bar above these two articles, and if I make these articles inline-block elements, it makes the navigation bar disappear. I don't know why this is happening, and have tried asking my teacher and classmates for help, but can't find a solution. Here is an image of what it looks like with both articles as block elements:
This is what it looks like when they are inline-block elements:
I want the articles to be together, as shown in the second image, but I still want to keep my navigation bar. Note that the navigation bar is styled with 'position:fixed', so that it always stays at the top of my page. I also want to keep this, but I feel as though it may be the cause for my problem. Here is a snippet of the code which I made (sorry if it doesn't work properly, and that the images don't work)
#import url('https://fonts.googleapis.com/css2?family=Limelight&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Zen+Dots&display=swap');
nav {
height: 120px;
background-color: black;
width: 100%;
display: block;
margin: -130px 0 0 -10px;
position: fixed;
}
.dropdown {
padding-right: 5px;
margin-right: 5px;
}
.tasa {
text-transform: uppercase;
font-family: 'Limelight', cursive;
}
.nav-bar-image {
width: 110px;
height: 100px;
margin: 10px -10px 10px 10px;
display: inline;
}
nav>ul>li>a {
text-decoration: none;
color: white;
}
nav>ul>li {
font-size: 20px;
font-family: Zen Dots;
display: inline;
padding: 10px;
}
nav>ul>li:hover {
background-color: darkgrey;
}
nav>ul>li>ul {
display: none;
margin-top: 10px;
font-size: 14px;
margin-left: 165px;
list-style-type: none;
position: absolute;
}
nav>ul>li:hover>ul {
display: block;
}
nav>ul>li>ul>li {
padding-left: 10px;
padding-right: 69.5px;
}
nav>ul>li>ul>li:hover {
background-color: darkgrey;
}
nav>ul>li>ul>li>a {
color: white;
text-decoration: none;
}
nav>ul {
display: inline-block;
vertical-align: top;
margin-top: 20px;
list-style-type: none;
}
body {
background-image: url(background.jpg);
}
article {
background-color: rgba(255, 231, 179, 0.80);
width: 400px;
margin: 130px 0 0 10px;
/*130px 0 0 10px*/
padding: 5px 10px 10px;
height: 200px;
text-align: justify;
height: 750px;
display: block;
verticle-align: top;
}
.left {
border-top-left-radius: 50px;
border-bottom-left-radius: 50px;
height: 200px;
}
.centre {
margin-top: 0;
height: 200px;
}
h1 {
color: white;
font-family: Limelight;
font-size: 40px;
text-align: center;
margin: 10px 0 0;
}
p {
text-align: jusify;
color: white;
}
article>ul>li>a {
color: white;
text-decoration: none;
}
article>ul {
list-style-type: none;
}
::-webkit-scrollbar {
width: 16px;
}
::-webkit-scrollbar-thumb {
background: #ffe7b3;
border-radius: 8px;
}
::-webkit-scrollbar-track {
background: #ffffff;
box-shadow: inset 0 0 5px grey;
border-radius: 8px;
}
/*
::-webkit-scrollbar-button:single-button {
background-color: #ffffff;
display: block;
border-style: solid;
height: 13px;
width: 16px;
}
*/
::-webkit-scrollbar-thumb:hover {
background: #d6c39a;
}
/*
::-webkit-scrollbar-button:single-button:vertical:decrement {
border-width: 0 8px 8px 8px;
border-color: transparent transparent #000000 transparent;
}
::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
border-color: transparent transparent #5e5e5e transparent;
}
::-webkit-scrollbar-button:single-button:vertical:increment {
border-width: 8px 8px 0 8px;
border-color: #000000 transparent transparent transparent;
}
::-webkit-scrollbar-button:vertical:single-button:increment:hover {
border-color: #5e5e5e transparent transparent transparent;
}
*/
html {
cursor: url(tasa-cursor-medium.cur), default;
}
a {
cursor: url(tasa-cursor-a-large.cur), default;
}
<header>
<nav>
<img src="logo.jpg" alt="TASA logo." class="nav-bar-image">
<ul>
<li>Home</li>
<li>Details</li>
<li class="dropdown">Presentations
<ul>
<li>Introduction</li>
<li>Constellations</li>
<li>Lunar Events</li>
</ul>
</li>
<li>Links</li>
</ul>
</nav>
</header>
<article class="left">
<h1>TASA</h1>
<p>
</p>
</article>
<article class=centre>
<h1>Images</h1>
</article>
This snippet has the display element on the articles set to block, not inline-block.
The problem: when you make the class left and centre inline-block, the margin-top of the nav is -130px. This makes it go out of screen.
A more clean solution would be to use flex box, and have some flexibility ;) of the alignment of items. In the solution, i removed the margin and changed it, see below:
/* Wrap the class "left" and "centre" with a div (i named it "main_content") */
.main_content {
display: flex;
flex-direction: row;
}
nav {
/* Removed this -> margin: -130px 0 0 -10px; */
position: fixed;
}
.centre {
/* Removed this --> margin-top: 0; */
}
nav>ul {
/* Changed margin-top from 20px to 0px */
margin-top: 0px;
}
#import url('https://fonts.googleapis.com/css2?family=Limelight&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Zen+Dots&display=swap');
nav {
height: 120px;
background-color: black;
width: 100%;
display: block;
position: fixed;
}
.dropdown {
padding-right: 5px;
margin-right: 5px;
}
.tasa {
text-transform: uppercase;
font-family: 'Limelight', cursive;
}
.nav-bar-image {
width: 110px;
height: 100px;
margin: 10px -10px 10px 10px;
display: inline;
}
nav>ul>li>a {
text-decoration: none;
color: white;
}
nav>ul>li {
font-size: 20px;
font-family: Zen Dots;
display: inline;
padding: 10px;
}
nav>ul>li:hover {
background-color: darkgrey;
}
nav>ul>li>ul {
display: none;
margin-top: 10px;
font-size: 14px;
margin-left: 165px;
list-style-type: none;
position: absolute;
}
nav>ul>li:hover>ul {
display: block;
}
nav>ul>li>ul>li {
padding-left: 10px;
padding-right: 69.5px;
}
nav>ul>li>ul>li:hover {
background-color: darkgrey;
}
nav>ul>li>ul>li>a {
color: white;
text-decoration: none;
}
nav>ul {
display: inline-block;
vertical-align: top;
margin-top: 0px;
list-style-type: none;
}
body {
background-image: url(background.jpg);
}
article {
background-color: rgba(255, 231, 179, 0.80);
width: 400px;
margin: 130px 0 0 10px;
/*130px 0 0 10px*/
padding: 5px 10px 10px;
height: 200px;
text-align: justify;
height: 750px;
display: block;
vertical-align: top;
}
.main_content {
display: flex;
flex-direction: row;
}
.left {
border-top-left-radius: 50px;
border-bottom-left-radius: 50px;
height: 200px;
}
.centre {
height: 200px;
}
h1 {
color: white;
font-family: Limelight;
font-size: 40px;
text-align: center;
margin: 10px 0 0;
}
p {
text-align: jusify;
color: white;
}
article>ul>li>a {
color: white;
text-decoration: none;
}
article>ul {
list-style-type: none;
}
::-webkit-scrollbar {
width: 16px;
}
::-webkit-scrollbar-thumb {
background: #ffe7b3;
border-radius: 8px;
}
::-webkit-scrollbar-track {
background: #ffffff;
box-shadow: inset 0 0 5px grey;
border-radius: 8px;
}
/*
::-webkit-scrollbar-button:single-button {
background-color: #ffffff;
display: block;
border-style: solid;
height: 13px;
width: 16px;
}
*/
::-webkit-scrollbar-thumb:hover {
background: #d6c39a;
}
/*
::-webkit-scrollbar-button:single-button:vertical:decrement {
border-width: 0 8px 8px 8px;
border-color: transparent transparent #000000 transparent;
}
::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
border-color: transparent transparent #5e5e5e transparent;
}
::-webkit-scrollbar-button:single-button:vertical:increment {
border-width: 8px 8px 0 8px;
border-color: #000000 transparent transparent transparent;
}
::-webkit-scrollbar-button:vertical:single-button:increment:hover {
border-color: #5e5e5e transparent transparent transparent;
}
*/
html {
cursor: url(tasa-cursor-medium.cur), default;
}
a {
cursor: url(tasa-cursor-a-large.cur), default;
}
<header>
<nav>
<img src="logo.jpg" alt="TASA logo." class="nav-bar-image">
<ul>
<li>Home</li>
<li>Details</li>
<li class="dropdown">Presentations
<ul>
<li>Introduction</li>
<li>Constellations</li>
<li>Lunar Events</li>
</ul>
</li>
<li>Links</li>
</ul>
</nav>
</header>
<div class="main_content">
<article class="left">
<h1>TASA</h1>
<p>
</p>
</article>
<article class="centre">
<h1>Images</h1>
</article>
</div>
I'm just wondering how I can put my button at the right-bottom of the parent box.
I have put position: relative; to the parent box and used position: absolute; for the button class.
This worked perfectly. However, the button overlapped with the contents of the parent box.
What would be the best way to fix this?
Here's my html and css Thank you!!
.color {
border: 1px solid black;
width: 70%;
margin: 10px auto;
padding: 0 30px;
position: relative;
}
.color p {
display: inline-block;
width: 200px;
height: 80px;
margin-right: 10px;
text-align: center;
line-height: 78px;
}
p.black {
background: black;
color: white;
}
p.gray {
background: gray;
color: white;
}
p.blue {
background: blue;
color: white;
}
p.white {
border: 1px solid black;
}
.btn {
position: absolute;
right: 10px;
bottom: 10px;
}
.btn a {
display: inline-block;
background: #efd9ca;
padding: 25px;
width: 300px;
text-align: center;
text-decoration: none;
}
<h1 class="heading">color</h1>
<p class="black">black</p>
<p class="gray">gray</p>
<p class="white">white</p>
<p class="blue">blue</p>
<div class="btn">Mozilla color collection website</div>
I removed your relative and absolute position declarations. Then I added following css declrations:
.btn {
float: right;
margin-bottom: -20px;
}
float: right; will align the button to the right side. With margin-bottom: -20px; you counter the padding bottom of 30px so that the spacing will only be 10px as previos attempted.
.color {
border: 1px solid black;
width: 70%;
margin: 10px auto;
padding: 0 30px;
}
.color p {
display: inline-block;
width: 200px;
height: 80px;
margin-right: 10px;
text-align: center;
line-height: 78px;
}
p.black {
background: black;
color: white;
}
p.gray {
background: gray;
color: white;
}
p.blue {
background: blue;
color: white;
}
p.white {
border: 1px solid black;
}
.btn a {
display: inline-block;
background: #efd9ca;
padding: 25px;
width: 300px;
text-align: center;
text-decoration: none;
}
.btn {
float: right;
margin-bottom: -20px;
}
<h1 class="heading">color</h1>
<p class="black">black</p>
<p class="gray">gray</p>
<p class="white">white</p>
<p class="blue">blue</p>
<div class="btn">Mozilla color collection website</div>
I am having an issue with this new website for my local Church. I followed this tutorial to create a burger menu with just HTML and CSS: https://www.youtube.com/watch?v=xMTs8tAapnQ&list=PLu-osytzWPuUXmu5BZTuHNRyMBpZS1bsG&index=4&t=0s
Now after learning how to do it, the issue I am running into is I am trying to put an image in the body under the navigation menus, however, when I make my web resolution smaller and click on the burger menu. It is under the image.
I appreciate any help, I tried to look for it everywhere, or I tried at least. I am new to coding. So thank you for your time spent helping me. I really do appreciate it.
**HTML**
<!DOCTYPE html>
<html>
<head>
<title>Church of Christ</title>
<link rel="stylesheet" type="text/css" href="main.css">
<meta charset="utf-8">
<meta name="viewport" contet="width=device-width, initial-scale=1.0">
</head>
<body>
<h1> The Church of Christ </h1>
<div class="nav">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle"/>
<div class="menu">
Home
Contact
About
<span>Members</span>
</div>
</div>
<h2> location </h2>
<img src="IMG_2597.jpg" alt="Church of Christ">
</body>
</html>
**CSS**
html, body {width: 100%;
height: 100%;
margin: 0;
}
html {
font-family: "helvetica neue", "sans sherif";
}
.nav {
border-bottom: 1px solid gold;
text-align: right;
height: 70px;
line-height: 70px;
}
.menu {
margin: 0 30px 0 0;
}
.menu a {
text-decoration: none;
color: rgb(255, 255, 255);
margin: 0 10px;
line-height: 70px;
clear: right;
}
span {
color: gold;
}
label {
margin: 0 40px 0 0;
font-size: 26px;
line-height: 70px;
display: none;
width: 26px;
float: right;
color: gold;
}
#toggle {
display: none;
}
#media only screen and (max-width: 500px) {
label {
display: block;
cursor: pointer;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu a {
display: block;
border-bottom: 1px solid gold;
margin: 0;
}
#toggle:checked + .menu {
display: block;
}
}
h1 {
text-align: center;
font-size: 50px;
margin: 10px 0px -10px 0px;
color: gold;
}
a {
font-size: 25px;
}
h2 {
text-align: center;
font-size: 45px;
color: rgb(255, 255, 255);
}
img {
width: 100%;
height: auto;
}
body {
background-color: rgb(0, 0, 0);
}
just remove css clear:right and add float:right
.menu {
margin: 0 30px 0 0;
float: right;
}
.menu a {
text-decoration: none;
color: white;
margin: 0 10px;
line-height: 70px;
}
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
html {
font-family: "helvetica neue", "sans sherif";
}
.nav {
border-bottom: 1px solid gold;
text-align: right;
height: 70px;
line-height: 70px;
/* this line changed */
position: relative;
}
.menu {
margin: 0 30px 0 0;
}
/* i advice,that a tag will made bacgraund-color,because when dropdown menu covering image */
.menu a {
text-decoration: none;
color: rgb(255, 255, 255);
margin: 0 10px;
line-height: 70px;
clear: right;
/* background-color: blue; */
}
span {
color: gold;
}
label {
margin: 0 40px 0 0;
font-size: 26px;
line-height: 70px;
display: none;
width: 26px;
float: right;
color: gold;
}
#toggle {
display: none;
}
#media only screen and (max-width: 500px) {
label {
display: block;
cursor: pointer;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu a {
display: block;
border-bottom: 1px solid gold;
margin: 0;
}
#toggle:checked + .menu {
display: block;
}
}
h1 {
text-align: center;
font-size: 50px;
margin: 10px 0px -10px 0px;
color: gold;
}
a {
font-size: 25px;
}
h2 {
text-align: center;
font-size: 45px;
color: rgb(255, 255, 255);
}
img {
width: 100%;
height: auto;
}
body {
background-color: rgb(0, 0, 0);
}
I've been playing around with flex box and I would like to center the "Logo" test in the upper left corner vertically in its blue container.
You can see it here: http://codepen.io/TimRos/pen/MwKNgw
* {
margin: 0;
padding: 0;
}
.box {
color: white;
font-size: 80px;
text-align: center;
text-shadow: 4px 4px 3px black;
}
/* COLORS & Style
===================================== */
.main-header { background: #e3e3e3; }
.main-footer { background: #e3e3e3; }
.main-content { background: #e3e3e3; }
.main-wrapper {
box-shadow: 2px 2px 10px #333;
}
.main-wrapper {
width: 80%;
margin: 0 auto;
}
/* HEAD
===================================== */
.main-header {
width: 100%;
height: 100px;
border-bottom: 1px solid black;
}
.main-nav {
list-style: none;
display: flex;
flex-flow: row wrap;
justify-content: flex-end;
align-items: flex-end;
height: 100%;
}
.main-nav li {
margin-left: 8px;
margin-right: 8px;
}
#logo {
margin-right: auto; /* Align Logo to Left, Nav to the right*/
margin-left: 0;
align-self: center;
}
.main-nav li:last-child {
margin-right: 0;
}
.main-nav li {
background-color: #3f8abf;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom: 4px solid firebrick;
}
.main-nav a {
text-decoration: none;
color: white;
text-align: center;
font-weight: bold;
padding: 8px 15px;
display: block;
width: 100px;
}
#logo {
border-top-left-radius: 0;
border-bottom-right-radius: 5px;
border-bottom: 0;
border-left: 4px solid firebrick;
padding: 0;
height: 100%;
}
#logo h1 {
padding: 0;
margin: 0;
}
/* CONTENT
===================================== */
.main-content {
padding: 15px;
}
h3 {
margin-bottom: 15px;
}
/* FOOTER
===================================== */
.main-footer {
border-top: 1px solid black;
text-align: center;
padding: 5px;
}
I tried margin and padding auto but that doesnt seem to work, please help!
Just add this CSS:
CSS
#logo a{
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%); // For Safari and Chrome Mobile
}
DEMO HERE
I have done a bit more research and found another solution to this problem. Since I'm already using flexbox anyways, might as well use flexbox like this:
#logo {
display: flex;
align-items: center
}
As I said, the other solution works just fine.
Unfortunately, I have always the same problem with heigths of divs.
I want that my div (If the content is minimum) fills the monitor. Otherwhise, if the content exceed the page I use the scrollbar (overflow:scroll) and this part is ok.
My page is composed like this:
<div id="container">
<div id="header"> ...</div>
<div id="navigation"> ... </div>
<div id="content"> ...
<div id="testo"></div>
</div>
I would like that the div content match the heigth of the page of the browser.
If you watch this example http://jsfiddle.net/EBnD2/
you can understand what is my problem.
thanks in advance!
Here's a script driven solution:
And the script that does the trick (I've used jQuery for convenience. Feel free to resort to pure javascript, if necessary :
$(document).ready(function () {
$("#content").css("height",
(
$(document).outerHeight()
- $("#header").outerHeight()
- $("#navigation").outerHeight()
- $("#footer").outerHeight()
- parseInt($("#content").css("padding"))) + "px");
});
Here's the updated style definitions:
html {
}
body {
min-width: 1150px;
overflow: auto;
background-color: pink;
margin: 0px;
}
#container {
margin: 0 100px;
background: #fff;
border-top: 1px solid grey;
font-family: sans-serif;
}
#header {
text-align:center;
background: #ccc;
padding: 20px;
border-left: 1px solid grey;
border-right: 1px solid grey;
}
#header h1 {
margin: 0;
}
#testo {
font-family: times, Times New Roman, times-roman, georgia, serif;
font-size: 18px;
line-height: 30px;
text-transform: uppercase;
color: #444;
}
p.sx {
text-align: left;
}
p.cx {
text-align: center;
}
p.dx {
text-align: right;
}
#navigation {
float: left;
width: 100%;
background: #CC3366;
font-weight: bold;
font-size: 90%;
font-size-adjust: inherit;
}
#navigation ul {
margin: 0;
padding: 0;
}
#navigation ul li {
list-style-type: none;
display: inline;
}
#navigation li a {
display: block;
float: left;
padding: 5px 10px;
color: #fff;
text-decoration: none;
border-right: 1px solid #fff;
}
#navigation li a:hover {
background: #993366;
}
#navigation li a.selected {
background: grey;
}
#content {
background-color: white;
border-left: 1px solid grey;
border-right: 1px solid grey;
padding: 20px;
}
#content h2 {
color: #000;
font-size: 160%;
margin: 0 0 .5em;
}
#footer {
border: 1px solid grey;
background: #ccc;
text-align: right;
padding: 20px;
}