What I want
I am trying to create a navigation bar for a mobile site. I want a dark blue navigation div to house a menu button and a search form.
What I get
My wrapper div just appears as a thin dark blue line and the navigation divs within just exist outside of the wrapper.
The code
<div id="mobileNavBar">
<div style="float:left;width:20%">
<span class="menu-trigger"><i class="fas fa-bars menuFA fa-2x"></i>
</span>
</div>
<div style="float:right;width:80%">
<?php get_search_form(); ?>
</div>
<div style="clear:both"></div>
</div>
Here is CSS for the navigation div
#mobileNavBar{
background-color: #4d94ff;
border:1px solid #4d94ff;
height:auto;
}
The image
Below is an image of my mobile site, ignore the large black boxes, that's just me hiding content. There's actually a logo there and written content.
As you can see, my navigation div is a thin darker blue line and the navigation contents are underneath.
What I tried
Well after looking at similar questions on this website, I was led to believe that the issue is that my elements are floating and therefore I need to add:
<div style="clear:both"></div>
However this doesn't seem to have an impact.
How, could I get the navigation div to wrap itself around the image for the menu and the search bar? Or rather, how do I get a div to wrap around floating divs?
There is a CSS hack for clearing all your internal floats.
Add class "clearfix" to your div:
<div id="mobileNavBar" class="clearfix">
<div style="float:left;width:20%">
<span class="menu-trigger"><i class="fas fa-bars menuFA fa-2x"></i>
</span>
</div>
<div style="float:right;width:80%">
<?php get_search_form(); ?>
</div>
<div style="clear:both"></div>
</div>
CSS code:
.clearfix {
overflow: auto;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
So, this will clear all the floats inside an existing div.
You could have created style with your div id 'mobileNavBar' as well but it is better to create a reusable class.
Please check https://www.w3schools.com/howto/howto_css_clearfix.asp for more clarity.
Floats can be tricky. Can you use flexbox?
display:flex will make this simpler :)
css:
#mobileNavBar {
background-color: #4d94ff;
border: 1px solid #4d94ff;
display: flex;
}
html:
<div id="mobileNavBar">
<div style="width:20%;">
<span class="menu-trigger"><i class="fas fa-bars menuFA fa-2x">first div</i></span>
</div>
<div style="width:80%">
second div
</div>
</div>
* markup for outline and padding not shown
Apply following class to floated elements parent.
.clear:after{
content: ' ';
display: table;
clear: both
}
Or you can add extra element in HTML
<div>
<div style="float: left;">Sidebar</div>
<div style="float: right;">Content</div>
<div style="clear: both;"></div><!-- Clear the float -->
</div>
above solution solve your problem but my opinion is you can use flex to grid for this kind of layout.
Related
My HTML:
<div class="container">
<div class="buttons-and-divs">
<button>Accordion Top</button>
<div>Are you</div>
<button>Accordion Middle</button>
<div>up for</div>
<button>Accordion Bottom</button>
<div>the challenge?</div>
</div><!--end buttons-and-divs-->
<div class="div-chatbox">
<div>Chatbox</div>
<div>
<input type="text" name="">
</div>
<div>
<button></button>
<button></button>
</div>
</div><!--end chatbox-->
</div><!--end container-->
My CSS:
div.buttons-and-divs button {
display: block;
width: 300px;
height: 50px;
}
.div-chatbox {
float: right;
}
I have set the display:block for the buttons because I want them to stack ontop of each other. The image of my problem is here: View in Browser
I do not want my div of class(chatbox) to be pushed out of the div(container). How do I fix this issue? To view the HTML and CSS in my github: https://github.com/psychicspies/AccordianChallenge/tree/master/accordianchallenge
Setting display block will cause them to clear.
There's a number of things you could do.
Quickest fix, try "inline-block",
but you'll still be left with a difficult to manage layout and cross browser will warrant extra attention.
But consider:
css flex
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
css grid
https://css-tricks.com/snippets/css/complete-guide-grid/
I have some images in the footer, wrapped in tags. For some reason they are not working whatsoever... I am totally lost.
website is HERE
any help would be great (footer is on every single page on the site)
relevant html:
<div class="socialLinks">
<div class="footerTitle">Follow Us At</div>
<div class="iconsContainer">
<a href="https://www.facebook.com/NewWaveAcademyMMA/">
<img class="socialicon" src="../images/fb.svg">
</a>
<a href="https://twitter.com/NewWaveMMA?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor">
<img class="socialicon" src="../images/twit.svg">
</a>
<a href="https://www.instagram.com/newwaveacademymma/">
<img class="socialicon" src="../images/insta.svg"></a>
</div>
</div>
Your .footercopyright div is overlapping the rest of your footer.
Since you're using floats to align the .affiliations and .sociallinks divs, you should wrap them in a clearfix. This will clear your floats and prevent your copyright div from expanding to fill the space.
<div class="footerbox">
<div class="clearfix">
<div class="affiliations"></div>
<div class="socialLinks"></div>
</div>
<div class="footercopyright"></div>
<div>
.clearfix:after {
content: "";
display: table;
clear: both;
}
The links on your webpage are working. You are unable to click on the links because you have placed a div over your links. Actually, you are clicking this div, not the links. This is the div (look it up in the browser console):
<div class="footercopyright">Copyright, All Rights Reserved NWA 2018</div>
You may resolve this by either removing this div, or by setting a higher z-index for the links container.
you can add clear in below class and work.
Also, noticed small dotted below links::
You use display:inline-block; on <a> to remove this
`.footercopyright {
position: relative;
color: #232528;
max-width: 100%;
font-size: 10pt;
text-align: center;
padding: 5px 0px;
clear: both;
}`
I use Bootstrap 3.3.7 and I wonder how to display:
Header element h1 aligned to the left of the page-header
button element aligned to the right of the page-header
Both elements being on the same baseline
Current code is pasted below and the working example is on JSFiddle. My question is similar to this question, but proposed solution does not work for me.
<body>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="page-header">
<div class="pull-left">
<h1>Hello World <small>Home Page</small></h1>
</div>
<div class="pull-right">
<button class="btn btn-primary">Submit</button>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</body>
Your problem is with the CSS, not the markup
The fiddle you provided works as expected, the reason why the elements don't seem to align properly is because bootstrap sets a default margin on h1 elements while it doesn't do so with buttons.
The easiest way to fix this is to add
h1 {
margin: 0;
}
To your site's CSS.
Alternatively for similar output in a "bootstrappy" way, you can look into bootstrap navbars and branded bootstrap navbars.
Remove top margin from header element:
.page-header h1 {
margin-top: 0;
}
I have a bootstrap row containing a header tag and a link tag. They are aligned on the same row when the screen width is less than 768 pixels. When the container width is 768 or greater the link element shifts a few pixels higher.
Here is an example that demonstrates this behaviour: https://jsfiddle.net/bz3399x8/
<div class="row">
<div class="col-sm-12">
<a class="btn btn-primary" href="#" style="width: 80px; float: right;">
<i class="icon-plus">
Add
</i>
</a>
<h1>
Hello World
</h1>
</div>
</div>
Here are screenshots demonstrating this behaviour.
There are two issues:
what is causing this?
how to i fix this?
your syntax according to Bootstrap Docs is wrong,
it needs the .container to wrap .row
and
h1 and a button elements needs to be wrapped in Bootstrap columns.
So, you can use .col-sm-10 + .col-sm-2 in this case.
Added .col-xs for demo
.row {
/* demo*/
background:red
}
.btn {
margin-top:20px /* choose as it fit you better */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-10 col-sm-10">
<h1>
Hello World
</h1>
</div>
<div class="col-xs-2 col-sm-2">
<a class="btn btn-primary" href="#">
<i class="icon-plus">
Add
</i>
</a>
</div>
</div>
</div>
While wrapping elements in different column will help answer your problem. If you are looking at wrapping both elements inside single column you need to specify elements to be inline. Problem is occurring since h1 element and a element even though in same row for bootstrap but are displayed as block and inline-block.
Add display: inline-block to h1 element with top padding to a element. This should answer it as well.
Try it with display: inline on h1 see the difference in behavior. inline element dont support vertical margins.
Fiddle: https://jsfiddle.net/dk_dragonknight/m8ey6mba/
How can I right align a button inside a div without wiping it from the Markup Flow with valid CSS and HTML? Is applying margin-leftthe only way to do this?
I have a structure like this
<div class="navContainer">
<div class="title">
<span>Nav Titulo</span>
</div>
<div class="navContent">
Nav Conteudo
</div>
<button type="button">Enviar</button>
</div>
<div class="navContainer">
<div class="title">
<span>Nav Titulo</span>
</div>
<div class="navContent">
Nav Conteudo
</div>
</div>
If I apply button { float: right } or button { position: absolute } the next div will get over the button. It happens that I just want to make the button position at the right side
what you want to read up on is clearing
if you have floated elements, they go out of page flow, but any element with clear:both will stay in page flow, but not allow anything on either side of it, floated or not.
in practice, adding a clear:both element after you floats makes things work the way you want them to.
.navContainer { text-align: right; }
#Matt is right. What you need to do is clear the div elements.
.navContainer {clear: both}
If you want your button aligned at the top of the containing div, you might have to move it before your div element of class "title".