I tried a lot of stuff and my buttons just won't align no matter how hard I try.
This is the screenshot of what I see on my page:
(https://i.stack.imgur.com/DhQIw.png)
They should be all just in the center aligned but it just won't.
idk if I do wrong combinations but I've tried a float: left, text-align: center. it just won't
any help would be appreciated.
BHeader is the parent Header that the buttons are in
.BHeader {
margin-top: 5px;
border-radius: 12px;
box-shadow: 0 1px 8px rgba(0, 0, 0, 0.50);
background-color: rgb(44, 44, 44);
width: 100%;
max-width: 98%;
display: flex;
flex-direction: right;
}
.HButtons {
background-color: black;
color: white;
}
button {
cursor: pointer;
background-color: rgba(0, 0, 0, 0.50);
border: 2px solid white;
color: white;
border-radius: 10%;
margin-left: 5%;
margin-top: 5%;
display: initial;
text-align: center;
}
<div>
<div className="BHeader">
<div className="HButtons">
<button className="BHeader__Home">Home</button>
<button className="BHeader__Content">Content</button>
<button className="BHeader__About">About</button>
</div>
</div>
</div>
The problem is in how you're using flexbox. You should use it in .HButtons (which is the button's container), not in .BHeader.
And there's another error too, because flex-direction only supports row, row-reverse, column and column-reverse as values, not right: https://developer.mozilla.org/es/docs/Web/CSS/flex-direction
You can do something like that. I changed some lines to make look as you was asking for:
.BHeader {
margin-top: 5px;
border-radius: 12px;
box-shadow: 0 1px 8px rgba(0, 0, 0, 0.50);
background-color: rgb(44, 44, 44);
width: 100%;
max-width: 98%;
}
.HButtons {
display: flex;
flex-direction: row; /* This line it's not necessary, because 'row' is the default value */
justify-content: center; /* Put the buttons horizontal centered inside the parent */
gap: 5%; /* To separate the buttons between themselves */
background-color: black;
color: white;
padding: 5%; /* Based on the percent you use to separate the buttons, just to add some space between the buttons and the bar */
}
.HButtons button {
cursor: pointer;
background-color: rgba(0, 0, 0, 0.50);
border: 2px solid white;
color: white;
border-radius: 10%;
}
<div>
<div class="BHeader">
<div class="HButtons">
<button class="BHeader__Home">Home</button>
<button class="BHeader__Content">Content</button>
<button class="BHeader__About">About</button>
</div>
</div>
</div>
.btn-group{
background-color:coral;
display:flex; /* to make buttons horizontally align */
justify-content:center; /* to align buttons horizontally center */
}
button{
padding: 10px;
margin:10px;
background:#000;
color:#fff;
}
.btn-group-2{
background-color:royalblue;
width: 400px;
margin:auto; /* to align parent div horizontally center */
display:flex; /* to make buttons horizontally align */
justify-content:center; /* to align buttons horizontally center */
}
<div class="btn-group">
<button>Button 1</button>
<button>Button 2</button>
<button>Button 3</button>
</div>
<div class="btn-group-2">
<button>Button 1</button>
<button>Button 2</button>
<button>Button 3</button>
</div>
Try this example and correct your snippet accordingly.
I hope this will help you completely.
Related
Let's say I want to hide container's horizontal content, but at the same time time I want to translate child elements. Adding overflow-x: hidden; to the parent causes it to clip vertically translated children too. Why does this happen and how can I work around it?
.content{
margin: 1rem;
}
.rail {
display: flex;
padding: 0.5rem;
background: #EEE;
overflow-x: hidden;
}
.card {
padding: 1rem;
border: 1px solid gray;
background: #FFF;
}
.card:hover {
transform: translate3d(0px, -1.5rem, 0px);
}
<div class="content">
<div class="rail">
<div class="card">CONTENT</div>
</div>
</div
I faced a similiar issue recently as well, a workaround I found was just to wrap a new container around the transformed element:
.content {
margin: 1rem;
}
.rail {
display: flex;
padding: 0.5rem;
background: #EEE;
}
.card {
padding: 1rem;
border: 1px solid gray;
background: #FFF;
}
.card:hover {
transform: translate3d(0px, -1.5rem, 0px);
}
<div class="content">
<div class="rail">
<div class="card-container">
<div class="card">CONTENT</div>
</div>
</div>
</div>
As far as I can see, yes you have to make the rail higher.
However, you can do this and make it look like it is not bigger. See the following CSS:
.content{
margin: 1rem;
/* Just to help show what is happening */
padding: 1rem;
background: pink;
/* Parameterise the work around */
--railPadding: 0.5rem;
--vertTranslate: -1.5rem;
--extraSpace: calc(0px - (var(--railPadding) + var(--vertTranslate)));
}
.rail {
/* The important constraints. */
display: flex;
overflow-x: hidden;
/* Make the extra space without changing the content box of the rail. */
padding: calc(var(--railPadding) + var(--extraSpace)) var(--railPadding) var(--railPadding) var(--railPadding);
/* Offset the extra height by backing over the margin. */
margin-top: calc(0px - var(--extraSpace));
/* Make the rail look like it has not backed over anything by making the overlap transparent. */
background: linear-gradient(to top, #EEE calc(100% - var(--extraSpace)), rgba(0, 0, 0, 0) var(--extraSpace));
}
.card {
padding: 1.0rem;
border: 1px solid gray;
background: #FFF;
}
.card:hover {
transform: translate3d(0px, var(--vertTranslate), 0px);
}
I'm experimenting on vertical buttons using CSS display grid & inline-grid and have them working. It's when I try to add regular buttons that things go wrong.
The image displays the issue.
]1
The grid's influence extends out past the visible items it contains and hence the "control" buttons are ending up below the vertical buttons instead of up top next to the first vertical button. I've tried surrounding the grid divs with other divs to try to contain their influence, but no luck.
How do I get the "control" buttons currently at the bottom back up toward the top?
<div id="control">
<div id="title">
Buttons In Grid
</div>
<div class="sideButtonsOuterContainer">
<div class="sideButtonsInnerContainer">
<button id="buttonR0" class="sideButtons">A</button>
<button id="buttonR1" class="sideButtons">B</button>
<button id="buttonR2" class="sideButtons">C</button>
</div>
<div class="sideButtonsInnerContainer">
<button id="buttonR3" class="sideButtons">D</button>
<button id="buttonR4" class="sideButtons">E</button>
<button id="buttonR5" class="sideButtons">F</button>
</div>
<div class="sideButtonsInnerContainer">
<button id="buttonR6" class="sideButtons">G</button>
<button id="buttonR7" class="sideButtons">H</button>
<button id="buttonR8" class="sideButtons">I</button>
</div>
</div>
<div id="sideControls">
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
</div>
</div>
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
#control{
width: 20%;
}
#title{
text-align: center;
font-size: 43px;
color: rgb(255, 0, 0);
}
.sideButtonsOuterContainer{
display: grid;
width: 52px;
grid-template-rows: auto auto auto;
gap: 10px;
background-color: #000000;
padding-left: 0px;
padding-right: 0px;
padding-top: 10px;
padding-bottom: 10px;
}
.sideButtonsInnerContainer {
display: inline-grid;
width: 45px;
grid-template-rows: auto auto auto;
gap: 4px;
padding: 3px;
}
.sideButtons{
background-color: #4CAF50; /* Green */
color: white;
width: 45px;
height: 127px;
text-align: center;
font-size: 38px;
}
.topButtons{
background-color: #4CAF50; /* Green */
border: none;
color: white;
text-align: center;
text-decoration: none;
font-size: 38px;
}
I am trying to put the top three blue boxes into side container to the right.
where i can display these 3 blue boxes verticaly , I am missing the reason they are just floating from left to right above my text and not as I desire.
currently stuck , tried to figure out my mistake for 2 hours
i use,flex-direction: column-reverse; method.
code:
<style>
#part1 {
border-bottom: 4px solid #2b8bc6;
background: linear-gradient(to bottom, #4eb5e5 0%, #389ed5 100%);
top: -40px;
left: 0px;
position: relative;
text-align:center;
border-radius:5px;
}
/* part box */
.part11 {
width: 101px;
height: 101px;
text-align:center;
}
/* text inside part boxes */
</style>
<title>HowTo lose weight fast and safely</title>
</head>
<body>
<div id="relatedcontainer">
<div class="pc_main_mainrelated">
<!-- MAIN (Center website) -->
<div class="pc_cat_mainrelated">
<div class="pc_catrelated">
<div class="pc_cat_columnrelated">
<div class="pc_cat_contentrelated">
<button
onclick="window.location.href = 'HowTo_computers_cat_Networks_cat_.html';">
<img src="/HowTo/img/related3.jpg" alt="networks_img" style="width:100%">
</button>
<h3>How to Run fast</h3>
</div>
</div>
<div class="pc_cat_columnrelated">
<div class="pc_cat_contentrelated">
<button
onclick="window.location.href = 'HowTo_computers_cat_Networks_cat_.html';">
<img src="/HowTo/img/related1.jpg" alt="networks_img" style="width:100%">
</button>
<h3>How to get abs</h3>
</div>
</div>
<div class="pc_cat_columnrelated">
<div class="pc_cat_contentrelated">
<button
onclick="window.location.href = 'HowTo_computers_cat_Networks_cat_.html';">
<img src="/HowTo/img/related2.jpg" alt="networks_img" style="width:100%">
</button>
<h3>How to get fat fast</h3>
</div>
</div>
</div>
</div>
<!-- END MAIN -->
</div>
</div>
<div class="box11">
<div class="internallinks">Main Categories >> Health Sub Categories >> HowTo lose weight fast and safely </div>
<div class="box22">
<br></br>
<hr class="hr1">
<h1>How to Lose Weight fast and safely</h1>
<hr class="hr1">
<p>You want to drop pounds, now. And you want to do it safely. But how?</p>
<p>First, keep in mind that many experts say it’s best to lose weight gradually. It’s more likely to stay off. If you shed pounds too fast, you’ll lose muscle, bone, and water instead of fat, says the Academy of Nutrition and Dietetics.</p>
<p>The academy’s advice: Aim to lose 1-2 pounds per week, and avoid fad diets or products that make promises that sound too good to be true. It’s best to base your weight loss on changes you can stick with over time.</p>
<p>For faster results, you’ll need to work with a doctor, to make sure that you stay healthy and get the nutrients that you need.
<br /><br />
<br /><br />
</div>
</div>
</body>
</html>
css:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
hr.hr1 {
border-top: 0.5px solid #d8e3f5;
}
ul {
list-style-position: inside;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
line-height: 1.9;
background-color: #d8e3f5;
}
.internallinks {
text-align: center;
margin-top: 80px;
color: #767676;
background-color: #d8e3f5;
cursor: default;
}
/* main page + navbar */
#mainboxes {
background: #e9e9e9;
display: flex;
flex-wrap: wrap;
/* align items horizental */
justify-content: center;
/* options for justify-content:
flex-start
flex-end
center
space-between
space-around
space-evenly*/
/* align items vertical must be height */
height: 874px;
align-items: baseline;
/* otions:
flex-start
flex-end
center
baseline
stretch */
align-content: center;
/*align items vertical where extra space */
/* options:
flex-start
flex-end
center
space-between
space-around
stretch*/
/* can also align single item using
align-self: center; or other commands
*/
}
/* logo and navbar buttons */
/* related style */
#pc_main_mainrelated {
box-sizing: border-box;
}
#pc_main_mainrelated .p {
text-align: bottom;
}
#pc_main_mainrelated .body {
background-color: #e9e9e9;
padding: 10px;
font-family: Arial;
}
/* Center website */
.pc_cat_mainrelated {
max-width: 1000px;
margin: auto;
}
#pc_main_mainrelated .h1 {
font-size: 10px;
word-break: break-all;
}
.pc_catrelated {
margin: 8px -16px;
}
/* Add padding BETWEEN each column */
.pc_catrelated,
.pc_catrelated > .pc_cat_columnrelated {
padding: 8px;
}
/* Create four equal columns that floats next to each other */
.pc_cat_columnrelated {
float: left;
width: 25%;
}
/* Clear floats after rows */
.pc_catrelated:after {
content: "";
display: table;
clear: both;
}
/* Content */
/* categories border */
.pc_cat_contentrelated {
border-bottom: 4px solid #2b8bc6;
background: linear-gradient(to bottom, #4eb5e5 0%, #389ed5 100%);
text-align: center;
font-size: 22px;
padding: 12px;
border-radius: 10px;
height: 250px;
margin-top: 50px;
}
/* image in categories */
.pc_cat_contentrelated img {
width: 180px;
height: 100px;
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: cover;
margin-bottom: -2px;
}
/* categories text style */
.pc_cat_contentrelated h3 {
color: white;
font-family: "Open Sans", sans-serif;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
font-size: 20px;
text-indent: 5px;
box-shadow: 0px 1.5px 0px 0px rgba(0, 0, 0, 0.2);
}
#relatedcontainer {
background-color: #d8e3f5;
margin-top: 20px;
flex-direction: column-reverse;
display: flex;
flex-wrap: wrap;
}
.related {
background: #f4f4f4;
border: #ccc solid 1px;
padding: 1rem;
text-align: center;
margin: 0.5rem;
flex-basis: 100px;
}
I fixed it but now got new problem,
i did remove, the float:left , at the {.pc_cat_columnrelated } in CSS
but now the three boxes are above the text, and not right to it.
Hi I have a simple label "District" and drop-down with a list of zip-codes. I simply want to have the label and the drop-down to be side-by-side, horizontal on one line but for some reason it will work. It keeps displaying vertically, as in the label on top and menu on bottom.
here is my html:
<div class="filterButton leaflet-control">
<span><i class="fa fa-filter fa-7x"></i>
<label class="menu">District: </label>
<select class="ml-1 menuContent" name="zipcode" [(ngModel)]="zipcode" (ngModelChange)="selectedZipcode()">
<option>-All-</option>
<option *ngFor="let zipcode of artworkList | duplicates ">{{zipcode}}</option>
</select>
</span>
</div>
and my css:
.filterButton {
margin-left: 43px;
border-radius: 0;
background-clip: padding-box;
border: 2px solid rgba(0, 0, 0, 0.2);
background-position: 50% 50%;
cursor: pointer;
text-align: center;
background-color: #fff;
padding: 3px;
}
.fa-filter:hover {
color: #5690C6;
}
.fa-filter {
color: #1770a6;
font-size: 21px;
padding-left: 4px;
padding-right: 4px;
align-content: center;
}
.menu, .menuContent {
display: inline;
}
You should make display: inline; or display: inline-block on the filterButton, the wrapper of your elements.
I'm trying to make a floating menu for one of my projects but I just can't get it to work.
My aim is to be able to have a horizontal menu floating in in the middle of the screen with a content div underneath. The content div (#preferencescontent), should never be wider than the content insider it, but no wider than 90% of the screen.
Now to the problem. It seems to work, sometimes, and for unknown reasons. Some tables shrink the div to the size of the menu while others expands a lot. I've added an example which for some reason expands the div way more than I expect it to.
Here's the code (codepen below):
<div class="lightbox" id="preferencesdiv">
<div id="preferencesholder">
<div class="sidemenu">
<div id="deviceoverviewbutton" class="menuitem">Device overview</div>
<div id="irulesbutton" class="menuitem">Defined iRules</div>
<div id="certificatebutton" class="menuitem">Certificates</div>
<div id="logsbutton" class="menuitem">Logs</div>
<div id="preferencesbutton" class="menuitem">Preferences</div>
<div id="helpbutton" class="menuitem">Help</div>
</div>
<div id="preferencescontent">
<div id="helpcontent">
<h2>Tips and tricks</h2>
<h3>Filtering for pool members being down</h3>
<p>This one is a bit of a hidden feature. In the Pool/Members column you can filter on "DOWN", "UP" and "DISABLED".</p>
<p>It's not perfect though since pools or members with any of these words in the name will also end up as results.</p>
</div>
</div>
</div>
https://codepen.io/anon/pen/vdOXWj
Grateful for any help. Thank you!
You can try removing float from your elements.
Also, you are adding positioning coordinates to elements which have not been given an explicit position, so you can remove them.
codepen
:root {
--alternatetablecolor: #f9f9f9;
--headerbackgroundcolor: #efefef;
--headerfontcolor: #333;
--bordercolor: #dddddd;
--defaultfontcolor: #222;
}
.lightbox {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
text-align: center;
}
div#preferencesholder {
background: #fff;
display: inline-block;
text-align: left;
max-height: 75%;
max-width: 90%;
overflow: hidden;
padding: 0px;
border: 1px #000 solid;
-webkit-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
margin-top: 100px;
}
div#preferencescontent {
overflow-y: scroll;
max-height: 80%;
margin: 10px;
width: 100%;
}
div.sidemenu {
background-color: var(--headerbackgroundcolor);
width: 100%;
text-align: center;
}
div.sidemenu div.menuitem {
padding: 10px;
font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
display: inline-block;
margin: 0px -2px 0px -2px;
}
div.sidemenu div.menuitem img {
max-height: 30px;
vertical-align: middle;
}
div.menuitem:hover {
background-color: #d0d0d0;
cursor: pointer;
}
div#helpcontent {
max-width: 550px;
margin: 0 auto;
}
<div class="lightbox" id="preferencesdiv">
<div id="preferencesholder">
<div class="sidemenu">
<div id="deviceoverviewbutton" class="menuitem">Device overview</div>
<div id="irulesbutton" class="menuitem">Defined iRules</div>
<div id="certificatebutton" class="menuitem">Certificates</div>
<div id="logsbutton" class="menuitem">Logs</div>
<div id="preferencesbutton" class="menuitem">Preferences</div>
<div id="helpbutton" class="menuitem">Help</div>
</div>
<div id="preferencescontent">
<div id="helpcontent">
<div id="helpcontent">
<h2>Tips and tricks</h2>
<h3>Filtering for pool members being down</h3>
<p>This one is a bit of a hidden feature. In the Pool/Members column you can filter on "DOWN", "UP" and "DISABLED".</p>
<p>It's not perfect though since pools or members with any of these words in the name will also end up as results.</p>
</div>
</div>
</div>
</div>
If you remove "float:left;"
from "div.sidemenu"
Do you get your desired result? I'm not sure I understand what you are trying to achieve here.