text-align footer HTML CSS - html

I got a question:
I want my text "left" to go left and my text "right" to go right and want them both on the same line.
I have added a text-align in CSS but it doesnt work. I have also added a display:inline-block so the 2 different divs can be on the same line. I also want to add a margin between the border of the website and the text. I tried width:90% in CSS but then the text is on the same line anymore.
My Problem
Here is my HMTL code
<div class="footer">
<div class="footerleft">
<p>Left1</p>
<p>Left2</p>
<p>Left3</p>
</div>
<div class="footerright">
<p>RIght1</p>
<p>RIght2</p>
<p>RIght3</p>
</div>
</div>
Here is my CSS code:
.footer {
position:absolute;
left: 0;
bottom: 0;
width: 100%;
background-color: #160a70;
color: white;
}
.footerright {
text-align: left;
display: inline-block;
}
.footerleft {
text-align: right;
display: inline-block;
}

text-align won't have any effect in your case because the parent width is the width of child content since you set display:inline-block. The text is already close to both edges.
The simpliest solution in this case is to use float and simply add padding to main container to create the space between border. Also change width:100% with right:0 to avoid overflow:
.footer {
position: absolute;
left: 0;
bottom: 0;
right:0;
background-color: #160a70;
color: white;
padding:20px; /* For spacing */
}
.footerright {
float: right;
display: inline-block;
}
.footerleft {
display: inline-block;
}
<div class="footer">
<div class="footerleft">
<p>Left1</p>
<p>Left2</p>
<p>Left3</p>
</div>
<div class="footerright">
<p>RIght1</p>
<p>RIght2</p>
<p>RIght3</p>
</div>
</div>
Or consider the use of flex which is better:
.footer {
position: absolute;
left: 0;
bottom: 0;
right:0;
padding:20px;
background-color: #160a70;
color: white;
display:flex;
}
.footerright {
text-align: right;
flex:1;
}
.footerleft {
text-align: left;
flex:1;
}
<div class="footer">
<div class="footerleft">
<p>Left1</p>
<p>Left2</p>
<p>Left3</p>
</div>
<div class="footerright">
<p>RIght1</p>
<p>RIght2</p>
<p>RIght3</p>
</div>
</div>
Or add width to your element and don't forget to clear the whitespace:
.footer {
position: absolute;
left: 0;
bottom: 0;
right:0;
padding:20px;
background-color: #160a70;
color: white;
display: inline-block;
font-size: 0;
}
.footerright {
font-size: initial;
text-align: right;
width: 50%;
display: inline-block;
}
.footerleft {
font-size: initial;
text-align: left;
width: 50%;
display: inline-block;
}
<div class="footer">
<div class="footerleft">
<p>Left1</p>
<p>Left2</p>
<p>Left3</p>
</div>
<div class="footerright">
<p>RIght1</p>
<p>RIght2</p>
<p>RIght3</p>
</div>
</div>

Related

Is there a way align text in both bottom right and left corners?

I am trying to create align text so that it sits in both the bottom right and bottom left of the page, as a footer.
e.g.
JANUARY (bottom left corner) / 2019 (bottom right corner)
Can anybody help me with the HTML code for this?
Thank you!
Please check this JSfiddle: link
I am using flexbox for alignment.
.wrapper {
height: 300px;
background: green;
display: flex;
align-items: flex-end;
justify-content: space-between;
}
<div class="circle">
</div>
<div class='wrapper'>
<span>JANUARY</span>
<span>2019</span>
</div>
Flex doesn't work on IE9 and some other browsers i'd use:
.wrapper {
height: 300px;
border: 1px solid green;
border-radius: 4px;
position:relative;
}
.wrapper span:first-child {
bottom: 0;
left:0;
position: absolute;
padding: 10px 15px;
}
.wrapper span:last-child {
bottom: 0;
right:0;
position: absolute;
padding: 10px 15px;
}
<div class='wrapper'>
<span>JANUARY</span>
<span>2019</span>
</div>
Also if this was just to go in a websites header and footer, you could just add CSS to the 2 spans.
.span_left {
position: fixed;
bottom: 0;
left: 0;
padding: 10px 15px;
}
.span_right {
position: fixed;
bottom: 0;
right: 0;
padding: 10px 15px;
}
<div class='wrapper'>
<span class="span_left">JANUARY</span>
<span class="span_right">2019</span>
</div>
I have made an example using bootstrap (https://getbootstrap.com). If you are tring to implement a sticky footer, this is a simple and clean way to achieve your request.
https://jsfiddle.net/giacomorock/e6p7cbjz/2/
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
line-height: 60px;
background-color: #f5f5f5;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col">
Test sticky footer
</div>
</div>
</div>
<div class="footer">
<div class="container">
<span class="float-left">January</span>
<span class="float-right">2019</span>
</div>
</div>
A version with position: absolute (for the older browsers).
.footer {
height: 200px;
background-color: teal;
position: relative;
}
.footer span {
position: absolute;
bottom: 5px;
}
.footer span:first-child {
left: 5px;
}
.footer span:last-child {
right: 5px;
}
.footer span:last-child a {
font-weight: 600;
color: #FFD500;
}
.footer span:last-child {
right: 5px;
}
.footer span a {
color: white;
text-decoration: none;
}
.footer span a:hover {
color: blue;
}
<div class="footer">
<span>JANUARY</span>
<span>2019</span>
</div>

Render an inline-block (with no text content) element inline with text

I have inline-block elements. These are glyphs and can contain SVG content, but don't contain text.
The problem is that these elements don't line up with text:
.example {
line-height: 32px;
margin: 12px 0;
}
.wrapper {
display: inline-block;
height: 24px;
width: 24px;
position: relative;
background-color: red;
}
.wrapper > .content {
position: absolute;
bottom: 3px;
right: 3px;
height: 12px;
width: 12px;
background-color: blue;
}
<div class=example>
<div class=wrapper>
<div class=content>
</div>
</div>
not aligned with text
<div class=wrapper>
<div class=content>
</div>
</div>
</div>
I can shift down individual elements easily enough, but it's messy and requires lots of micro tweaking.
I can't rely on the line height and icon size being identical, and the SVG inside are overlaid, which requires absolute positioning.
Is there a way to make these consistently vertically centre with text?
Specify vertical-align:bottom to wrapper class :
.example {
line-height: 24px;
margin: 12px 0;
}
.wrapper {
display: inline-block;
height: 24px;
width: 24px;
position: relative;
background-color: red;
vertical-align:bottom;
}
.wrapper > .content {
position: absolute;
bottom: 3px;
right: 3px;
height: 12px;
width: 12px;
background-color: blue;
}
<div class=example>
<div class=wrapper>
<div class=content>
</div>
</div>
aligned with text
<div class=wrapper>
<div class=content>
</div>
</div>
</div>

Unwanted spacing between html elements

It appears as if there is padding between two of my elements - content1 and footer. I do not want this 'padding' but I cannot understand why it is there at all. Here is part of problematic html text on its own - the 'padding' still appears. I've tried adding in padding: 0 and margin: 0 to both the elements with no result.
<style type="text/css">
body{
margin: 0;
}
.footer{
position: relative;
width: 100%;
min-width: 512px;
height: 150px;
background-color: black;
font-size: 12px;
font-family: arial;
color: gray;
z-index: 5;
}
.content1{
position: relative;
width: 100%;
height: 300px;
background-color: #E6E6E6;
z-index: 5;
}
.imagecontainer{
height: 80%;
float: right;
}
.image{
position: relative;
display: block;
height: 100%;
}
</style>
<body>
<div class="content1">
<!--<div class="textcontainer">
<p style="color: gray; font-size: 15px; font-family: arial;">this is some text</p>
</div>-->
<div class="imagecontainer">
<img class="image" src="C:\Users\wrigh\Pictures\SWITCH\capture01.png"></img>
</div>
</div>
<div class="footer">
<center><p style="padding-top:50px; max-width: 50%;">ONLY AVAILIBLE ON ANDROID<br><br>UPDATE: NO CURRENT WORK IS SCHEDULED</p></center>
</div>
</body>
In response to the proposed answer to this question. I have removed the image from the text and unfortunately the 'padding' was not removed.
It seems that your paragraph tag has a margin.
Apply this css rule:
.footer p {
margin: 0;
}
Here is a fiddle
You have encountered collapsing margins.
When elements have top or bottom margin, and the parent element doesn't have a border or padding, the margins collapes. The effect is that the margin is visible outside the parent element, not between the parent element boundaries and the child element.
It's the margin of the p element in the footer that is collapsing. It creates the distance between the content1 and the footer element.
By removing the margin on the p element, you get rid of the distance:
.footer p {
margin: 0;
}
Demo:
.footer p {
margin: 0;
}
body{
margin: 0;
}
.footer{
position: relative;
width: 100%;
min-width: 512px;
height: 150px;
background-color: black;
font-size: 12px;
font-family: arial;
color: gray;
z-index: 5;
}
.content1{
position: relative;
width: 100%;
height: 300px;
background-color: #E6E6E6;
z-index: 5;
}
.imagecontainer{
height: 80%;
float: right;
}
.image{
position: relative;
display: block;
height: 100%;
}
<div class="content1">
<!--<div class="textcontainer">
<p style="color: gray; font-size: 15px; font-family: arial;">this is some text</p>
</div>-->
<div class="imagecontainer">
<img class="image" src="C:\Users\wrigh\Pictures\SWITCH\capture01.png"></img>
</div>
</div>
<div class="footer">
<center><p style="padding-top:50px; max-width: 50%;">ONLY AVAILIBLE ON ANDROID<br><br>UPDATE: NO CURRENT WORK IS SCHEDULED</p></center>
</div>
if you want, you can always CSS your way through it, something like
* { margin:0; padding:0; }
It should reset All elements, after that you define new paddings and margins, which is much easier ;)
Your using a <center> tag if your using HTML5 it's not supported... if your not using HTML5 the <center> tag is a block element, add display: inline-block in the css.

how to align div's horizontally in CSS

I have three child divs inside a container and I want to align these div's horizontally. I tried using the css float property but the circles are becoming oval.
Markup Code:
<div class="container info-box clearfix">
<div class="circle">
<div class="content">
<h3>Learn at your own Pace</h3>
</div>
</div>
<div class="circle">
<div class="content">
<h3>Methodic learning</h3>
</div>
</div>
<div class="circle">
<div class="content">
<h3>Unique Approach</h3>
</div>
</div>
</div>
CSS:
.circle {
position: relative;
background-color: #3cb371;
border-radius: 50%;
padding: 5px 10px;
width: 20%;
}
.content {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
overflow: auto;
}
.circle:before {
content: '';
display: block;
margin-top: 100%; /* 1:1 ratio */
}
.clearfix:before, .clearfix:after{
content: " ";
display: table;
}
.clearfix:after{
clear: both
}
.info-box{
margin-top: 20px;
width:100%;
}
.container{
margin-left: auto;
margin-right: auto;
padding-left:15px;
padding-right:15px;
text-align:center;
}
*{
box-sizing: border-box;
}
I tried using the float property but the circles are turning into oval. Please let me know where I am going wrong.
Code on jsfiddle: jsfiddle
Circles are becoming oval because of padding property you have applied. just remove padding: 5px 10px; and add float:left; in the circle class.
.circle {
position: relative;
background-color: #3cb371;
border-radius: 50%;
float: left;
width: 20%;
}
Please use display: inline-block;
http://jsfiddle.net/K6PKK/
try this:
div.clearfix {
display : table;
}
div.circle {
display : table-cell;
}

Float a DIV toward bottom-right using CSS

I have three DIV and inside the DIV, I would like to float the "Learn More" to bottom right so it will be on top of the grey background.
CSS
/* the div for LEARN MORE */
#trt {
z-index: 9999999999999;
position: relative;
float: right;
bottom: 0; // not working
top: 12; //not working
}
/* the entire div */
.main .cols { padding-left: 2px; padding-right: 0px; padding-top: 10px; }
.main .cols .col { width: 315px; height: 108px; float: left; background: url(images/tempf.png) no-repeat 0 0; }
.main .cols .col:after { content:''; width: 100%; clear: both; }
.main .cols .col + .col { padding-left: 20px; }
.main .cols .col img.hid { float: left; width: 129px; height: 108px; }
.main .cols .col-cnt { width: 183px; float: right; }
.main .cols .col .more { font-weight: bold; color: #0206AA; }
HTML
<div class="main">
<section class="cols">
<div class="col">
<a href="link.aspx">
<img class="hid" src="css/images/orgNews.png" alt="" />
</a>
<div class="col-cnt">
<h3 style="color: #FFFFFF;">Organization News</h3>
<p style="color: #FFFFFF;">Interfaith Medical Center related news and updates</p>
<div id="trt">
<img src="css/images/arrow.png" width=11 height=11 align=absmiddle />
Learn More
</div>
</div>
</div>
</section>
</div>
CSS - After Edit
.trt {
z-index: 9999999999999;
position: absolute;
bottom: 3px;
right: 3px;
}
...
.main .cols .col-cnt { width: 183px; float: right; position: relative; }
...
This CSS worked:
.trt {
z-index: 9999999999999;
position: absolute;
top: 85px;
right: 3px;
}
set col-cnt div to position: relative set trt to position: absolute; bottom:3px; right:3px; that should get you where you need to be.. also, trt should be a class if it is being reused
First at all, you must set parent of #trt to relative.
#parent-of-trt {
position: relative;
}
And set #trt to absolute
#trt {
position: absolute;
left: 4px;
bottom: 5px;
}
Your float: right isn't working because of a width issue on the #trt div. Basically it's extending 100% of the width and so it can't technically go left or right. Instead of floating, just use...
#trt { text-align: right; }
???
As for getting it pushed down onto that grey line, add some margin-top to #trt to do that...
Other solution would be to use position: absolute; but would be less preferable.
Maybe use position: absolute; instead of relative
change position as fixed like following:
position:fixed;
it should work.