How do I conditionally align elements based on screen size? - html

I have a fairly simple header on my site:
<header>
<nav class="navbar navbar-inverse" style="">
<div class="navContainer">
<div id="navbar">
<div id="leftNavSection">
<img alt="My Logo" width="300" src="/assets/main_logo-791a416e4f99d38a339debb8dcebd7361d4172919425ace42ba2ce90336218e2.png">
</div>
<div id="rightNavSection">
Logged in as Dave A
Edit
<a rel="nofollow" data-method="delete" href="/logout">Log Out</a>
</div>
</div>
</div>
</nav>
</header>
I align the logo to the left and the Logout links to the right:
#leftNavSection {
float: left;
}
#rightNavSection {
float: right;
}
What I would like, however, is if the screen size is small (mobile browsers), for the Log Out links to appear aligned to the left beneath the logo.
However, when I change the “float:right” to “float:left” this doesn’t happen. Here is my Fiddle — https://jsfiddle.net/kje3q74k/. How do I pull this off?

So here's one way to do it:
Add min-width: 50% to the leftNavSection and rightNavSection.
This allows the rightNavSection to wrap to the second line on
smaller displays when the content widths forces it down.
Remove the default margin of body using to adjust for the 100% width of the navbar:
body {
margin: 0;
}
Now the wrapping will occur exactly below 600px!
Float the rightNavSection to the left and align it to the right using text-align: right
Below 600px use text-align: left using media query:
#media only screen and (max-width: 600px) {
#rightNavSection {
text-align: left;
}
}
snippet below:
body {
margin: 0;
}
header {
overflow: hidden;
}
#navbar {
width: 100%;
font-family: Arial;
vertical-align: top;
display: inline-block;
}
#leftNavSection {
float: left;
min-width: 50%;
}
#rightNavSection {
float: left;
min-width: 50%;
text-align: right;
}
#media only screen and (max-width: 600px) {
#rightNavSection {
text-align: left;
}
}
<header>
<nav class="navbar navbar-inverse" style="">
<div class="navContainer">
<div id="navbar">
<div id="leftNavSection">
<img alt="My Logo" width="300" src="http://placehold.it/300x300">
</div>
<div id="rightNavSection">
Logged in as Dave A
Edit
<a rel="nofollow" data-method="delete" href="/logout">Log Out</a>
</div>
</div>
</div>
</nav>
</header>
Hope you can take it forward from the above example. Let me know your feedback on this. Thanks!

Related

Change menu icon position HTML/CSS with FlexBox Grid

I have a menu icon which is displayed when window reaches certain size.
Everything is fine but the position of this icon. I don't know how to get this to the right side of the site - the most favourable would be to define the right property.
Here's what it look like now:
And I would like it to be really close to the right boundary of the window.
Here's the code:
HTML:
<div class="header">
<div class="row">
<div class="col-sm-offset-1">
<img src="images/logo.svg">
</div>
<div class="col-xs-offset-1">
<div class="iconcont">
<a href="javascript:void(0);" class="icon" onclick="header()" >
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</a>
</div>
<div class="menu" id="mainmenu">
Home
News
Members
History
Projects
</div>
</div>
</div>
</div>
CSS:
/* HEADER */
.header {
background-image: url("images/stars.png");
width: 100%;
height: 150px;
}
header img {
height: 100%;
width: 100%;
}
/* MENU */
.menu {
background-color: transparent;
overflow: hidden;
}
.icon {
display: none;
}
#media screen and (max-width: 1370px) {
.menu a {
display: none;
}
.icon {
display: block;
}
}
.iconcont {
top: 55px;
position: relative;
}
I tried to wrap it in div (iconcont) but the right or left property doesn't work as I want. I guess it's because the whole menu is "col-xs-offset-1" (Flexbox Grid) but I don't know how to fix this and not ruin everything else.
EDIT:
For anyonewondering I fixed it. I put the icon in another div col-offset-5 but AFTER menu. I don't know why I hadn't done it in the first place.
Maybe add an ID to the class you want special treatment for and then make an exception with that?
HTML
<div class="col-xs-offset-1" id="header-layout">
<div class="iconcont">
<a href="javascript:void(0);" class="icon" onclick="header()" >
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</a>
</div>
<div class="menu" id="mainmenu">
Home
News
Members
History
Projects
</div>
</div>
CSS
#media screen and (max-width: 1370px) {
#header-layout
{ display: flex;
align-items: flex-end;
}
}

Contain navbar links to content container when resizing window

I have a bootstrap navbar that I need to span the entire width of the screen, but have the logo and link at the right stay the consistent width of the container below it, as illustrated below, and not have the LINK on the right jump to the logo and logo shoved to the left below 768px when shrunk down:
[=============LOGO------------------------------------------LINK=============]
| |
| |
| |
When the user downsizes the screen, the navigation items should remain inline with the content below.
<nav class="navbar navbar-default">
<ul class="nav nav-justified centered">
<li><img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width="140" height="40">
</li>
<li><a class="getapp" href="#">LINK</a>
</li>
</ul>
</nav>
<div class="container">
CONTENT
</div>
.navbar {
background-color: #000;
}
.centered {
width:100%;
margin:0 auto;
}
.nav>li{
display:table-cell;
}
JSFIDDLE: LINK
I found a simple solution by setting the outer div of the nav and the content container to use .inside which contains the nav and content to the same width. When the window is resized, the navigation and page content grow and shrink at the same rate.
<nav>
<div class="inside">
<div class="logo">
<img src="logo.png">
</div>
<div class="links">
<img src="image.png">
</div>
</div>
nav{
position: fixed;
top: 0;
height: 70px;
width: 100%;
background: #000;
z-index: 99999;
}
.logo{
float: left;
padding-top: 15px;
}
.links{
float: right;
line-height: 50px;
padding-top: 20px;
padding-right: 15px;
}
.inside{
width: 90%;
margin: 0 auto;
}

How to center content in footer

I am building a website using wordpress theme. I have two elements (one floated left, second floated right) in the footer. I need to make it centered (the second one below the first one) when I resize the browser window. I tried giving the <p> and <div> tag a class and then style it to float:none; - hovewer you cann check that It didn't really work on the webpage. I also attach a picture of how I want it to be..
WEBPAGE
<div class="site-info">
<div style="margin:0 auto; width: 75%;">
<p style="float:left;">© Copyright <?= date('Y'); ?> Hotel Švýcarský Dům</p>
<div style="float:right;">Naleznete nás na sociálních sítích:
<a style="display: block; float:right; margin:-4px 0 0 5px;" href=""><img src="/wp-content/themes/adamos/images/gplus.png" /></a>
<a style="display: block; float:right; margin:-4px 5px 0 5px;" href=""><img src="/wp-content/themes/adamos/images/facebook.png" /></a>
</div>
<div class="clear"></div>
</div>
</div><!-- .site-info -->
Here is updated code. with a screen less than 600px, the divs will go on top of each other. This probably will need tweaking to fit on your site.
#left {
float: left;
}
#right {
float: right;
}
#center {
text-align: center;
}
#container {
margin-left: 12.5%;
margin-right: 12.5%;
}
.imagefloat {
display: block;
float: right;
margin: -4px 5px 0 5px;
}
#media (max-width: 600px) {
.nofloat {
width: 100%!important;
text-align: center;
float: none!important;
}
.imagefloat {
float: none!important;
}
}
<div class="site-info">
<div id="container">
<div id="left" class="nofloat">© Copyright
<?=d ate( 'Y'); ?>Hotel Švýcarský Dům</div>
<div id="right" class="nofloat">
<a class="imagefloat" href="">
<img src="/wp-content/themes/adamos/images/gplus.png" />
</a>
<a class="imagefloat" href="">
<img src="/wp-content/themes/adamos/images/facebook.png" />
</a>
</div>
<div id="center">Naleznete nás na sociálních sítích:</div>
<div class="clear"></div>
</div>
</div>
Perhaps add align-text:center to one of the divs and a p tag to put the images on a new line
<div class="site-info">
<div style="text-align:center; width: 75%;">
<p >© Copyright <?= date('Y'); ?> Hotel Švýcarský Dům</p>
<div >Naleznete nás na sociálních sítích:
<p><img src="/wp-content/themes/adamos/images/gplus.png" />
<img src="/wp-content/themes/adamos/images/facebook.png" />
</div>
<div class="clear"></div>
</div>
</div>
Firstly, you kept your float:left and float:right as inline styling so you will need to move the left and right float to an external css as you can't override inline styling with just css.
Secondly, Add a separate class for the left and right, say class="float-left" and class="float-right" and then use media query to switch properties for the classes like this:
#media (max-width: 768px) {
.float-left {
float: none;
}
.float-right {
float: none;
}
}
#media (min-width: 769px) {
.float-left {
float: left;
}
.float-right {
float: right;
}
}
Thirdly, to center the footer text on smaller screens, just add text-align: center to the above media query like this:
#media (max-width: 768px) {
.site-info {
text-align: center;
}
.float-left {
float: none;
}
.float-right {
float: none;
}
}
Lastly, add the icons and text within a <p></p> tag so they will line-break accordingly.

adding a sidebar to a single centered column

My layout has a single column on the homepage that's centred in the middle of the page. The .posts class is contained in the .home class, which is contained in a .wrap class that has a max width of 800px. I wish to add a second narrow column or a side bar, for example of 120px, called the .sidebar class. If I set the .home class to have a maximum width of 600px and set the sidebar class to have a width of 120, it's still getting pushed to the bottom of the page, not next to the .home class.
Here's a demo on jsfiddle with the html and css from jekyll included http://jsfiddle.net/mjmitche/V4F6H/
How can I get the sidebar column next to the .home class?
HTML
<div class="wrap">
<a class="site-title" href="#">My Jekyll Blog</a>
<nav class="site-nav">
<div class="trigger">
<a class="page-link" href="http:google.com">blah blah</a>
</div>
</nav>
</div>
</header>
<div class="page-content">
<div class="wrap">
<div class="home">
<ul class="posts">
<li>
<a class="post-link" href="#">This is a link to my post</a>
<p></p>
</li>
</ul>
</div>
<div class="side-bar">
</div>
</div>
</div>
key CSS
.wrap:before,
.wrap:after { content:""; display:table; }
.wrap:after { clear: both; }
.wrap {
max-width: 800px;
padding: 0 30px;
margin: 0 auto;
zoom: 1;
}
.page-content {
padding: 30px 0;
background-color: #fff;
}
.home h1 { margin-bottom: 25px;
}
.home { max-width: 600px};
.sidebar{ width: 100px;}
Float the .home div to the left and the .sidebar to the right.
Unfortunately, your JSfiddle does not seem to have the full HTML and there is way too much CSS for a reduced case so I cannot make a demo.

How can I make images stack on top of each other as web page scales down?

Basically there are two images that are supposed to be on the center of the page and when the page is made smaller those images need to stack vertically. Currently I can get them to scale vertically, but I don't know how to center them. If I use margins or padding they stay in their position when the page is shrunk and don't look very good. I need them to move towards the edge as the page is being shrunk and then stack once the width of the page is too small. I'm doing this so they display properly on mobile and smaller resolutions. Does anyone know the best way to do this?
Here is the html:
<body>
<div class="wrapper">
<div class="wordmark">
<a href="#">
<img src="........." />
</a>
</div>
</div>
<div class="logowrap">
<div class="row">
<ul class="thumbnails">
<div class="logo1">
<li class="span6 home-left">
<a href="#">
<img src="SDI-logo.png" alt="SDI-logo" />
</a>
</li>
</div>
<div class="logo2">
<li class="span6 home-right">
<a href="#">
<img src="Debate-Logo.png" alt="SDI-logo" />
</a>
</li>
</div>
</ul>
</div>
</div>
</body>
Here is the CSS:
.navbar {
background-color:#000;
}
.container{
background-color:transparent;
}
.wrapper {
background-color:#000;
}
.wordmark{
max-width:100%;
max-height:100%;
padding-left:15px;
}
.logo1{
float:left;
.logo2 {
float:inherit;
}
.logowrap{
}
I have changed your code a bit. Take a look here and see if that helps you (http://jsbin.com/UdODawI/1/)
.thumbnails {
width: 100%;
margin: 0 auto;
list-style-type: none;
}
.wrapper {
background-color:#000;
}
.logowrap {
margin: 0 auto;
text-align: center;
}
.logo1{
display: inline-block;
}
.logo2 {
display: inline-block;
}
try adding this css to your image
.thumbnails img {
max-width:100%;
height: auto;
}
this allows your images to resize according to its parent