I am currently working on a school assignment where we can only use HTML + CSS (and PHP to include repeated elements, navbar + footer in this case).
For the footer I would like to place 3 elements in the 'Left' - 'Center' - 'Right' part of the footer.
Left: A newsletter bar to enter e-mail with a SIGN UP button
Center: 3 line text - Address, contact, opening hours.
Right: 2 icons - 1 for school and 1 for business'.
This is my code:
HTML:
<footer>
<div class="footer">
<p class="left">Sign up botton here</p>
<p class="right">School - business here</p>
<p class="centered">3 lines with address, contact info, and opening hours.</p>
</div>
CSS:
.left{
text-align:left;
float:left;
}
.right{
float:right;
text-align:right;
}
.centered{
text-align:center;
}
.footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#052D48;
}
.footer p {
color: #fff;
font-size: 8px;
}
How would I go about this? I've been reading and trying stuff for hours, but I just get more confused.
i.imgur.com/6IFJnxF.png Here is a picture of what I have in mind
Hope someone can help me in the right direction, thanks a lot!
Using flexbox and wrapping everything inside a container and a row with a 100% width. Then divide each block by X percentage. I changed the p tags with an unordered list.
.row{
width: 100%;
display: flex;
flex-wrap: wrap;
}
.left{
width: 33%;
height: 40px;
}
.right{
width: 33%
}
.right ul{
list-style: none;
color: white;
}
.middle{
width: 33%
}
.centered{text-align:center;}
.flex{
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.flex-column{
display: flex;
flex-direction: column;
}
.footer {
padding: 20px 10px;
background:#052D48;
}
.footer p{
font-size: 1.3em;
color: #ffffff;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<footer>
<div class="footer">
<div class="row">
<div class="left flex">
<input type="text" class="" placeholder="Email">
<input type="submit" class="" value="Submit">
</div>
<div class="right centered ">
<ul class="flex-column">
<li><i class="fa fa-map-marker" aria-hidden="true"></i> Address.</li>
<li><i class="fa fa-phone" aria-hidden="true"></i> Contact Info</li>
<li><i class="fa fa-clock-o" aria-hidden="true"></i> Opening Hours.</li>
</ul>
</div>
<div class="middle centered">
<p class="">School - business here</p>
</div>
</div>
</div>
</footer>
I would recommend taking the class off of footer and just use the footer tag to target the parent container. Then I would use div tags for each section instead of p tags, putting p tags inside the div. And my last recommendation, although your professor will think you're cheating, is to use flexbox. Enjoy.
Also the box-sizing: border-box; is for the padding I added to the footer so it will still be width: 100%; instead of 100% + 40px
* {
box-sizing: border-box;
}
.left {}
.centered {}
.centered p {}
.right {}
footer {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background: #052D48;
}
footer p {
margin: 0;
color: green;
font-size: 8px;
}
<footer>
<div class="left">
<p>Sign up botton here</p>
</div>
<div class="centered">
<p>1 line</p>
<p>2 line</p>
<p>3 line</p>
</div>
<div class="right">
<p>School - business here</p>
</div>
</footer>
here is one idea.
https://jsfiddle.net/gztLhdk4/2/
you can customize it more based on your needs.
<footer>
<div class="footer">
<div class="left padd">
<p>
Sign up botton here
</p>
<p>
<input type="text"> <button>sign up </button>
</p>
</div>
<div class="centered padd">
<p>
rttertertert<br>
gereryrt ytyt<br>
tryryrytru
</p>
</div>
<div class="right padd">
<div>
school
</div>
<div>
business
</div>
</div>
</div>
</footer>
.left{
text-align:left;
float:left;
}
.right{
float:right;
text-align:right;
}
.centered{
text-align:center;width:50%;float:left;
}
.footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#052D48;
}
.footer p {
color: #fff;
font-size: 8px;
}
.padd{padding:5px;color:#fff;}
Related
I am attempting to have our opening days aligned to the left and our hours aligned to the right but sit in the center of our navigation bar. I am using squarespace. Currently I have it like this but not sufficiently close and on the mobile version it looks silly, any help would be appreciated thanks.
HTML Code Block:
<center>
<div class="contactfield">
<div class="contact">
<div class="date">Mon-Wed</div><div class="time">5PM - 11PM</div>
<div class="date">Thu</div><div class="time">12PM - 11PM</div>
<div class="date">Fri-Sat</div><div class="time">12PM - 1AM</div>
<div class="date">Sun</div><div class="time">12PM - 11PM</div>
</div></center>
<center> <span><img class=“sm_icons“ src="https://static1.squarespace.com/static/615e86638bf80f2683975e8f/t/630ff2cac2a9b76708e4df5d/1661989587824/phone.png" width= 12px ></span> 03 8591 3000
<div class="smaller">hello#trinitystkilda.com</div>
</center>
CSS:
p.smaller {
line-height: 0px;
}
p.smaller{
margin-top:-25px;
}
.navbar{
text-align:center;
.header-nav-list{
width: 100%;
max-width:800px;
margin:0 auto;
justify-content:space-evenly;
}
}
p.contact {
line-height: 0px;
}
p.contact{
margin-top:0px;
}
.contact .date{
font-size: 14px;
width:30%;
display:inline-block;
box-sizing:border-box;
text-align:left;
}
.contact .time{
font-size: 14px;
text-align:right;
padding-right:10px;
width:70%;
display:inline-block;
box-sizing:border-box;
}
p.email {
line-height: 0px;
}
p.email{
margin-top:5px;
color: white;
}
Images:
Mobile
Web
Just give your date & time class with some wrapper (Heres I gave wrapper with class name .date-time), and use flex to make the child center.
.contact {
display: flex;
flex-direction: column;;
}
.date-time {
display: flex;
justify-content: space-around;
}
.date, .time {
width: 50%;
text-align: center;
}
<div class="contact">
<div class="date-time">
<div class="date">Mon-Wed</div>
<div class="time">5PM - 11PM</div>
</div>
<div class="date-time">
<div class="date">Thu</div>
<div class="time">12PM - 11PM</div>
</div>
<div class="date-time">
<div class="date">Fri-Sat</div>
<div class="time">12PM - 1AM</div>
</div>
<div class="date-time">
<div class="date">Sun</div>
<div class="time">12PM - 11PM</div>
</div>
</div>
Using the 98.css library: https://jdan.github.io/98.css/
I'm currently trying to fit the bottom element status-bar at the bottom of the box with its width set to stretch to the entire box's width. I feel like I'm doing it incorrectly and/or not doing it properly via percentages in .width-stretch.
The result is this:
Note that it is somehow overlapping the bottom-right edge of the box. When I try making the width: 99%, it gets pretty close to what I want but not quite, and it is left-aligned (and not centered). I'm trying to figure out a more elegant solution that fixes this issue; any suggestions? I'm also open to any CSS frameworks that can run alongside 98.css to make styling easier. Thanks!
...
<style>
html, body {
margin:0px;
background: #c0c0c0;
}
.center {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top:0px;
right:0px;
bottom:0px;
left:0px;
}
.relative-position {
position: relative;
width: auto;
}
.bottom {
position: absolute;
bottom: 0;
padding-bottom: 4px;
}
.width-stretch {
width: 100%;
}
</style>
</head>
<body>
<!-- MAIN -->
<div class="center">
<div class="window relative-position" style="width: 95%; height: 95vh;">
<div class="title-bar">
<div class="title-bar-text">A Window With A Status Bar</div>
</div>
<div class="window-body">
<p> There are just so many possibilities:</p>
<ul>
<li>A Task Manager</li>
<li>A Notepad</li>
<li>Or even a File Explorer!</li>
</ul>
</div>
<div class="status-bar bottom width-stretch">
<p class="status-bar-field">Press F1 for help</p>
<p class="status-bar-field">Slide 1</p>
<p class="status-bar-field">CPU Usage: 14%</p>
</div>
</div>
</div>
</body>
</html>
You can use flex-direction:column on .window, with flex:1 on the .window-body so that it fills all the available vertical space.
html,
body {
margin: 0px;
background: #c0c0c0;
}
.center {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
.window {
display: flex;
flex-direction: column;
}
.window-body {
flex: 1;
}
<link rel="stylesheet" href="https://unpkg.com/98.css">
<div class="center">
<div class="window " style="width: 95%; height: 95vh;">
<div class="title-bar">
<div class="title-bar-text">A Window With A Status Bar</div>
</div>
<div class="window-body">
<p> There are just so many possibilities:</p>
<ul>
<li>A Task Manager</li>
<li>A Notepad</li>
<li>Or even a File Explorer!</li>
</ul>
</div>
<div class="status-bar">
<p class="status-bar-field">Press F1 for help</p>
<p class="status-bar-field">Slide 1</p>
<p class="status-bar-field">CPU Usage: 14%</p>
</div>
</div>
</div>
Add these styles to the inside of the style tag.
.status-bar {
display: flex;
}
.status-bar-field {
flex: 1;
padding: 0 10px;
border: 1px solid black;
}
How do I make navbar fixed/sticky? position: fixed, sticky not working.
Html
<body>
<header>
<div class="header">
<div>
<img id="fc-logo" src="https://pwa-cdn.freecharge.in/pwa-static/pwa/images/header/fc-logo.svg" alt="freecharge logo" height="70" width="200">
</div>
<div>
<i class="login-icon fa fa-user-circle fa-3x" aria-hidden="true"></i>
</div>
<div>
<p id="login">Login/Register</p>
</div>
</div>
</header>
css
.header{
position:sticky;
top: 0;
align-items: center;
}
.header{
position:fixed;
top: 0;
width:"100%";
min-height:"8vh";
}
Before you check for other issues, it might be a good idea to ensure that you're using a browser that supports position: sticky.
I am suggesting you top as extra parameter because
a sticky element requires a threshold to be specified, which means that you must set a value other than "auto" for at least one of the following properties:
top
or
right
or
bottom
or
left
For more details visit Here
.navbar {
position : sticky;
top : 0;
background-color: #32839c;
}
Try this code! change flex-direction: row and remove child padding if you want a horizontal item menu. Thanks :)
*,*::before,*::after{
box-sizing: border-box;
}
body{
height: 100vh;
}
.header {
background: grey;
position: fixed;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
top: 0;
width: 100%;
height: auto;
overflow-x: hidden;
}
.header>div:first-child {
padding-top: 20px;
}
.header>div:last-child {
padding-bottom: 20px;
}
<body>
<header>
<div class="header">
<div>
<img id="fc-logo" src="https://pwa-cdn.freecharge.in/pwa-static/pwa/images/header/fc-logo.svg" alt="freecharge logo" height="70" width="200">
</div>
<div>
<i class="login-icon fa fa-user-circle fa-3x" aria-hidden="true"></i>
</div>
<div>
<p id="login">Login/Register</p>
</div>
</div>
</header>
</body>
ImageI would like to display the page in two columns below the heading and center align the buttons the way it is.
I do not understand if I have missed any divs here?
I have been trying to do it but its not showing up the way i expected.
<div>
<div class="slds-p-top--x-large slds-text-align--center slds-p-bottom_small" width="100%">
<span>Help us improve Customer Support</span>
</div>
<table>
<tr>
<td width="50%" class="divText slds-p-bottom--medium leftBtn" >Tell us what you think<br/>
<div class="slds-text-align--center slds-p-top--small slds-p-bottom--large slds-p-top--medium">
<button class="slds-button slds-button--neutral">
<span class="btn-feedback">Provide feedback</span>
</button>
</div>
</td>
<td width="50%" class="vertical-liness divText slds-p-bottom--medium rightBtn" >Collaborate with our team<br/>
<div class="slds-text-align--center slds-p-top--small slds-p-bottom--large slds-p-top--medium">
<button class="slds-button slds-button--neutral">
<span class="btn-feedback">Get Involved</span>
</button>
</div>
</td>
</tr>
</table>
</div>
.THIS .vertical-liness
{
border-left: 2px solid red;
}
.THIS .leftBtn{
padding-left:115px;
float:right;
}
.THIS .rightBtn{
padding-left:175px;
}
.THIS {
background-color: #f4f7f7; /* ibm-cool-white-3; */
border-top: 1px solid #d0dada; /* ibm-gray-10 */
font-size: 20px;
font-weight: normal;
color: #272727; /* ibm-gray-90 */
}
.THIS .divText{
font-size: 16px;
color: #272727; /* ibm-gray-90 */
}
I simplified your markup to show an example. You can create a couple of flex parents and use their centering properties to recreate this.
.flex {
display: flex;
justify-content: center;
align-items: center;
}
.col {
flex-direction: column;
}
.button {
padding: 0 3em;
text-align: center;
}
.button1 {
border-right: 1px solid #ccc;
}
header {
margin: 0 0 .5em;
}
<div class="flex col">
<header>
Help us improve Customer Support
</header>
<div class="buttons flex">
<div class="button button1">
<div>
Tell us what you think
</div>
<button>Provide feedback</button>
</div>
<div class="button button2">
<div>
Tell us what you think
</div>
<button>Provide feedback</button>
</div>
</div>
</div>
You need to create two divs in your body and place the content inside each of them.
body {
width: 500px;
height: 500px;
}
.left, .right {
float: left;
width: 50%;
height: 100%;
}
.left {
background-color: red;
}
.right {
background-color: blue;
}
<div class="left">
<p>Left column</p>
</div>
<div class="right">
<p>Right column</p>
</div>
https://codepen.io/anon/pen/QgLKzQ
float: left; with width: 50%; is the key here.
Be careful that you need either content inside your div like the below example, either give them an height (eg. CSS: .left-float { height: 500px; }
Be careful either that floating elements will break the flow.
You will need to clear float with the next elements:
https://css-tricks.com/almanac/properties/c/clear/
CSS :
.left-float {
width:50%;
float:left;
}
HTML :
<div>
<div class="left-float" style="background-color:green;">
left div
</div>
<div class="left-float" style="background-color:red;">
right div
</div>
</div>
So, with your code... Ugh, put me off this <table> element please !
They are designed to display tabular data and not to provide a way of positioning elements. In your case you do not display tabular data.
An example of how it could be :
https://jsfiddle.net/12fd30bf/
HTML:
<div>
<div class="slds-p-top--x-large slds-text-align--center slds-p-bottom_small" width="100%">
<span>Help us improve Customer Support</span>
</div>
<div class="left-float">
Tell us what you think<br/>
<div class="slds-text-align--center slds-p-top--small slds-p-bottom--large slds-p-top--medium">
<button class="slds-button slds-button--neutral">
<span class="btn-feedback">Provide feedback</span>
</button>
</div>
</div>
<div class="left-float">
Collaborate with our team<br/>
<div class="slds-text-align--center slds-p-top--small slds-p-bottom--large slds-p-top--medium">
<button class="slds-button slds-button--neutral">
<span class="btn-feedback">Get Involved</span>
</button>
</div>
</div>
</div>
CSS :
.left-float {
width:50%;
float:left;
}
I am trying to make a business card
with name and title in the center and email and phone to be on extreme left and right on the card
Here is my following code
.business-card{
position:relative;
border:1px solid black;
width:200px;
}
.business-card section {
display:flex;
flex-flow:column;
align-items:center;
}
.email{
position:absolute;
right:0;
}
<div class="business-card">
<section>
<span>
name:abc
</span>
<span>
title:xyz
</span>
</section>
<footer>
<span class="phone">
123-123-123
</span>
<span class="email">
abc#abc.com
</span>
</footer>
</div>
I am trying to get the name/title wrapped but it extends out of the div.
.business-card{
position:relative;
border:1px solid black;
width:200px;
}
.business-card section {
display:flex;
flex-flow:column;
align-items:center;
}
.email{
position:absolute;
right:0;
}
<div class="business-card">
<section>
<span>
name:abcsfsdfjsdflkjsdjflssfsdfds
</span>
<span>
title:xyz
</span>
</section>
<footer>
<span class="phone">
123-123-123
</span>
<span class="email">
abc#abc.com
</span>
</footer>
</div>
Can some one please help on this
PS:Attached is the sample screen shot of the business card im looking to develop
.card {
border: 1px solid lightgray;
}
.title {
display: flex;
flex-direction: column;
padding: 1em;
align-items: center;
text-align: center;
word-break: break-all;
}
.title > div {
width: 50%;
}
.info {
display: flex;
padding: 2em;
}
.info > div {
flex: 1;
}
.info > div:nth-child(2) {
text-align: right;
}
<div class="card">
<div class="title">
<div>Name: eDesignary</div>
<div>Title: Source code platform!</div>
</div>
<div class="info">
<div>Hyderabad</div>
<div>edesignary#gmail.com</div>
</div>
</div>
Please let me know if your problem is solved.
Get a codepen.io account > search "business card" and then create something similar based off another person's pen. You can learn this way about other methods you wouldn't normally know about.
As for this, I'd probably make a DIV of something like 500px
The picture would take 50% of the div's heigh
Then format your text accordingly
When we type names, we put spaces between first, middle and last names. Assuming that none of these is very long, we can make your code work simply by swapping 'align-items' with 'text-align'.
HTML:
<div class="business-card">
<section>
<span>
name:abcsfs dfjsd flkjsdj flssfsdfds
</span>
<span>
title:xyz xyz xyz xyz xy xyz xyz xyz xyz
</span>
</section>
<footer>
<span class="phone">
123-123-123
</span>
<span class="email">
abc#abc.com
</span>
</footer>
</div>
CSS:
.business-card {
position: relative;
border: 1px solid black;
width: 200px;
}
.business-card section {
display: flex;
flex-flow: column;
text-align: center;
}
.email {
position: absolute;
right: 0;
}
Please let me know if this solves your problem.
Check Below snippet... let me know
.business-card{
position:relative;
border:1px solid black;
width:800px;
height: 400px;
}
.business-card section {
display:flex;
flex-flow:column;
align-items:center;
}
.email{
position:absolute;
right:0;
}
#textbox p{
display: inline-block;
width:31%!important;
vertical-align:top;
text-align:left;
padding:0px 5px;
}
<div class="business-card">
<section>
<span>
<img style="height: 200px; width: 400px; align-items:center;" src="http://www.underconsideration.com/brandnew/archives/google_2015_logo_detail.png"/>
</span>
</section>
<div id="textbox">
<p>Text on the left.Text on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the leftText on the left</p>
<p>Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.Text on the middle.</p>
<p>Text on the right.</p>
</div>
<br>
<br>
<div style="clear: both;"></div><!-- Fixes float issues -->
</div>