How to float div to right without mixing with the next content? - html

I do not know how to formulate my question but I will explain it easily. My div content is mixing within the next div content when using float: right and I do not know why.
I am trying to achieve something like this using html and css:
I am trying to put that span text to right, using float: right this happens:
I see it is mixing within the next div when It should be outside.
Maybe I do not know what I doing. But this is my code:
#foot {
background-image: url(https://images.pexels.com/photos/3184433/pexels-photo-3184433.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260);
background-size: cover;
}
#foot .container{
width: 90%;
}
#foot .container .upper-f
{
padding: 2em;
}
#foot .container .bottom-f .bg-container-f
{
padding: 2em;
background-color: rgba(34, 55, 109, 0.85);
}
#foot .container .bottom-f .img-container
{
text-align: center;
}
#foot .container .bottom-f .title-trajes h6
{
text-transform: initial;
line-height: 0.8em;
color: white;
font-size: 0.9em;
font-weight: 600;
}
#foot .container .semi-title-pu
{
background: rgba(206, 39, 36, 0.8);
float: right;
}
#foot .container .semi-title-pu div span
{
padding: 0.5em;
}
<footer id="foot">
<div class="container">
<div class="upper-f">
</div>
<div class="bottom-f">
<div class="semi-title-pu">
<span>Proveedor de uniformes</span>
</div>
<div class="bg-container-f">
<div class="title-trajes">
<h6>testing</h6>
</div>
<div class="img-container">
<img src="./images/uniformalogo png.png" height="24">
</div>
</div>
</div>
</div>
</footer>
How can I float or put that div to right and achieve like the first image?

I changed the position of div content. As well as I added the margin-top to the bg-container-f to decrease the gap between big-container-f and semi-title-pu . You can change it as you want.
#foot {
background-image: url(https://images.pexels.com/photos/3184433/pexels-photo-3184433.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260);
background-size: cover;
}
#foot .container{
width: 90%;
}
#foot .container .upper-f
{
padding: 2em;
}
#foot .container .bottom-f .bg-container-f
{
padding: 2em;
background-color: rgba(34, 55, 109, 0.85);
margin-top:-15px;
}
#foot .container .bottom-f .img-container
{
text-align: center;
}
#foot .container .bottom-f .title-trajes h6
{
text-transform: initial;
line-height: 0.8em;
color: white;
font-size: 0.9em;
font-weight: 600;
}
#foot .container .semi-title-pu
{
background: rgba(206, 39, 36, 0.8);
float: right;
}
#foot .container .semi-title-pu div span
{
padding: 0.5em;
}
<footer id="foot">
<div class="container">
<div class="upper-f">
<div class="semi-title-pu">
<span>Proveedor de uniformes</span>
</div>
</div>
<div class="bottom-f">
<div class="bg-container-f">
<div class="title-trajes">
<h6>testing</h6>
</div>
<div class="img-container">
<img src="./images/uniformalogo png.png" height="24">
</div>
</div>
</div>
</div>
</footer>

try this:
#foot .container .semi-title-pu
{
background: rgba(206, 39, 36, 0.8);
float: right;
line-height: 1.2em;
transform: translateY(-1.2em);
}

Better to avoid float:right.
Instead use one of these:
text-align: right; on the text element itself. For this to work the text has to be in a block element like <p> or <div>, or you have to add a display: block; to the <span> element.
Put your text element inside of a container, for example a <div> and put display: flex; on it and make sure it's as wide as your page. Then add justify-content: flex-end; to the same container css. This will justify the span within it (and anything else) to the far right on the page.
If you want to have your element float on top of another element you can put the container and text inside or a larger container with a photo background-image. Or you can keep it outside the image container and pull it up on the photo with a negative margin or add position: absolute and use top, left, right and bottom positioning to fine tune the position.
Floats are taken out of the flow context of the html document and is a bit trickier to work with, that's why you should avoid it when you have better alternatives.
Try the red element outside the footer:
<section class="image-container">
<div class="semi-title-pu">
<span>Proveedor de uniformes</span>
</div>
</section>
<footer id="foot">
<div class="container">
<div class="upper-f">
</div>
<div class="bottom-f">
<div class="bg-container-f">
</div>
</div>
</div>
</footer>
Full code: https://jsfiddle.net/ks9tLhzp/
Result:

Related

How to keep footer at the bottom of page under the body content

What I am trying to accomplish is to get the footer of all my pages underneath the content of the body. All pages will have different sizes of body content. The challenging bit for me is to keep only one CSS for all pages.
I tried my best showing the css and HTML here but no luck. Instead here is a the JSFiddle of my code: https://jsfiddle.net/zsrsd20m/
.container {
min-height:80%;
position:relative;
}
.titleText{
width:100%;
padding-top: 35px;
padding-bottom: 35px;
background-color: #127577;
color: white;
text-align: center;
}
.navBar{
padding-right: 20px;
float:left;
}
.mainText{
height:100%;
padding-left:220px;
padding-right:250px;
padding-bottom:0px;
font-size: 20px;
text-align: justify;
}
.footerText{
width:100%;
padding-top: 35px;
padding-top: 23px;
background-color: #127577;
color: white;
text-align: center;
}
.Container and all the other Divs made in HTML was made because of this: http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
I want it so that even if the body content is too small the footer always stays at the bottom of the page. Same applies for if the body content is big. Currently when setting the height of the body content to 100% it shows me a scroll bar even when the content is small and doesnt need a scroll bar. When removing the height it makes the footer directly under the small body content which is half good but its not at the bottom of the page so it looks horrible.
Screenshots of the problems:
https://imgur.com/a/x16RC
Wow - that link's old. We've got some better techniques available these days, namely flexbox.
/* The magic: */
.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.Site-content {
flex: 1;
}
/* Stlyes to make the demo easier to see: */
body { margin: 0; }
header { background-color: #FDD; }
main { background-color: #DFD; }
footer { background-color: #DDF; }
<body class="Site">
<header>Header</header>
<main class="Site-content">Content</main>
<footer>Footer</footer>
</body>
You can read all about it right here
Use sticky footer CSS https://css-tricks.com/couple-takes-sticky-footer/
<body>
<div class="content">
<div class="content-inside">
content
</div>
</div>
<footer class="footer"></footer>
</body>
html, body {
height: 100%;
margin: 0;
}
.content {
min-height: 100%;
}
.content-inside {
padding: 20px;
padding-bottom: 50px;
}
.footer {
height: 50px;
margin-top: -50px;
}
Try this.
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<p class="navbar-text pull-left">© 2014 - Site Built By Mr. M.
<a href="" >Test Link</a>
</p>
<a href="" class="navbar-btn btn-danger btn pull-right">
<span class="glyphicon glyphicon-star"></span>Copyright 2017</a>
</div>
Reference: https://bootsnipp.com/snippets/featured/easy-sticky-footer

Text in div being bumped down - how to center?

I have a series of CSS-styled boxes. Each box has a heading, followed by a number in a paragraph tag. Some of the headings are 2 lines, and in this case, the number shows up right where I want it: centered in the bottom part of the box. Where the heading is only 1 line, the number floats up higher than I'd like. How can I get the number to be in the center of the white space? What's going on here?
Code here: https://jsfiddle.net/snp3gvke/
<div class="sm red left-margin"><h2>Website<br/>Visitors</h2><p>120,363</p> </div>
Try adding vertical-align:middle; and line-height
This is the hacky solution, but you can solve your problem by adding two line breaks to your headings. That's essentially the problem - when your heading only takes one line, it doesn't push the number down as far into the white part of the div.
p {
font-weight: bold;
font-size: 2em;
text-align: center;
position:absolute;
bottom: 5%;
width: 100%;
}
I was able to do it by using flexbox. I had to make some changes to your CSS to override the colors coming from langsdale-dashboard.css file.
I went ahead and made your CSS a little bit more efficient also. I made changes only on the CSS to make things work. Here's what I did:
Applied the colors to the h2 instead of the parent container.
Removed the height from the parent containers and set the heights to the h2 and p instead.
Applied display:flex; justify-content:center; and align-items:center to both the h2 and the p.
I'm including the code below. You can also view it on JSFiddle: https://jsfiddle.net/m0nk3y/snp3gvke/11/
Let me know if you have any questions.
.lg,.med,.sm {
border-radius: 15px;
border-style: solid;
border-width: 1px;
position: relative;
}
.lg {
width: 700px;
}
.med {
width: 500px;
display: inline-block;
}
.sm {
width: 175px;
display: inline-block
}
.sm, .med, .lg {
vertical-align: top;
}
.left-margin {
margin-left: 15px;
}
.row {
margin-bottom: 10px;
}
h2,
p {
display: flex;
margin: 0;
text-align: center;
justify-content: center;
align-items: center;
}
h2 {
height: 75px;
border-radius: 12px 12px 0 0;
}
p {
height: 100px;
font-weight: bold;
font-size: 2em;
}
.blue, .red, .green, .orange {
background: transparent;
}
.blue {
border-color: #41B6E6;
}
.blue h2 {
background: #41B6E6;
}
.red {
border-color: #ce2029;
}
.red h2 {
background: #ce2029;
}
.green {
border-color: #C4D600;
}
.green h2 {
background: #C4D600;
}
.orange {
border-color: #E35205;
}
.orange h2 {
background: #E35205;
}
<link href="https://langsdale.ubalt.edu/zz-test/langsdale-dashboard.css" rel="stylesheet"/>
<body>
<div class="row">
<div class="lg blue">
<h2>Walk-in Visitors</h2>
<p>109,328</p>
</div>
</div>
<div class="row">
<div class="med red">
<h2>Special Collections<br/>Flickr Views</h2>
<p>75,985</p>
</div>
<div class="sm green left-margin">
<h2>Questions<br/>Answered</h2>
<p>19,570</p>
</div>
</div>
<div class="row">
<div class="sm blue">
<h2>Materials<br/>Circulated</h2>
<p>375,985</p>
</div>
<div class="med orange left-margin">
<h2>Instruction Session<br/>Attendees</h2>
<p>2,045</p>
</div>
</div>
<div class="row">
<div class="med green">
<h2>Database Searches</h2>
<p>330,479</p>
</div>
<div class="sm red left-margin">
<h2>Website<br/>Visitors</h2>
<p>120,363</p>
</div>
</div>
<div class="row">
<div class="lg orange">
<h2>Titles Borrowed via ILL</h2>
<p>5,773</p>
</div>
</div>
</body>

2 divs, side by side, with right-hand div taking up remainder of containing div

I have the classic two divs side-by-side problem, which usually I have no problem with (float: left both divs and add a clear:both div after them).
My requirements are making this more complicated to solve...
I would like the left-hand div to occupy, as a column, the left hand side of the containing div (the left hand div will hold a number, ie '1.')
I would like the right-hand div to occupy the remaining space to the right of the left div - and most importantly I would like it NOT to drop below the left-hand div when there is insufficient 'space' for it to fit. Instead, I would like the right-hand div to remain in position and for the text within to WRAP, staying to the right of the left-hand div. Surely this is simple!
I do NOT want to set arbitrary width values because the length of the number in the left-hand div will vary, affecting the distance between the number and the right-hand text.
Here is some example html:
<div class="popup-container"> // set to width: 300px; in css
<div class="popup-text">
<div class="float-left">
<h3>2.<.h3>
</div>
<div class="float-left">
<h3>Example text here, long enough to wrap around<.h3>
</div>
<div class="clear"></div>
</div>
</div>
And the css:
.popup-container {
width: 300px;
}
.popup-text h3 {
line-height: 1.25;
padding: 0px 8px 0px 0px;
}
.float-left {
float: left;
}
.clear {
clear: both;
}
OK, I think that's about it. If anyone knows how to have the left div operate as a column, against which the text in the right-hand div remains justified left (instead of dropping 'below' the left hand div), that would be swell.
EDIT
Thanks for all the answers. I should have mentioned (!!) it has to work in IE8. I know. But it really does. Big organisation, not updating its machines, unfortunately.
Flexbox and CSS Tables can both do that.
Support
Flexbox is IE10+
CSS Tables are IE8+
FLEXBOX
.popup-container {
width: 300px;
border:1px solid grey;
}
.popup-text {
display: flex;
}
.popup-text h3 {
line-height: 1.25;
padding: 0px 8px 0px 0px;
}
.left {
flex: 0 0 auto;
background: #c0ffee;
}
.right {
flex:1;
background: yellow;
}
<div class="popup-container">
<div class="popup-text">
<div class="left">
<h3>2.</h3>
</div>
<div class="right">
<h3>Example text here, long enough to wrap around</h3>
</div>
</div>
</div>
CSS Tables
.popup-container {
width: 300px;
border:1px solid grey;
}
.popup-text {
display: table
}
.popup-text h3 {
line-height: 1.25;
padding: 0px 8px 0px 0px;
}
.left {
background: #c0ffee;
display: table-cell;
}
.right {
background: yellow;
display: table-cell;
}
<div class="popup-container">
<div class="popup-text">
<div class="left">
<h3>2.</h3>
</div>
<div class="right">
<h3>Example text here, long enough to wrap around</h3>
</div>
</div>
</div>
Use display:flex;
.popup-container {
width: 300px;
}
.popup-container .popup-text {
display: flex;
}
.popup-text h3 {
line-height: 1.25;
padding: 0px 8px 0px 0px;
}
.float-left {
float: left;
}
.clear {
clear: both;
}
<div class="popup-container">
<!-- set to width: 300px; in css -->
<div class="popup-text">
<div class="float-left">
<h3>2.</h3>
</div>
<div class="float-left">
<h3>Example text here, long enough to scroll</h3>
</div>
<div class="clear"></div>
</div>
</div>
Here is a solution using display: flex
.popup-container {
width: 300px;
background-color: coral;
}
.popup-text {
display: flex;
}
.popup-text div.two {
flex: 1;
background-color: cornflowerblue;
}
.popup-text h3 {
line-height: 1.25;
padding: 0px 8px 0px 0px;
}
<div class="popup-container">
<!-- set to width: 300px; in css -->
<div class="popup-text">
<div class="one">
<h3>2.</h3>
</div>
<div class="two">
<h3>Example text here, long enough to scroll</h3>
</div>
</div>
</div>

Locating image and text information

Iv'e been trying to locate an image in a center of a page, and to locate two text sections in it's sides (left and right). The right text section is locating under the image and I cant locate it in the same line.
here is my HTML code:
<pre>
<html>
<head>
<link rel="stylesheet" href="EXC.css">
<script type="text/javascript" src="EXC.js"></script>
</head>
<body>
<div id="ronimg">
<img src="achivs.png"/>
<br>
<button class="button" style="vertical-align:middle"><span> GOBACK </span></button>
</div>
<div id="ronalfor">
THIS IS THE FIRST EXAMPLE
</div>
<div id="another">
THIS IS THE SECOND EXAMPLE
</div>
</body>
</html>
</pre>
This is the css code:
<pre>
#ronimg
{
margin-top: 30px;
float: right;
margin-right: 600;
clear: none;
}
#ronalfor
{
color: #43acf8;
font-style: oblique;
margin-top: 30px;
border: 5px inset #b1b53e;
float:left;
width: 500px
}
#another
{
clear: both;
color: #43acf8;
font-style: oblique;
margin-top: 30px;
border: 5px inset #b1b53e;
float:right;
width: 500px
}
</pre>
Flexbox to the rescue. I added a flexbox container around your HTML, implicitly making the children of the container into flex children. Then I use the order property to arrange the children the way you want (image in the middle with text sections flanking it).
.flex-container {
display: flex;
margin-top: 30px;
}
#ronimg img {
width: 100%;
max-width: 100%;
height: auto;
}
#ronimg {
order: 1; /* image in the middle */
}
#ronalfor,
#another {
border: 5px inset #b1b53e;
font-style: oblique;
color: #43acf8;
flex-basis: 200px; /* sets a minimum width for these elements */
}
#ronalfor {
order: 0; /* section on the left */
}
#another {
order: 2; /* section on the right */
}
<div class="flex-container">
<div id="ronimg">
<img src="http://placekitten.com/200/200" />
<br>
<a href="EXC.html">
<button class="button" style="vertical-align:middle"><span> GOBACK </span></button>
</a>
</div>
<div id="ronalfor">
THIS IS THE FIRST EXAMPLE
</div>
<div id="another">
THIS IS THE SECOND EXAMPLE
</div>
</div>
jsfiddle demo
Remove the #another { clear:both; } that makes to locate it in same line.

HTML/CSS Css box messing up margin top

So I have this CSS box:
.navigation-div
{
text-align:right;
margin-top:14px;
box-shadow:0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color:#E3E3E3;
background-color: #333;
}
With an image and a piece of text inside of it
#mailtext
{
margin-top:-10px;
display:inline-block;
font-size:20px;
color:white;
font-style:italic;
}
#mailpicture
{
display:inline-block;
margin-top:16px;
}
This is the HTML I have for it:
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Mail Us</h1>
<img id="mailpicture" src="images/gmail.png">
</nav>
</div>
Currently there is no styling for the class navigation. The Mail picture is in the correct position, but the text I want to go upwards. As you can see from the #mailtext styling I have margin-top:-10px; This does not move the text upwards.
How would I move this text upwards with or without using margin-top.
This question is like my previous question in a way, but now the text will not go to where I want it to (upwards). Using margin-left is bad, but when I did that I could move the margin top also. Since the navigation-div has a text align of right, this might be messing it up.
How would I keep the text in the same position with moving the margin top without using margin left. I would like to keep the text on the same line with the image, not above. The picture is in the right place, all i want to move is the text higher. I want the text to be parallel to the center of the image on the same line.
The previous question I have posted was about keeping all the elements on the same line, this one is about moving the margin-top.
To align the text a little higher you need to replace margin-top with position: relative and top:-10px, like in the code snippet and fiddle.
For a more efficient solution i recommend using the CSS property vertical-align. In this case if the image(size) is changed, it will still align with the text.
JSFiddle
.navigation-div {
text-align: right;
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
}
#mailtext {
position: relative;
top: -10px;
display: inline-block;
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture {
display: inline-block;
margin-top: 16px;
}
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="images/gmail.png">
</a>
</nav>
</div>
Edit:
.navigation {
margin-top:14px;
box-shadow:0px 0px 10px rgba(0, 0, 0, 0.47);
padding: 0;
color:#E3E3E3;
background-color: #333;
width: 100%;
height: 100px;
}
.container {
display: flex;
align-items: center;
justify-content: center;
float: right;
line-height: 0.5;
text-align: center;
margin-right: 20px;
}
#mailtext {
align-self: center;
font-size: 20px;
color: white;
font-style: italic;
margin-right: 15px;
}
#mailpicture {
align-self: center;
}
<nav class="navigation">
<div class="container">
<h1 id="mailtext">Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="images/gmail.png">
</a>
</div>
</nav>
JS Fiddle
There are issues with inline-block elements, especially when one is a block element and the other is an inline element. What I'd do is set parent font-size to 0 and come back to the H1 element to set the desired font-size. Then, I'd set vertical alignment to middle.
Mention: setting an id to the image element doesn't work, IMHO, without working with the link that contains it. They're both inline elements and one has to include the other, acting like a block, right?
Check the code, its a bit simplified, but you will definitely work it out.
.navigation-div {
background: #333;
color: #fff;
font-size: 0;
text-align: right;
}
#mailtext {
font-size: 20px;
margin-right: 5px;
}
.navigation a,
#mailtext {
display: inline-block;
vertical-align: middle;
}
#mailpicture {
display: block;
}
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Mail Us</h1>
<img id="mailpicture" src="images/gmail.png">
</nav>
</div>
I don't know how big your logo will be, but here is an approach that is relatively clean.
For the two inline-block elements, #mailtext and #mailpicture, set vertical-align: middle.
For #mailtext, zero-out the default margins from the h1 tag.
For #mailpicture, adjust the left and right margins as need to get horizontal white space suitable with your design. and then set the top and bottom margin accordingly.
The vertical-align property will keep the two elements centered with respect to each other.
However, if your image is such that the visual center of the image is not at the mid-height of the image, you can add position: relative to #mailtext and adjust the top or bottom offset (use one or the other).
If your image height is actually less than the height of the text, apply the position-relative adjustment to the image instead of the text.
.navigation-div {
text-align: right;
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
}
#mailtext {
display: inline-block;
vertical-align: middle;
margin: 0; /* zero out h1 margins */
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture {
display: inline-block;
margin: 10px; /*adjust as needed */
vertical-align: middle;
}
.ex2 #mailtext {
font-size: 2.5em;
margin: 10px 0;
}
.tweak #mailpicture {
position: relative;
bottom: 5px; /* use top if you want to move the image downward */
}
<div class="navigation-div">
<nav class="navigation">
<h1 id="mailtext">Large Logo - Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="http://placehold.it/100x50">
</a>
</nav>
</div>
<div class="navigation-div ex2">
<nav class="navigation">
<h1 id="mailtext">Small Logo - Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="http://placehold.it/100x10">
</a>
</nav>
</div>
<div class="navigation-div ex2 tweak">
<nav class="navigation">
<h1 id="mailtext">Position Tweak - Mail Us</h1>
<a href="mailto:info#email.com">
<img id="mailpicture" src="http://placehold.it/100x10">
</a>
</nav>
</div>