I am trying to make my headers contents (the logo and the white text) inline with the content class below where the logo is floating to the left and the text to the right but I am unable to do so since flexbox seems to be disallowing something, I just need help to figure this out.
Navigation Bar:
body {
background-color: #000000;
height: 100%;
margin: 0;
top: 0;
line-height: 160%;
position: relative;
font-family: Tahoma, Arial, Sans Serif;
font-size: 16px;
color: rgba(250, 250, 210, 0.6);
box-sizing: border-box;
overflow-y: hidden;
}
.navigationBar {
background: rgba(0, 0, 0, 0.8);
padding: 20px;
height: 35px;
width: 100%;
position: fixed;
box-shadow: 0px 3px 5px #000;
color: white;
font-size: 38px;
font-family: BurbankBigCondensed-Black, sans-serif;
top: 0;
display: -webkit-box;
/* OLD - iOS 6-, Safari 3.1-6, BB7 */
display: -ms-flexbox;
/* TWEENER - IE 10 */
display: -webkit-flex;
/* NEW - Safari 6.1+. iOS 7.1+, BB10 */
display: flex;
/* NEW, Spec - Firefox, Chrome, Opera */
align-items: center;
justify-content: center;
}
.navigationLogo {
color: #ffa500;
float: left;
margin-right: 1000px;
}
.wrapper {
margin-top: 75px;
width: 100%;
overflow-y: auto;
height: calc(100vh - 75px);
position: fixed;
}
.content {
padding-top: 25px;
margin-left: auto;
margin-right: auto;
min-height: 1500px;
background: rgba(0, 0, 0, 0.5);
width: 1130px;
padding-left: 20px;
padding-right: 20px;
/*border-left: 1px solid #080808;*/
/*border-right: 1px solid #080808;*/
}
.navigationItem {
margin-right: 20px;
}
<div class="navigationBar">
<div class="navigationLogo">Fortnite
<font color="#ffae19">Pro</font>
<font color="#ffb732">Snipes</font>
</div>
<div class="navigationItem">EU</div>
<div class="navigationItem">NAE</div>
<div class="navigationItem">NAW</div>
</div>
<div class="wrapper">
<div class="content">
...
</div>
</div>
Related
I have a popup window (within the same page) which I'm attempting to put a container which scrolls horizontally into, yet it distorts the popup window and does not display anything other than the scrollbar. I'm honestly at a loss, can anyone help me here? I've looked around for solutions but I can't find anything that I can see applies to my problem.
If anyone can help, or point me in the right direction, I'd be really grateful. The scrollbar works perfectly fine when isolated, but inside the window shows like this:
Standalone:
My HTML (popup window with scrollbar inside)
<div id="formula-popup" class="popup-window">
<div>
<a onclick="closeFormulaWindow()" title="Close" class="close">X</a>
<span id="ftitle" class="title1"></span>
<form method="post" id="formulaform" name="edit">
<span>Current Formula</span>
<p id="current-formula" class="formula">Existing formula</p>
<input id="id-passer" type="hidden" name="formula-id" value="">
<!--sort out horizontal scrollbar from bookmarks here later-->
<input onclick="refreshWindow()" name="edit-formula" type="submit" value="Confirm">
</form>
<div class="h-scrollbar">
<section class="h-scrollbar-container">
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
</div>
</div>
<div class="pseudo-track"></div>
</section>
</div>
</div>
My CSS:
.scrollbar-container {
display: flex;
flex-direction: row;
}
.h-scrollbar {
display: flex;
max-width: 30vw;
padding: 0px 10px;
height: 20vh;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.h-scrollbar-container {
width: 100%;
}
.outer-wrapper {
max-width: 100vw;
overflow-x: scroll;
position: relative;
scrollbar-color: #d5ac68 #f1db9d;
scrollbar-width: thin;
-ms-overflow-style: none;
}
.pseudo-track {
background-color: #f1db9d;
height: 2px;
width: 100%;
position: relative;
top: -3px;
z-index: -10;
}
.outer-wrapper::-webkit-scrollbar {
height: 5px;
}
.outer-wrapper::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 0px rgba(0, 0, 0, 0);
}
.outer-wrapper::-webkit-scrollbar-thumb {
height: 5px;
background-color: #d5ac68;
}
.outer-wrapper::-webkit-scrollbar-thumb:hover {
background-color: #f1db9d;
}
.outer-wrapper::-webkit-scrollbar:vertical {
display: none;
}
.inner-wrapper {
display: flex;
padding-bottom: 10px;
}
.pseudo-item {
height: 30px;
width: 80px;
margin-right: 15px;
flex-shrink: 0;
background-color: gray;
}
.pseudo-item:nth-of-type(2n) {
background-color: lightgray;
}
.popup-window {
position: fixed;
font-family: Arial, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
}
.popup-window div {
width: 40vw;
height: 30vw;
position: relative;
margin: 10% auto 30%;
border-radius: 10px;
background: #213B54;
padding-top: 2vh;
padding-left: 1vw;
padding-right: 1vw;
padding-bottom: 2vh;
display: flex;
flex-direction: column;
}
.close {
font: Arial, sans-serif;
background: #067A9F;
color: #B5E5E7;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
border-radius: 12px;
box-shadow: 1px 1px 3px #000;
cursor: pointer;
}
.popup-window div .title1 {
font-family: Arial, sans-serif;
font-weight: normal;
font-size: 36px;
color: #EE6802;
align-self: center;
}
.popup-window form input[type=submit]:hover {
opacity: 0.8;
}
.popup-window form span {
color: #EE6802;
font-size: 22px;
}
.popup-window form {
display: flex;
flex-direction: column;
font-family: Arial, sans-serif;
}
.popup-window form span, input {
width: 100%;
}
.popup-window form input[type=submit] {
width: 20%;
background-color: #067A9F;
color: #213B54;
padding: 14px 0;
cursor: pointer;
border: none;
}
I found the solution, it was that I forgot to select an element inside the window properly and instead it was selecting all divs and so overriding the CSS properties.
On my site, there is a scrolling container, which contains static cards that display certain data. The user scrolls through the cards one-by-one. On iOS Safari, only the first 2 cards are displaying, and as I scroll through, the other cards are invisible.
From the screenshot you can see that the element is there on the page, but invisible. You can even select the text on the element as if its there. The HTML and CSS behind every card is exactly the same.
.rc_eid-card {
position: relative;
width: 202px;
min-width: 202px;
height: 282px;
border-radius: 8px;
background: white;
padding: 20px;
box-sizing: border-box;
z-index: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
scroll-snap-align: start;
margin-right: 16px;
&:last-child {
margin-right: 0;
}
img {
width: 40px;
margin-bottom: 16px;
}
h3 {
font-family: $font-base;
font-size: 32px;
font-weight: 700;
color: #BE67A1;
}
&--text {
font-size: 16px;
line-height: 1.375;
color: $color-grey--dark;
}
&--bottom {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
font-size: 12px;
color: $color-grey--dark;
}
}
This is the CSS for the container if that matters as well:
.rc_eid-container--scrolling {
display: flex;
justify-content: center;
overflow: auto;
max-width: 1074px;
width: 100%;
margin: auto;
padding: 8px;
scroll-padding: 8px;
scroll-snap-type: x mandatory;
box-sizing: border-box;
filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.15)) drop-shadow(0px 4px 10px rgba(0, 0, 0, 0.1));
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
&::-webkit-scrollbar {
display: none;
}
#media (max-width: 1073px) {
justify-content: flex-start;
}
}
Thanks in advance!
This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Flexbox: center horizontally and vertically
(14 answers)
css single or multiple line vertical align
(8 answers)
Closed 10 months ago.
I've included the JSFiddle below.You have to shrink the size to about 670px to see the issue. What I am trying to fix are the flexbox items at the bottom of the page where the footer says "call xxx-xxx-xxxx". It is hard to see because the background image isn't loaded on the JSFiddle, but when the screen shrinks, the text "to schedule a consultation" pushes into the white background. Initially I used the line height trick, making it equal to the container height, so it vertically centers my first line of text but pushes the second line 100px down off the footer. What I am going for is to make both lines of text center vertically together instead of 100px apart.
https://jsfiddle.net/4m7pysqb/
HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1">
<title>DLGTreecare - Home</title>
<link rel="icon" href="images/favicon-16x16.png">
<link rel="Stylesheet" href="DLGtreecare.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome#1.1.7/css/fork-awesome.min.css" integrity="sha256-gsmEoJAws/Kd3CjuOQzLie5Q3yshhvmo7YNtBG7aaEY=" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab:wght#400;500&display=swap" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="dlg.js"></script>
</head>
<body>
<div class="header">
<div class="heroimagecontainer">
<img class="heroimage" src="images/heroimage.jpg">
</div>
<div class="redbar">
</div>
<div class="orangebar">
</div>
</div>
<div class="wrapper">
<div class="logowrapperdiv">
<div class="logoarea"> <p class="dlg">DLG Tree Care </p> <img class="logo" src="images/logotransparent.png"> </div>
<p class="undertree">Professional Tree Services</p>
</div>
<!-- https://drive.google.com/file/d/1YcJmJO-7mKo1er338P4AQ9Kn6HohaJsy/preview
https://drive.google.com/uc?export=view&id=1YcJmJO-7mKo1er338P4AQ9Kn6HohaJsy
-->
<div class= maincontent>
<p class="intro">PROVIDING THE "518" WITH ALL YOUR TREE CARE NEEDS!</p>
<iframe class="videointro" src="https://drive.google.com/file/d/1YcJmJO-7mKo1er338P4AQ9Kn6HohaJsy/preview" allow="autoplay"></iframe>
<div> </div>
<div class="phonebar"> Call 518-407-9500 for a free estimate!</div>
<div class="messagebuttontext"> Or message us on
<a class="messagebutton" href="https://m.me/DLGTreeCare">
<span style=color:orange>Facebook!</span>
<i class="fa fa-facebook-messenger fa-1x" aria-hidden="true"></i>
</a></div>
<div class="clearfix"></div>
</div>
<h2>Services</h2>
<h6>(Click images to see "before and after")</h6>
<div class="services">
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Tree Removal</p><p class="servicedescription ">Removing dead or unwanted trees is sometimes a must, using the proper skills this can be done safely</p>
<img class="toggleon" src = "images/beforeafter/treeremovalflip_300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Tree Trimming</p><p class="servicedescription ">Having your trees trimmed properly is important and can help maintain healthy future growth</p>
<img class="toggleon" src = "images/beforeafter/treetrimmingflip_300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Stump Grinding</p><p class="servicedescription">By grinding the stump of the tree we are able to totally remove the stump in order to grow grass or replant something new</p>
<img class="toggleon" src = "images/beforeafter/stumpgrindingflip_300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Hedge Trimming</p><p class="servicedescription ">From big to small, we have the tools and expertise for all your needs</p>
<img class="toggleon" src = "images/beforeafter/hedgetrimmingflip300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Fruit Tree Pruning</p><p class="servicedescription">From big to small, we have the tools and expertise for all your needs</p>
<img class="toggleon" src = "images/beforeafter/fruittreeflip_300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Wood & Brush Removal</p><p class="servicedescription">From big to small, we have the tools and expertise for all your needs</p>
<img class="toggleon" src = "images/beforeafter/treeremovalflip300x400.png">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Lot Clearing</p><p class="servicedescription">We can turn any wooded lot into an open usable space for the building of Homes, Businesses, etc.</p>
<img class="toggleon" src = "images/beforeafter/lotclearingflip300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Cabling & Bracing</p><p class="servicedescription">Large branches and/or weak crotches sometimes can split under their own weight, cabling can keep this from happening without damaging the tree</p>
<img class="toggleon" src = "images/beforeafter/cablingbracingflip_300x400.jpg">
</div>
<div class="servicenode"><button class="mybutton" type="button">></button><p class="servicetitle">Storm Damage</p><p class="servicedescription">We're available 24/7 for any tree related emergencies</p>
<img class="toggleon" src = "images/beforeafter/stormdamageflip_300x400.jpg">
</div>
</div>
<h2>See more of our work</h2>
<div class="gallery">
<div class="gallerynode"><img class="galleryimg" src="images/GALLERY/Resized95FB95IMG951628801998990.jpg"></div>
<div class="gallerynode"><img class="galleryimg" src="images/GALLERY/FB95IMG951628860144118.jpg"></div>
<div class="gallerynode"><img class="galleryimg" src="images/GALLERY/FB_IMG_1628860108712.jpg"></div>
<div class="gallerynode"><img class="galleryimg" src="images/GALLERY/Resized_20210319_094919.jpg"></div>
<div class="gallerynode"><img class="galleryimg" src="images/GALLERY/Resized_20210325_104241.jpg"></div>
<div class="gallerynode"><img class="galleryimg" src="images/GALLERY/Resized_20210322_131140.jpg"></div>
</div>
<div class="flex-container">
<div class="flex-item">Serving the 518 area</div><div class="flex-item">Call 518-407-9500 to schedule a consultation.</div>
</div>
</div>
</body>
</html>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root{
/* base red */
--base-red: 10;
/* base yellow */
--base-yellow: 60;
/* base green */
--base-green: 99;
/*base blue*/
--base-blue: 200;
/* colors */
--brown-normal: hsla(17, 42%, 41%, 100%);
--brown-normal: hsla(17, 42%, 41%, 100%);
--red-light: hsla(var(--base-red), 100%, 75%, 100%);
--red-normal: hsla(var(--base-red), 100%, 45%, 100%);
--red-darker: hsla(var(--base-red), 100%, 35%, 100%);
--yellow-light: hsla(var(--base-yellow), 50%, 75%, 100%);
--yellow-normal: hsla(var(--base-yellow), 50%, 50%, 100%);
--yellow-darker: hsla(var(--base-yellow), 50%, 35%, 100%);
--green-light: hsla(var(--base-green), 50%, 75%, 100%);
--green-normal: hsla(var(--base-green), 50%, 50%, 100%);
--green-darker: hsla(var(--base-green), 50%, 35%, 100%);
--blue-light: hsla(var(--base-blue), 50%, 75%, 100%);
--blue-normal: hsla(var(--base-blue), 50%, 50%, 100%);
--blue-darker: hsla(var(--base-blue), 50%, 35%, 100%);
}
#font-face {
font-family: TreeHuggerMedium-lEqZ;
src: url(TreeHuggerMedium-lEqZ.ttf);
}
body {
min-height: 100vh;
max-height: 195.625rem;
background-image: url("images/stump.jpg");
background-color: white;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
margin: auto;
}
div.header {
min-width: 320px;
text-align: center;
height: 300px;
}
div.heroimagecontainer {
height: 210px;
width: inherit;
}
img.heroimage {
height: 100%;
width: 100%;
object-fit: cover;
}
div.redbar {
width: inherit;
background-color: var(--red-normal);
height: 20px;
}
div.orangebar {
width: inherit;
background-color: orange;
height: 70px;
}
div.logowrapperdiv {
min-width: 320px;
max-width: 1000px;
position: relative;
height: auto;
margin: auto;
top: -50px;
}
div.logoarea {
border-bottom-style: solid;
border-color: white;
border-width: 5px;
min-width: 320px;
max-width: 525px;
margin: auto;
height: 92px;
color: white;
position: relative;
}
img.logo {
max-width: 36.5%;
top: -188px;
display: block;
left: 17%;
position: relative;
overflow: visible;
z-index: 105;
object-fit: contain;
}
p.dlg {
font-family: Roboto Slab;
position: relative;
max-width: 525px;
min-width: 320px;
font-size: 3.9em;
font-weight: 500;
text-align: center;
white-space: pre;
top: 20px;
}
.undertree {
font-family: Roboto Slab;
font-weight: 500;
max-width: 525px;
color: white;
text-align: center;
height: 50px;
margin: auto;
margin-top: 0;
padding-bottom: 40px;
letter-spacing: 0.10em;
font-size: 2.16em;
position: relative;
top: 0px;
}
.wrapper {
margin: auto;
min-width: 320px;
max-width: 1000px;
background-image: linear-gradient(var(--brown-normal), orange);
padding-top: 50px;
border-radius: 0px 0px 5px 5px;
}
.maincontent {
min-width: 320px;
text-align: center;
height: auto;
color: white;
position: relative;
margin-bottom: 25px;
padding: 15px;
}
.intro {
font-family: Roboto Slab;
font-weight: 400;
font-size: 1.7em;
color: white;
text-align: center;
padding-bottom: 25px;
min-width: 300px;
max-width: 1000px;
}
.videointro {
min-width: 300px;
min-height: 225px;
position: relative;
display: block;
border-style: solid;
border-width: 2px;
border-color: white;
border-radius: 5px;
margin: auto;
}
.phonebar {
font-family: Roboto Slab;
font-weight: 400;
text-align: center;
position: relative;
float: left;
min-width: 295px;
max-width: 550px;
margin: 25px 0px 0px 20px;
font-size: 1.7em;
border: 1px solid white;
padding: 5px;
border-radius: 15px;
}
.phonebar a {
color: orange;
text-decoration: none;
}
.messagebutton {
display: inline-block;
text-align: center;
color: orange;
position: relative;
margin: auto;
text-decoration: none;
}
.messagebuttontext {
min-width: 295px;
max-width: 550px;
color: white;
position: relative;
font-family: Roboto Slab;
font-weight: 400;
font-size: 1.7em;
display: block;
float: right;
border: 1px solid white;
border-radius: 15px;
margin: 25px 20px 0px 0px;
padding: 5px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
/*code for photo galley */
h2 {
font-family: Roboto Slab;
font-weight: 400;
text-align: center;
font-size: 5em;
color: white;
margin: 50px auto;
position: relative;
}
h6 {
font-size: 2em;
font-family: Roboto Slab;
font-weight: 400;
text-align: center;
color: white;
position: relative;
margin: 10px auto;
}
button {
appearance: button;
background-color: white;
color: red;
cursor: pointer;
font-weight: 500;
border-color: white;
z-index: 101;
top: 30px;
left: 0px;
position: relative;
border-radius: 5px;
height: 25px;
width: 25px;
margin: 0 auto;
border-width: 1px;
transition: transform .3s linear;
}
.buttonrotate {
transform: rotate(90deg);
}
.services {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
width: auto;
height: auto;
margin: auto;
}
.servicenode {
position: relative;
width: 300px;
margin: auto;
margin-bottom: 25px;
}
.servicenode img {
display: block;
margin-left: auto;
margin-right: auto;
width: 300px;
height: 200px;
object-fit: none;
border: 1px solid red;
border-radius: 8px;
transition: 0.1s object-position ease;
position: relative;
}
.servicetitle {
font-family: Roboto Slab;
font-weight: 400;
font-size: 1.4em;
vertical-align:top;
display:inline-block;
color: white;
width: 100%;
position: relative;
text-align: center;
margin-bottom: 10px;
}
.servicedescription {
font-family: Roboto Slab;
font-weight: 400;
font-size: 1.2em;
color: white;
z-index: 100;
transition-property: opacity, border-radius;
transition-duration: .4s;
transition-timing-function: linear;
opacity: 0;
margin: auto;
width: 298px;
position: absolute;
display: block;
background: rgba(0,0,0, 0.6);
left: 0;
right: 0;
border-radius: 8px 8px 8px 8px;
text-align: center;
user-select: none; /* supported by Chrome and Opera */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
pointer-events: none;
}
.servicedescriptionshow {
position: absolute;
display: block;
width: 298px;
left: 0;
right: 0;
border-radius: 8px 8px 0px 0px;
text-align: center;
opacity: 1;
}
.toggleon {
object-position: top;
cursor: pointer;
}
.toggleoff {
object-position: bottom;
cursor: pointer;
}
/* Gallery stuff */
.gallery {
display: grid;
grid-template-columns: repeat(2, minmax(320px, auto));
width: auto;
height: auto;
margin: auto;
}
.gallerynode {
color: white;
text-align: center;
position: relative;
margin: auto;
border-width: 1px;
border-style: solid;
border-color: white;
height: 490px;
}
.galleryimg {
object-fit: cover;
width: 490px;
height: 490px;
}
/* footer stuff */
.footer {
height: 5vh;
width: 100%;
background-color: white;
position: relative;
margin-top: 100px;
bottom: 0;
border-style: solid;
border-color: red;
border-width: 3px;
border-radius: 0px 0px 5px 5px;
}
.flex-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-top: 10px;
}
.flex-item {
-ms-flex-preferred-size: 33%;
flex-basis: 50%;
background-color: orange;
padding: 5px;
height: 100px;
color: white;
font-weight: bold;
font-size: 1.5em;
text-align: center;
border: 1px solid #333;
box-sizing: border-box;
line-height: 100px;
}
.flex-item a {
color: white;
}
/* media queries */
#media screen and (max-width: 1000px) {
div.maincontent {
height: auto;
}
.messagebuttontext {
float: none;
margin: 20px auto;
}
.phonebar {
float: none;
margin: 20px auto;
}
.gallery {
grid-template-columns: repeat(1, minmax(320px, auto));
}
.flex-item {
font-size: 1em;
}
}
#media screen and (max-width: 545px) {
div.logoarea {
width: 420px;
}
p.dlg {
font-size: 3em;
top: 35px;
}
img.logo {
left: 17%;
top: -130px;
}
.undertree {
font-size: 1.6em;
}
}
#media screen and (max-width: 500px) {
.gallerynode {
height: 320px;
}
.galleryimg {
object-fit: cover;
width: 320px;
height: 320px;
margin: auto;
}
}
#media screen and (max-width: 485px) {
div.logoarea {
width: 320px;
}
img.logo {
top: -86px;
left: 16%
}
p.dlg {
font-size: 2.6em;
top: 42px;
}
}
#media screen and (max-width: 354px) {
p.dlg {
font-size: 2.6em;
top: 42px;
}
.undertree {
font-size: 1.39em;
}
img.logo {
top: -86px;
}
.maincontent {
padding: 8px;
}
}
JS
$(document).ready(function(){
$(".servicenode > img").click(function(){
$(this).toggleClass('toggleon toggleoff');
});
$(".mybutton").click(function() {
$(this)
.siblings(".servicedescription")
.toggleClass('servicedescriptionshow');
$(this).toggleClass('buttonrotate');
});
});
Having trouble centering text vertically in a fieldset. This particularly when a sibling is hidden.
This is what the code should looks like when the sibling is showing:
#title {
margin: 20px;
}
#definition {
margin: 0 auto;
margin-top: 5%;
text-align: center;
max-width: 60%;
font-size: 1.5vmax;
}
hr {
color: white;
background-color: white;
width: 80%;
height: 1px;
}
#formulaLine {
color: white;
background-color: white;
height: 1px;
}
section#formula {
width: auto;
max-width: 70%;
background: #393e46;
box-shadow: inset 2px 5px 10px rgb(24, 23, 23);
border-radius: 5px;
margin: 5% auto;
padding: 10px;
font-size: 2vmax 1vmin;
}
.center {
text-align: center;
}
p .center {
margin-top: 5%;
}
.tBox {
position: relative;
width: auto;
max-width: 100%;
min-height: 400px;
max-height: 500px;
background-color: #222831;
border-radius: 5px;
margin: 40px auto;
align-content: center;
color: #eeeeee;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12) !important;
font-family: 'Lato', sans-serif;
}
.legend {
padding: 0.2em 0.8em;
background: #d65a31;
border-radius: 25px;
float: left;
margin-top: -20px;
margin-left: 20px;
width: auto;
min-width: 200px;
font-size: 3vmax 2vmin;
font-family: 'Lato', sans-serif;
}
<div>
<fieldset class="tBox">
<legend class="legend">Definition</legend>
<div id="definition">Answers if we did what we said we would do. BECAUSE IT'S LONG I'LL ADD EXTRA TEXT TO SHOW MULTI-LINE EFFECT</div>
<div>
<hr>
<section id="formula">
<div class="row">
<p class="column center" style="margin-top: 5%; margin-left: 3%;">Formula:</p>
<div class="column center">
<p>∑ # completed tasks in month 'A' (from month 'B' schedule)</p>
<hr id="formulaLine">
<p>∑ # tasks forecased to finish in month 'A'</p>
</div>
</div>
</section>
</div>
</fieldset>
</div>
Problem is that when hiding the formula sibling (I am using React), the definition doesn't center. It looks like this:
#title {
margin: 20px;
}
#definition {
margin: 0 auto;
margin-top: 5%;
text-align: center;
max-width: 60%;
font-size: 1.5vmax;
}
hr {
color: white;
background-color: white;
width: 80%;
height: 1px;
}
#formulaLine {
color: white;
background-color: white;
height: 1px;
}
section#formula {
width: auto;
max-width: 70%;
background: #393e46;
box-shadow: inset 2px 5px 10px rgb(24, 23, 23);
border-radius: 5px;
margin: 5% auto;
padding: 10px;
font-size: 2vmax 1vmin;
}
.center {
text-align: center;
}
p .center {
margin-top: 5%;
}
.tBox {
position: relative;
width: auto;
max-width: 100%;
min-height: 400px;
max-height: 500px;
background-color: #222831;
border-radius: 5px;
margin: 40px auto;
align-content: center;
color: #eeeeee;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12) !important;
font-family: 'Lato', sans-serif;
}
.legend {
padding: 0.2em 0.8em;
background: #d65a31;
border-radius: 25px;
float: left;
margin-top: -20px;
margin-left: 20px;
width: auto;
min-width: 200px;
font-size: 3vmax 2vmin;
font-family: 'Lato', sans-serif;
}
<div>
<fieldset class="tBox">
<legend class="legend">Definition</legend>
<div id="definition">MY TEXT HERE. IT CAN GET LONG. MULTI-LINE. HERE'S MORE TO FILL THIS OUT. LONG LONG LONG.</div>
</fieldset>
</div>
Note that the CSS for this second example is the same as above. What am I doing wrong? I've tried Top, Float, and a variety of other options. None seem to work.
I would recommend adjusting your markup to support using :only-child in CSS. This is a pseudo-class that represents an element without any siblings. Definitely give the documentation a review for some other examples.
/* Selects each <p>, but only if it is the only child of its parent. */
p:only-child {
background-color: lime;
}
It's pretty useful for situations just like this and the implementation wouldn't take very many changes.
var formula = document.createElement("P");
formula.innerText = "This element represents your formula being added to the container which removes the styles applied with :only-child.";
var active = false;
function toggleFormula() {
active = !active;
document.getElementById("legend").innerText = active ? "Click here to hide formula." :
"Click here to show formula.";
let tbox = document.getElementById("t-box");
if (active)
tbox.appendChild(formula);
else
tbox.removeChild(formula);
}
.container { position: relative; }
.legend {
position: absolute;
top: -10px;
left: 20px;
z-index: 1;
padding: 0.2em 0.8em;
background: #d65a31;
border-radius: 25px;
width: auto;
min-width: 200px;
font-size: 3vmax 2vmin;
font-family: 'Lato', sans-serif;
cursor: pointer;
}
#definition {
margin: 0 auto;
margin-top: 5%;
text-align: center;
max-width: 60%;
font-size: 1.5vmax;
}
#definition:only-child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.tBox {
position: relative;
width: auto;
max-width: 100%;
min-height: 400px;
max-height: 500px;
background-color: #222831;
border-radius: 5px;
margin: 40px auto;
align-content: center;
color: #eeeeee;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12) !important;
font-family: 'Lato', sans-serif;
}
#definition {
margin: 0 auto;
margin-top: 5%;
text-align: center;
max-width: 60%;
font-size: 1.5vmax;
}
#definition:only-child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<legend id="legend" class="legend" onclick="toggleFormula();">Click here to show formula.</legend>
<fieldset id="t-box" class="tBox">
<div id="definition">Answers if we did what we said we would do. BECAUSE IT'S LONG I'LL ADD EXTRA TEXT TO SHOW MULTI-LINE EFFECT</div>
</fieldset>
</div>
Alternative options are using position: absolute or display: flex:
/* Absolute Version */
#definition.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* Flex Version */
.tBox {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
With your exiting code, just adding few properties to your css will be an easy fix. Flex properties are really helpful in these scenarios, align-items: center will align all elements inside the div to align vertically and justify-content: center will align items horizontally.
section#formula {
width: auto;
max-width: 70%;
background: #393e46;
box-shadow: inset 2px 5px 10px rgb(24, 23, 23);
border-radius: 5px;
margin: 5% auto;
padding: 10px;
font-size: 2vmax 1vmin;
display: flex;
justify-content: center;
align-items: center;
}
.center {
justify-content: center;
display: flex;
width: 100%;
flex-flow: row wrap;
}
You can see it here.
My #main element ignores it's wrapper padding. I set position:absolute on children, but when I try to change it from position:static,to position:relative it just ignores parent's height. Any workarounds?
body, html {
height: 100%;
margin: 0;
padding: 0;
}
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding: 25px;
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button, .menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
height: 100%;
width: 100%;
position: absolute;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test
<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
https://jsfiddle.net/Ldmmxw9m/3/
It doesn't ignore the parents height when using position: relative, it simply keeps the padding of the parent, but apart from that it fills the parent - see my snippet. Of course the parent's height has to be set when you use a percentage value for the child's height...
#wrapper-main{
flex:1 1 auto;
display:flex;
align-items:center;
justify-content:center;
position:relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding:25px;
background-color:yellow;
height: 200px;
}
#main{
background-color:green;
height:100%;
width:100%;
position:relative;
}
<div id="wrapper-main">
<main id="main">
some content
</main>
</div>
As Santi said, you can remove position: absolute on #main, since that will place the element relative to it's nearest positioned ancestor, ignoring the ancestor's padding.
Or if that's not an option, you could use top/left/right/bottom values that match the padding amount, and remove the padding on the parent if that's no longer needed.
/* TAGS */
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
/* END OF TAGS */
/* WRAPPERS */
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
/* END OF WRAPPERS */
/* CONTENT */
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button,
.menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
top: 25px;
left: 25px;
right: 25px;
bottom: 25px;
position: absolute;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<body>
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test
<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
</body>
1. Remove position: absolute; from #main.
Absolutely positioned items are "out of the flow". Setting the parent to relative will modify the absolute child element's bounding box to it's own height and width, but padding is not taken into account.
2. Change the wrapper's align-items: center; to align-items: stretch;
It seems to me that you don't want the child to be vertically-aligned in the middle, but rather to take up the entire height of the wrapper. align-items: stretch will apply this behavior.
Updated Fiddle
/* TAGS */
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
/* END OF TAGS */
/* WRAPPERS */
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: stretch;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding: 25px;
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
/* END OF WRAPPERS */
/* CONTENT */
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button,
.menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
width: 100%;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<body>
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
</body>
Try adding this to the parent element:
box-sizing:border-box;
This changes how the width and height is calculated by the browser so it includes padding and borders. With flex, using border-box on the parent has corrected spacing issues.