Make display:flex responsive while retaining alignment - html

Hello fellow stackers.
I have used display:flex on a div which sits in the middle of the Y and X div, as you can see here. However I want to make it responsive, which it NEARLY is! When I resize the browser wide down to around 250 pixels the div and the text within the div just stops responding.
Now I understand that if I remove display:flex it will allow the text to continue responding. However, when I do so the alignment drops to the bottom of the div. The misalignment doesn't display when I remove display:flex though which leads me to believe that there is something in my code which relies on display:flex to retain the alignment. You can view the website here. Please find the code below, and the Jsfiddle in the link above. Much obliged.
#registry {
background-color:#fff;
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
}
.pane {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
min-height:50vh;
padding:6rem 1.5em;
position:relative;
width:100%
}
.pane .pane-title, .pane .title-section {
margin-bottom:2em;
}
.pane-title h2{
font-family: 'Abril Fatface', cursive;
text-transform: uppercase;
font-size: 1.875em;
}
#media (max-width:222px){
.pane-title h2{
font-size:1.3em;
}
}
.pane .pane-content {
max-width:68em;
margin-left:auto;
margin-right:auto
}
.pane .pane-content::after {
clear:both;
display:table
}
.pane .pane-row {
display:block;
margin-bottom:3em
}
.pane .pane-row::after {
clear:both;
display:table
}
.pane.flex {
display:-webkit-flex;
display:-ms-flexbox;
display:flex;
flex:1;
flex-direction: column
-ms-flex-line-pack:center;
-webkit-justify-content:center;
-ms-flex-pack:center;
justify-content:center
}
.pane.flex .pane-content {
-webkit-align-self:center;
-ms-flex-item-align:center;
align-self:center
}
#registry {
background-image:url(http://kadeem.london/Content/Image/KL.png);background-color:#e94378;
-webkit-background-size:cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size:cover;
min-height:110vh
}
#registry .pane-content {
max-width:48em;
background-color:#fff;
padding:6em 2em
}
#media screen and (min-width:768px) {
#registry .registry-description {
float:left;
display:block;
margin-right:2.12766%;
text-decoration: none;
width:65.95745%;
margin-left:17.02128%
}
#registry .registry-description:last-child {
margin-right:0
}
#registry p {
text-align:center
}
}
.registry-description p a{
text-decoration: none;
border-bottom: 1px solid #000;
color: #000;
}
.registry-description p a:hover{
text-decoration: none;
background-color: #000;
color: #fff;
}
<section id="registry" class="pane flex">
<div class="pane-content">
<div class="pane-title">
<h2>Get In Touch</h2>
<span class="underline"></span>
</div>
<div class="registry-description">
<p>I hope your liking my website so far. If you would like to work with me you can give me a call or message me on the email below. Alternatively you can view more of my articles, designs, and projects.
</p>
<br>
<button class="connn"><a>contact#kadeem.london</a>
</button>
</div>
</div>
</section>

Your contact button (contact#kadeem.london) is what is stopping the content from resizing down any further.
However, having said that, you probably don't need to worry about supporting devices that narrow - all devices I'm aware of are at least 480px wide in portrait orientation.

Related

Flexbox height displays as 0px, contains img tags

I'm trying to get two images to display in a row, so I'm using a flexbox. I set the box's height to be 500px, but it almost* always calculates to be 0px. It reminds me of the issue with floating elements within, but I've tried this out with img {display:block} and by nesting the img tags in container divs, but neither seem to work.
= I say "almost" because when viewing on a test page in Chrome 49.0.2623.112 (but not my fiddle) and adjusting the viewport's width, right after the media query flips from the min-width:737px style to the max-width:736px style, the flexbox suddenly has height.
Here's a fiddle: https://jsfiddle.net/territorylit/6v4euuwL/
CSS
.popup_background {
position:fixed;
left:0;
top:0;
width:100%;
height:100%;
background-color:rgba(255,255,255,0.8);
z-index:100000000;
}
#media screen and (min-width:737px) {
}
#media screen and (max-width:736px) {
}
.popup_background img.button {
position:fixed;
right:0;
top:0;
width:50px;
height:50px;
border: none;
z-index:100000001;
transition:all 0.1s linear;
}
.popup_background img.button:hover {
border-right-style:solid;
border-right-color:rgba(175,0,175,1);
border-top-style:solid;
border-top-color:rgba(175,0,175,1);
}
#media screen and (min-width:737px) {
.popup_background img.button {
margin-right: calc(5% + 3px);
margin-top: calc(5% + 3px);
padding-top:5px;
}
.popup_background img.button:hover {
margin-right: calc(5% + 3px);
margin-top: calc(5% + 3px);
border-right-width:3px;
border-top-width:3px;
padding-right:3px;
padding-top:8px;
}
}
#media screen and (max-width:736px) {
.popup_background img.button {
padding-top:5px;
}
.popup_background img.button:hover {
}
}
.popup_container {
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
justify-content:center;
align-items:center;
align-content:center;
flex-direction:column;
overflow-y:scroll;
background-color:rgba(255,255,255,0.9);
}
#media screen and (min-width:737px) {
.popup_container {
margin-left:5%;
margin-right:5%;
margin-top:5%;
margin-bottom:5%;
border-width:3px;
border-style:solid;
border-color:rgba(0,0,0,0.6); /* grey */
box-shadow: 0px 0px 3px 2px rgba(10,123,167,0.2); /* cerulean */
}
}
#media screen and (max-width:736px) {
.popup_container {
margin-left:3%;
margin-right:3%;
margin-top:3%;
margin-bottom:3%;
border-width:2px;
box-shadow: 0px 0px 3px 2px rgba(255,255,255,0.9); /* white transparent */
}
}
.popup_container.top_heavy {
justify-content:flex-start;
}
p.chelsea {
font-family:garamond,serif;
font-size:1.3em;
}
#media screen and (min-width:737px) {
p.chelsea {
max-width:70%;
line-height:140%;
}
}
#media screen and (max-width:736px) {
p.chelsea {
height:auto;
max-width:90%;
line-height:130%;
}
}
p.chelsea.footnote {
font-family:garamond,serif;
font-size:1rem;
text-align:right;
margin-bottom:1.5rem;
}
#media screen and (min-width:737px) {
p.chelsea.footnote {
width:50%;
}
}
#media screen and (max-width:736px) {
p.chelsea.footnote {
width:90%;
}
}
p.chelsea.translation {
font-size:1.2rem;
line-height:150%;
}
p.chelsea img {
width:100%;
}
.milky {
height:500px;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
flex-direction:row;
justify-content:center;
align-items:flex-start;
align-content:center;
flex-wrap:nowrap;
overflow:hidden;
}
#media screen and (min-width:737px) {
.milky {
width:70%;
}
}
#media screen and (max-width:736px) {
.milky {
width:90%;
}
}
#rotation-01 {
flex:0.6;
}
#rotation-02 {
flex:1.5686;
}
HTML
<div id="section_04" class="section">
<div class="popup_background">
<img class="button" src="http://res.cloudinary.com/territory/image/upload/v1461522074/general/hr_grey_50x50.png" onclick="talkPopUpOff(this.id)" id="section_04_off" />
<div class="popup_container top_heavy">
<p class="chelsea"> </p>
<div class="milky">
<img id="rotation-01" src="https://static1.squarespace.com/static/557a4c2ee4b0fe5a537746b5/t/58b76175bf629a06758f0e2c/1488413284637/milky-way-rotation-1.jpg" />
<img id="rotation-02" src="https://static1.squarespace.com/static/557a4c2ee4b0fe5a537746b5/t/58b7618b8419c2a168e77ac6/1488413330003/milky-way-rotation-2.jpg" />
</div>
<p class="chelsea">“...in the absence of a bright star near the celestial south pole, Quechua peoples and their ancestors organized the sky by reference to the Milky Way, called Mayu or the “celestial river,” and its apparent cruciform rotations. In a twenty-four-hour period, the Milky Way forms two intersecting intercardinal axes that divide the heavens into quarters. Since the plane of the Milky Way is inclined in relation to the earth’s axis, the stars of one quarter will rise as those of the opposite quarter set as the earth rotates. Astronomical phenomena can be tracked with respect to these quarters, which create a systematic means for the spatial and temporal reckoning of the world and its natural and social rhythms. This principle is central to pre-Columbian spatial reckoning.”</p>
<p class="chelsea footnote">Gartner, William Gustav. "6· Mapmaking in the Central Andes." <em>Americas</em> 169 (1970): 647-54.</p>
<p class="chelsea"> </p>
</div>
</div>
</div>
Your problem is that .popup_container is a flexbox.
Simply change .popup_container to display: block, take the height off of .milky, and I believe it will behave as you would like.
Why?
The items within the .popup_container flexbox (such as your content, images, and footnote) automatically try to share all the vertical space, which is 100% of the display height, since .popup_container is a descendant of .popup_background, which has height: 100%. However, there is an exception. For some reason (if anyone knows why I'll be glad to include it), the text content takes precedence over the flexbox with the images. While the text gets to use up all the space it needs, the flexbox is reduced to barely anything. Your height property on the flexbox is obsolete because it is, itself, a flexbox item.
Also note: it's bad practice to have a fixed element the child of a fixed element, which is what you currently have. The inner element doesn't need to be fixed at all.

How can I implement a CSS styled flag into my topbar?

So my website should be multilingual. To let the user change between languages there will be flags in a dropdown.
To get a better resize ability for my images (of the flags) I wanted to create them soley via CSS. However I failed doing this, so I created little 1x3 and 3x1 .jpgs files which I wanted to resize via CSS.
Here are 2 examples I created:
(Most likely you should just download the pictures and scale them really high to understand what I did.)
My plan was using the image-rendering properties pixelated to get a resized images without any smoothing or color gradients and it worked fine until I used IE.
I created a little code snippet to recreate the basic idea:
.ger {
image-rendering: pixelated;
background-image: url(http://i.stack.imgur.com/tNV8n.jpg);
background-size: 1px 45px;
background-repeat: repeat;
}
.fr {
image-rendering: pixelated;
background-image: url(http://i.stack.imgur.com/ErVbV.jpg);
background-size: 120px 1px;
background-repeat: repeat;
}
#flag1, #flag2{
width: 120px;
height: 45px;
}
<body>
<div id="flag1" class="ger"></div>
<br/>
<div id="flag2" class="fr"></div>
</body>
But I guess I'm too new to this topic to be able to do it right. Because somehow it won't show the german flag to you.
Anyways... I can't ask you to make IE starting to support this function. But what I can ask is if you know some way to work arround this.
If not, do you know some way to create these simple flags just using CSS?
I was thinking of three divs of different colors beneith each other.
For example:
.black, .red, .yellow{
width:800px;
height:100px;
}
.black{
background-color:black;
}
.red{
background-color:red;
}
.yellow{
background-color:yellow;
}
<div class="black"></div>
<div class="red"></div>
<div class="yellow"></div>
... for the german flag.
But if I try to implement something similar into my dropwdown...
I fail...
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, #dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li.dropdown {
display: inline-block;
float: right;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.black, .red, .yellow{
width:60px;
height:10px;
}
.black{
background-color:black;
}
.red{
background-color:red;
}
.yellow{
background-color:yellow;
}
<ul>
<li><a class="logo">Logo</a></li>
<li class="dropdown">
<div class="black"></div><div class="red"></div><div class="yellow"></div>
<div class="dropdown-content">
Flag 1
Flag 2
Flag 3
</div>
</li>
</ul>
Because if I do it like this, it will never have the full size of the bar, will it?
I'm sorry for providing so much information, because it's propably just too much. However these were my attempts and I really have no clue what I'm missing out onto.
In the ende the bar (shown in the last snippet) should contain a flag. The flag should touch the right and upper border of the window and the bottom broder of the bar. If you hover over it a dropdown should appear with similar flags.
If I wasn't clear at some point just ask I will try to make it clearer.
The problem with the first snippet is that there were <style> tags in the CSS section of the snippet, and that was messing it up.
.ger {
image-rendering: pixelated;
background-image: url(http://i.stack.imgur.com/tNV8n.jpg);
background-size: 1px 45px;
background-repeat: repeat;
}
.fr {
image-rendering: pixelated;
background-image: url(http://i.stack.imgur.com/ErVbV.jpg);
background-size: 120px 1px;
background-repeat: repeat;
}
#flag1,
#flag2 {
width: 120px;
height: 45px;
}
<body>
<div id="flag1" class="ger"></div>
<br/>
<div id="flag2" class="fr"></div>
</body>

Container won't center

This container stubbornly refuses to center. Demo: http://codepen.io/Diego7/pen/KzXgZN
I've tried just about every centering code I can find on the web, to no avail.
Removing width: 90%; from the css aligns the container to the left, even though margin: 0 auto; is telling it to center.
Sorry if this question isn't up to StackOverflow's 'standards', but codingforums.com are down at the moment :(
Thanks heaps!
HTML
<div class="container">
<article>
<header>
<img src="https://softwarereviews.files.wordpress.com/2016/04/bg-header-no-logo.png" width="972px"><br />
<h2>Information</h2>
</header>
<p>There's currently is no information available. Sorry.</p>
<footer>
© 2016
</footer>
</article>
</div>
CSS
##import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: 'Open Sans', sans-serif;
background: #fff;
}
.container {
list-style:none;
margin:0 auto;
width:90%;
padding-top: 20px;
background: #fff;
border-radius: 6px;
box-sizing: container-box;
}
article header h2 {
color: #282828;
font-size: 1.2em;
font-weight: normal;
display:inline;
line-height: 1.3;
}
article p {
font-size: 1em;
display:inline;
line-height: 1.5em;
color: #282828;
max-width: 972px;
}
article footer {
font-size: .9em;
display:inline;
color: #999;
}
a {
color: #2790ae;
text-decoration: none;
outline: none;
}
a:hover {
color: #0f6780;
}
Your .container is already centered: if you change background to red you will see it. And, if you add text-align property its content will be centered too.
.container {
list-style:none;
margin:0 auto;
width:90%;
padding-top: 20px;
border-radius: 6px;
box-sizing: container-box;
text-align:center;
background: red;
}
If you make the width a bit narrower (like 70%), you see that it IS centered.
by the way: " list-style:none;" has no effect whatsoever, and "box-sizing: container-box;" should be "box-sizing: content-box;"
Looks like you're centering the <div class="container">, but it doesn't look like it, because you're looking at the image.
If you want the image to take up the entire <div> element (so that any centering takes effect on both), try something like the following, instead of using an <img> element:
div.container {
background-image: url(https://softwarereviews.files.wordpress.com/2016/04/bg-header-no-logo.png);
}
There are other properties you can use to fiddle with precisely how the image is displayed. You can find more info here.
If you are using container after float tag. It can create problem sometimes. So to avoiding this user <div class="clear"></div>. Also clear class properties would be:
.clear{
clear:both;
margin:0px;
padding:0px;
height:0px;
font-size:0px;
line-height:0px;
float:none;
}
Hope it will be helpful..

CSS Button has a border

I am trying to define a custom css button for my search form. I cant figure out why this particular button has a strange border around it? I need to get it removed but cannot figure out where it is coming from within the css..code and fiddle below.
/* Define Search Button */
button.button-search::-moz-focus-inner { padding:0; border:0; } /* FF Fix */
button.button-search { -webkit-border-fit:lines; } /* <- Safari & Google Chrome Fix */
button.button-search { position:absolute; right:10px; top:8px; }
button.button-search > span {
background: #3399CC; /* Old browsers */
box-shadow:1px 1px 0 #a4a4a4;
display:block;
float:none;
width:88px;
height:32px;
line-height:30px;
text-align:center;
font-size:15px;
color:#fff;
text-align:center !important;
}
button.button-search span span { padding:0; float:none; }
button.button-search:hover > span {
opacity:0.8 !important;filter:alpha(opacity=80) !important;
box-shadow:1px 1px 0 #a4a4a4;
}
.header .form-search button.button-search { }
.header .form-search button.button-search > span { }
.header .form-search button.button-search:hover > span { }
.header .form-search button.button-search span span { }
.header .form-search button.button-search:hover span {}
<div class="header">
<div class="form-search">
<button type="submit" title="<?php echo $this->__('Search') ?>" class="button-search"><span><span>Search</span></span></button>
</div>
</div>
http://jsfiddle.net/fnysccad/
Thanks
You are applying the CSS to the spans inside the button, so the default styling for the button is still being used:
Get rid of all the messy <span>, and, as #Christoph said in the comments, type="submit" can be omitted, as it is the default functionality of a button:
<div class="form-search">
<button title="<?php echo $this->__('Search') ?>" class="button-search">Search</button>
</div>
Apply the CSS to the input:
button.button-search::-moz-focus-inner { padding:0; border:0; } /* FF Fix */
button.button-search { -webkit-border-fit:lines; } /* <- Safari & Google Chrome Fix */
button.button-search { position:absolute; right:10px; top:8px; }
button.button-search {
background: #3399CC; /* Old browsers */
box-shadow:1px 1px 0 #a4a4a4;
display:block;
float:none;
width:88px;
height:32px;
line-height:30px;
text-align:center;
font-size:15px;
color:#fff;
text-align:center !important;
border:none;/*Removes the border*/
}
http://jsfiddle.net/q3t2srfg/1/
Button has border, and background by default.
Remove them, and will be good.
But i dont think its valid to add span into button.
Solution is here: (css)
button.button-search { background: transparent; border: none; position:absolute; right:10px; top:8px; }
This is happening because of default style you need to override it by define your own class for example 'change':-
<button type="submit" title="<?php echo $this->__('Search') ?>" class="button-search change"><span><span>Search</span></span></button>
button.button-search.change{
border:0;
padding:0;
}
Updated fiddle :-http://jsfiddle.net/ynwypqw2/
Looks like solutions requiring a different html structure work for you. But to answer the original question, here's the css solution for getting a button to respect your custom styles:
button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 0;
border: 0;
}
This tells Safari and Chrome (webkit), Firefox (moz), and standards-compliant browsers to not enforce their default button styles, and then makes sure there's no padding or border.
If you add the following code above your code, it will work:
button {
border: medium none;
margin: 0;
padding: 0;
}
This code reset some of the default styles in the browsers.
You need to do something like this, if i understood your question:
.button-search{border:0px;background-color:inherit;}
.button-search:focus{outline:none;}
use this .button-search{ border: 0; padding: 0; }

How Can I Vertically Center All Elements in the <Body> Tag?

Well, I’m currently working on a coming soon site. So far everything has been great, but I seem to be running into one issue. For the life of me, I can't seem to get all the content vertically centered - I’ve read many pages on the Internet, but I can’t get any working.
The HTML:
<h1>Protean</h1>
<p>Your status bar, your way.</p>
<hr>
<a class="Button" href="#">
<i class="fa fa-spin fa-refresh"></i> Coming Soon</a>
<hr style="height:8pt; visibility:hidden;" />
The CSS:
h1 {
color: #ffffff !important;
font-size: 350%;
}
p {
color: #ffffff !important;
font-size: 19px;
}
body {
background:#4fb088 !important;
text-align:center !important;
}
.Button {
background-color:#5fc79c;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:HelveticaNeue-Medium;
font-size:16.5px;
padding:15px 35px;
text-decoration:none;
}
.Button:hover {
background-color:#6cd2a8;
}
.Button:active {
position:relative;
top:1px;
}
a:hover {
text-decoration:none;
color:white;
}
brbutton {
display: block;
margin: 10px 0;
}
hr {
height:1px;
visibility:hidden;
margin-bottom:-1px;
}
I dumped the files into a fiddle, here.
If you are willing to help, that’d be appreciated.
Edit: Felipe M has helped me resolve my issue.
<div class="container">
<div class="cent"></div>
</div>
html,body
{
height: 100%;
}
body
{
display: table;
margin: 0 auto;
}
.container
{
height: 100%;
display: table-cell;
vertical-align: middle;
}
.cent
{
height: 50px;
width: 50px;
background-color: black;
}
You could try this: http://jsfiddle.net/danield770/tVuS6/14/
From here: Center a div horizontally and vertically and keep centered when resizing the parent
Change about your needs.
By the way, there isn't a way to make content centered without using some divs elements.
If you want to learn more about that, I would like to recommend you some tips:
http://www.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/
http://css-tricks.com/centering-in-the-unknown/
Good luck!