please tell me what to do to move my button to the center of the page. beacause right now it is in the right corner and i tried a lot of times to move it.
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 13px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 17px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
font-weight: bold;
}
.button1:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
</style>
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
Horizontal aligment, you need to put css on the containing div, to control the child element...
.container {
display: block;
margin: 0 auto;
text-align: center;
}
<div class="container">
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
</div>
If you are looking to vertically center the element, use...
button {
position: relative;
top: 50%;
transform: translateY(-50%);
}
Alternatively you can do it with flexbox, it's a powerful way to quickly center elements both horizontally and vertically.
You just have to put your button inside a container, apply flexbox to it, then margin: auto; will do the rest.
.container {
display: flex;
}
.button {
margin: auto;
}
<div class="container">
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
</div>
Related
I'm having some trouble aligning my dropdown menu in my angular app.
Please see the screenshot attached. The menu extends too far right of the screen. I need it to align to the "top right" of the ellipses instead of the "top left" as it is currently. The menu is currently functioning in a table.
Any assistance in getting the menu to shift to the left would be greatly appreciated.
Here is the HTML/CSS:
<td class="dropup">
<div class="dropup">
<button style="background-color: white;" class="dropbtn">
<img class="icon" src="assets/ellipsis.png">
</button>
<div class="dropup-content">
Admin Functionality
Download Project Snapshot
<a [routerLink]="['/project/'+j._id+'/project-activity']">View Project Activity</a>
Archive Project
<a *ngIf="j.creatorid != user._id" (click)="onLeaveProjectClick(j._id, j.projectname, n)">Leave Project</a>
</div>
</div>
</td>
.dropbtn {
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropup {
position: relative;
display: inline-block;
float:right;
}
.dropup-content {
display: none;
position: absolute;
transform-origin: 60% 40%;
top: 20px;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 10px;
}
.dropup-content :hover {
border-radius: 10px;
}
.dropup-content a {
color: black;
padding: 8px 16px;
text-decoration: none;
display: block;
}
.dropup-content a:hover {
background-color: #ddd;
color: #00aca8 !important;
}
.dropup:hover .dropup-content {
display: block;
border-radius: 10px;
}
As you set .dropup-content to absolute, it will be left aligned relative to .dropup as .dropup-content is within .dropup. But as your class is already absolute, simply add:
right: 0;
left: auto; // Unsure if you really need this though
to .dropup-content. This will take care that the class is right aligned relative to .dropup.
add to class .dropup-content this:
right:0;
https://jsfiddle.net/b1stpfr4/2/
I have a navbar and a button defined in HTML like this :
<div class="topnav">
<a class="active" href="#home">Hooligans</a>
<button class="button"><p style="font-family:courier;">drop dead</p></button>
</div>
The CSS for the above goes like this :
.topnav {
background-color: #F9FAFA;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
color: #BA55D3;
text-align: center;
padding: 8px 5px;
text-decoration: none;
font-size: 3vw;
}
.button {
background-color: #F9FAFA;
border: 2px solid #BA55D3;
border-radius: 5%;
color: #BA55D3;
text-align: center;
margin-left: 70%;
display: inline-block;
}
Right now, the best I can do is the button to fit exactly inside navbar. I want it to be smaller than the navbar like the Signup button in the stackoverflow navbar.
When I set height of the button the text inside the button goes out of the border and when I try padding the button goes bigger.
Any help ?
Remove the <p> tag inside the button, that is what's causing the unexpected margins. Also, I added display: flex to center align the items in the nav:
.topnav {
background-color:#F9FAFA ;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
overflow: hidden;
display: flex;
align-items: center;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
color: #BA55D3 ;
text-align: center;
padding: 8px 5px;
text-decoration: none;
font-size: 3vw;
}
.button{
background-color: #F9FAFA ;
border:2px solid #BA55D3;
border-radius: 5%;
color:#BA55D3;
text-align: center;
margin-left: 70%;
display: inline-block;
font-family: courier;
font-size: 1vw;
}
<div class="topnav">
<a class="active" href="#home">Hooligans</a>
<button class="button" >drop dead</button>
</div>
I have this code below. I have one container div with 2 inner div. I want the two inner divs to be side by side so I used in-line block on the two divs. Also I want the two divs to be start on top. In the demo below they are stuck on top and I dont know why while in my own project they are side by side but first div starts on top while second div does not start on top.
What is the best css style to make the 2 div in a container start on top while it is side by side?
What is the best way to make two div side by side?
.homissync {
display: block;
height: 100%;
}
.homissync>div {
padding: 27px;
margin: 3px;
display: inline-block;
}
#homissyncbuttons {
height: 100vh;
width: 20%;
margin: 3px;
}
#homissynclist {
height: 100vh;
margin: 3px;
width: 68%;
}
#homissyncbuttons .libuttons {
width: 100% !important;
background-color: #ff0000;
}
.vBorder {
border: solid 1px #ddd;
}
button, input[type=submit] {
padding: 8px 20px;
color: #fff;
text-shadow: 0 0 2px rgba(0,0,0,0.35);
background-color: orange;
font-size: 0.9rem;
font-weight: bold;
border-radius: 3px;
border: 0;
outline: none !important;
margin: 3px 0;
cursor: pointer;
transition: background 1s ease-in-out;
}
<div class=" homissync">
<div id="homissyncbuttons" class=" vBorder">
<ul>
<li>
<button class="libuttons">UACS</button>
</li>
<li>
<button class="libuttons">Medicine</button>
</li>
<li>
<button class="libuttons">Non-Drugs</button>
</li>
<li>
<button class="libuttons">Miscellaneous</button>
</li>
</ul>
</div>
<div id="homissynclist" class=" vBorder">
<button class="listbuttons" id="new_uacs_entry">New UACS Entry</button>
<button class="listbuttons" id="update_uacs_entry">Update UACS Entry</button>
<div id="homissynclistresult" class=" vPadding vBorder">
</div>
</div>
</div>
Please try this code instead of the display:inline-block; and just add float:left.
.homissync>div {
display: block;
float: left;
}
you can use float: left; instead of display: inline-block;
.homissync {
display: block;
height: 100%;
}
.homissync>div {
padding: 27px;
margin: 3px;
float:left;
}
#homissyncbuttons {
height: 100vh;
width: 20%;
margin: 3px;
}
#homissynclist {
height: 100vh;
margin: 3px;
width: 65%;
}
#homissyncbuttons .libuttons {
width: 100% !important;
background-color: #ff0000;
}
.vBorder {
border: solid 1px #ddd;
}
button, input[type=submit] {
padding: 8px 20px;
color: #fff;
text-shadow: 0 0 2px rgba(0,0,0,0.35);
background-color: orange;
font-size: 0.9rem;
font-weight: bold;
border-radius: 3px;
border: 0;
outline: none !important;
margin: 3px 0;
cursor: pointer;
transition: background 1s ease-in-out;
}
<div class=" homissync">
<div id="homissyncbuttons" class=" vBorder">
<ul>
<li>
<button class="libuttons">UACS</button>
</li>
<li>
<button class="libuttons">Medicine</button>
</li>
<li>
<button class="libuttons">Non-Drugs</button>
</li>
<li>
<button class="libuttons">Miscellaneous</button>
</li>
</ul>
</div>
<div id="homissynclist" class=" vBorder">
<button class="listbuttons" id="new_uacs_entry">New UACS Entry</button>
<button class="listbuttons" id="update_uacs_entry">Update UACS Entry</button>
<div id="homissynclistresult" class=" vPadding vBorder">
</div>
</div>
</div>
display:inline-block have default white space, you need to remove the white space. otherwise you need to relace the display-inline-block with float:left , there is so many options to remove the white space please check the reference link below
Why is there an unexplainable gap between these inline-block div elements?
I am making a website with a navigation menu on the top. I have multiple buttons with dropdown menus. I want to make the buttons in all in a row at the same height and I want the buttons to be in the middle. Here is my code:
/* Links CSS */
a,
a:visited,
a:active {
text-decoration: underline;
color: white;
}
a:hover {
color: red;
text-decoration: underline;
}
/* Element CSS */
html,
body {
margin: 0px;
background-color: white;
}
html {
height: 100%;
width: 100%;
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
position: relative;
padding-bottom: 6rem;
min-height: 100%;
}
.button,
.games,
.programs,
.apps,
.misc {
font-family: 'Arsenal';
font-size: 18px;
text-decoration: underline;
background: transparent;
padding-top: 1%;
padding-bottom: 1%;
padding-left: 1.5%;
padding-right: 1.5%;
cursor: pointer;
border: 0px;
}
.content {
font-family: 'Arsenal';
font-size: 15px;
text-decoration: none;
background-color: white;
border: 0px;
cursor: pointer;
}
.button:hover,
.content:hover,
.games:hover,
.programs:hover,
.apps:hover,
.misc:hover {
background-color: #f0efef;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
padding: 0.5%;
}
.games-dropdown {
position: relative;
display: inline-block;
}
.progams-dropdown {
position: relative;
display: inline-block;
}
.apps-dropdown {
position: relative;
display: inline-block;
}
.misc-dropdown {
position: relative;
display: inline-block;
}
.show {
display: block;
}
/* Div CSS */
#page {
margin-top: 0px;
}
#title {
font-family: 'Arsenal';
font-size: 37px;
padding-top: 0.5%;
color: black;
display: inline-block;
cursor: pointer;
}
#links {
margin: auto;
display: inline-block;
overflow: auto;
}
#content {
background-color: white;
border: 1px solid black;
border-radius: 3px;
margin-left: 10%;
margin-right: 10%;
box-shadow: 1px 1.5px #8f8f8f;
}
#footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 1rem;
background-color: #f0efef;
text-align: center;
border-top: 1px solid black;
font-family: 'Arsenal';
font-size: 15px;
}
<!-- HTML -->
<center>
<div id="links">
<!-- Code For Dropdown Menus | Code From http://www.w3schools.com/ | Thanks To Them!-->
<!-- Games Dropdown Menu: Browser and Downloadable-->
<div class="programs-dropdown">
<button class="programs" onclick="games()" title="Games">Games</button>
<div id="gamesDropdown" class="dropdown-content">
<button class="content" onclick="download()">Download</button>
<button class="content" onclick="online()">Online</button>
</div>
</div>
<!-- Programs Dropdown Menu: Windows and Max OS X-->
<div class="programs-dropdown">
<button class="programs" onclick="programs()" title="Programs">Programs</button>
<div id="programsDropdown" class="dropdown-content">
<button class="content" onclick="windows()">Windows</button>
<button class="content" onclick="mac()">Mac OS X</button>
</div>
</div>
<button class="button" onclick="websites()" title="Websites">Websites</button>
<button class="button" onclick="home()" title="Home">Home</button>
<!-- Apps Dropdown Menu: IOS and Android -->
<div id="apps-dropdown">
<button class="apps" onclick="apps()" title="Apps">Apps</button>
<div id="appsDropdown" class="dropdown-content">
<button class="content" onclick="ios()">IOS</button>
<button class="content" onclick="android()">Android</button>
</div>
</div>
<button class="button" onclick="blog()" title="Blog">Blog</button>
<!-- Misc. Dropdown Menu: Chrome Extensions, GitHub, Etc.-->
<div id="misc-dropdown">
<button class="misc" onclick="misc()" title="Misc.">Misc.</button>
<div id="miscDropdown" class="dropdown-content">
<button class="content" onclick="chrome()">Chrome Extensions</button>
<button class="content" onclick="github()">GitHub</button>
</div>
</div>
</div>
</center>
The easiest way to center elements is to use flexbox.
You can learn about it more at: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Using flexbox to center elements is actually quite simple. Assuming you have set of elements:
<div class="elements">
<div class="element__item">Element one</div>
<div class="element__item">Element two</div>
<div class="element__item">Some other element</div>
</div>
You can center them horizontally & vertically using css like this:
.elements {
display: flex;
justify-content: center;
align-items: center;
}
You can check this on JSfiddle: https://jsfiddle.net/kf405784/
I'm writing a CSS framework and when it comes to handling buttons I'm trying to make it so that the user can segment the button (this is done, see the fiddle below) - however, I want to add another semantic CSS selector that will allow the user to positon this left/right of the button text (automatically right). My issue is, however - I don't want to affect the HTML in any way, the HTML structure is the same for every other button, so I'd rather not altar this if possible.
I've tried floating the segment left, afterwards I thought it was pretty obvious that wouldn't work - the height of the button is also dependent on the padding of the segment - so (as far as I'm aware) it's not possible to position this absolutely. I'm having a mental block as to how to achieve this.
Here is my current CSS:
.dte.button {
border-radius: 0;
display: inline-block;
border: 0;
outline: 0;
padding: 10px;
background: #34495e;
color: white;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
cursor: pointer;
transition: 0.25s all;
position: relative;
}
button.dte.button.segmented {
padding: 0;
padding-left: 10px;
position: relative;
}
.dte.button .segment {
filter: brightness(50%);
background: rgba(0, 0, 0, 0.53);
padding: 10px;
display: inline-block;
margin-left: 10px;
}
And my HTML structure
<button class="dte button segmented">
This should align the segment RIGHT (it does)
<div class="segment">
<i class="fa fa-align-right"></i>
</div>
</button>
<button class="dte button segmented left">
This should align the segment LEFT(It doesn't)
<div class="segment">
<i class="fa fa-align-left"></i>
</div>
</button>
Fiddle of what I current have.
It is not pretty, but you can use float:left if you then fix your spacing with some negative margins.
So for example:
.dte.button {
border-radius: 0;
display: inline-block;
border: 0;
outline: 0;
padding: 10px;
background: #34495e;
color: white;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
cursor: pointer;
transition: 0.25s all;
position: relative;
}
button.dte.button.segmented {
padding: 0;
padding-left: 10px;
position: relative;
}
button.dte.button.segmented.left {
padding: 10px 10px 10px 0;
}
.dte.button .segment {
filter: brightness(50%);
background: rgba(0, 0, 0, 0.53);
padding: 10px;
display: inline-block;
margin-left: 10px;
}
.dte.button.left .segment {
float: left;
margin: -10px 10px -10px 0;
}
<div style="padding: 20px;">
<button class="dte button">dte-button</button>
<button class="dte button segmented">
Dropdown Button
<div class="segment">
ICON
</div>
</button>
<button class="dte button segmented">
Segment Aligned Right
<div class="segment">
ICON
</div>
</button>
<button class="dte button segmented left">
Segment Aligned Left
<div class="segment">
ICON
</div>
</button>
</div>
Here also a fiddle.