I am trying to make a footer for a div element, with a <p> tag, however, depending on the font size, the footer would be outside of the box.
How can I make it align at the bottom of the page, with correct padding?
Here's the HTML & CSS file:
#import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
body {
background-color: #202020;
font-family: 'Montserrat', sans-serif;
color: #ffffff;
}
#list {
width: 70%;
height: 250px;
padding: 10px;
overflow: auto;
background-color: #303030;
color: white;
}
.currency {
background-color: #202020;
height: 20%;
color: white;
}
.currency-flag {
float: left;
padding: 5px;
}
.currency-name {
text-align: left;
font-size: 120%;
/* padding-top: 5px; */
}
.currency-value {
text-align: left;
font-size: 50%;
}
<center>
<div id="list">
<div class="currency">
<img class="currency-flag" src="flags/eur.svg"></img>
<p class="currency-name">European Euro</p>
<p class="currency-value">1 R$ = 2 EUR</p>
</div>
</div>
</center>
The problem is that you have set fixed height to .currency insted of height:20% use height:auto;
.currency {
background-color: #202020;
height: auto;
color: white;
}
to fixed it at botton use positions like
#list {
width: 70%;
height: 250px;
padding: 10px;
overflow: auto;
background-color: #303030;
color: white;
position: absolute;
bottom: 0;
}
.currency {
background-color: #202020;
height: auto;
color: white;
}
Set the height property to auto instead of fixing it it will make your p tag inside the div
One suggestion :- Do not use the center dag as its outdated instead try to do similar thing with css property of text-align center
Related
My banner is meant to be directly under the navigation bar but as of now, there is a space between it. I tried to use top for css and it doesn't move.
The css for the banner is:
/*Index CSS*/
* {
margin:0px; padding: 0px;
}
body {
position: absolute;
width: 1250px;
height: auto;
margin-left: auto;
margin-right: auto;
}
#wrapper {
background-color: rgb(161, 193, 217);
position: absolute;
width: 1250px;
height: auto;
margin-left: 5px;
margin-right: 5px;
}
#welcome {
background: url(../Resources/Header/CUiZMwBXAAAQy1M.jpg);
width: 1250px;
height: 480px;
}
#WelcomeTo {
color: white;
font-size: 55px;
text-align: center;
font-family: Bebas;
margin-top: 100px;
}
#LittleChef {
color: white;
font-size: 60px;
text-align: center;
font-family: Candy Shop Personal Use;
}
<div id="welcome" name="banner">
<div id="WelcomeTo" name="WelcomeTo">
<h1>WELCOME<br>TO</h1>
</div>
<div id="LittleChef" name="LittleChef">
<h1>Little Chef</h1>
</div>
</div>
I've had this problem for a very long time. Here is a screenshot to what it looks like as of now.
it is because the margin of your h1 element.
the solution is set the margin-top of h1 to 0.
Or you can set the padding of the wrapper
im getting a white space when im putting text into the div. How to remove that ? i would like to ask you aswell how to make the text "welkom op dennis website" automatic center in the middle of the div.
here you can see the code :
.container {
max-width: 100%;
max-width: 100%;
margin: 0;
padding: 0;
display: inline-block;
}
html,
body {
margin: 0px;
padding: 0px;
}
.nav {
height: 5%;
width: 100%;
background-color: white;
}
.top {
height: 40%;
width: 100%;
background-color: #1E90FF;
}
.nav {
background-color: #444;
}
.nav a {
display: inline-block;
background-color: #444;
font-family: Arial;
padding: 10px 20px;
text-decoration: none;
color: white;
float: right;
}
.nav a:hover {
background-color: #1E90FF;
}
.logo {
color: white;
display: inline-block;
padding: 10px 20px;
font-family: Arial;
text-decoration: none;
}
p.center {
padding: 150px 550px;
color: white;
font-family: Arial;
font-size: 25px;
{}
<header>
<title>Dennis Zwart Home Pagina</title>
<link href="css/MyStyle.css" rel="stylesheet" style="css" />
</header>
<body>
<div class="container">
<div class="nav">
<text class="logo">Dennis Zwart</text>
Contact
Games
Foto's
Hobby's
Home
</div>
<div class="top">
<p class="center">Welkom op de website van Dennis Zwart</p>
</div>
</div>
</body>
The space between your navigation and blue text field is from collapsing margins. You'll need to remove the margins created by your <p> element in .top, more on Collapsing Margins.
If you need the text vertically centered as well, you can use relative positioning and translate.
Other Notes
<text> is not a valid HTML element, use <p>, <span>, <div>, <a> etc. instead. I switched it to an <a> in my answer.
I see that you're using percentage heights. Those can be tricky. In order for percentage heights to work a height has to be set on the parent element. If that parent element's height is a percentage, then it's parent needs a height set. So on and so forth all the way to the root element <html> if percentages are used. In my answer I switch the heights to px values.
A number of block level elements (<div>, <nav>) had width: 100%; applied to them, I removed them as they're not needed. A block level element will always take up 100% width of it's containing element by default.
To vertically center your navigation items I set the line-height of the <a> elements equal to the height of the <nav> element.
I removed your .container element as it wasn't doing anything useful. You might need it later (likely in a different location) if you decide to add media queries and limit it's width for various viewport sizes.
html,
body {
margin: 0px;
padding: 0px;
}
.nav {
height: 45px;
background-color: white;
}
.top {
height: 300px;
background-color: #1E90FF;
}
.nav {
background-color: #444;
}
.nav .logo {
float: left;
}
.nav a {
display: inline-block;
background-color: #444;
font-family: Arial;
padding: 0 20px;
text-decoration: none;
line-height: 45px;
color: white;
float: right;
}
.nav a:hover {
background-color: #1E90FF;
}
p.center {
position: relative;
top: 50%;
transform: translateY(-50%);
margin: 0;
color: white;
font-family: Arial;
font-size: 25px;
text-align: center;
}
<header>
<title>Dennis Zwart Home Pagina</title>
<link href="css/MyStyle.css" rel="stylesheet" style="css" />
</header>
<body>
<div class="nav">
<a class="logo" href="#">Dennis Zwart</a>
Contact
Games
Foto's
Hobby's
Home
</div>
<div class="top">
<p class="center">Welkom op de website van Dennis Zwart</p>
</div>
</body>
This is because p element has natural margins (defined by browser). Remove it:
p {
margin-top: 0;
}
Then remove the p horizontal padding and center your text with
text-align: center;
In order to remove the blank area on the right side of the screen.
p {
margin-top: 0;
text-align: center;
}
.container {
max-width: 100%;
max-width: 100%;
margin: 0;
padding: 0;
display: inline-block;
}
html,
body {
margin: 0px;
padding: 0px;
}
.nav {
height: 5%;
width: 100%;
background-color: white;
}
.top {
height: 40%;
width: 100%;
background-color: #1E90FF;
}
.nav {
background-color: #444;
}
.nav a {
display: inline-block;
background-color: #444;
font-family: Arial;
padding: 10px 20px;
text-decoration: none;
color: white;
float: right;
}
.nav a:hover {
background-color: #1E90FF;
}
.logo {
color: white;
display: inline-block;
padding: 10px 20px;
font-family: Arial;
text-decoration: none;
}
p.center {
padding: 150px 0px;
color: white;
font-family: Arial;
font-size: 25px;
}
<header>
<title>Dennis Zwart Home Pagina</title>
<link href="css/MyStyle.css" rel="stylesheet" style="css" />
</header>
<body>
<div class="container">
<div class="nav">
<text class="logo">Dennis Zwart</text>
Contact
Games
Foto's
Hobby's
Home
</div>
<div class="top">
<p class="center">Welkom op de website van Dennis Zwart</p>
</div>
</div>
</body>
I am trying to make a responsive tweet button with the twitter bird floated left, the text next to it and centered.
My code is:
.flex-rectangle {
float: left;
margin: 0 5px;
max-width: 500px;
text-align: center;
width: 200%;
background: #FFFFFF;
border: 7px solid #00A5EF;
}
/* Styles Twitter Bird png */
.image-wrapper {
padding-top: 10%;
position: relative;
width: 100%;
padding-bottom: 10%;
}
img .tweet {
float: left;
}
/* Tweet This: */
.span-content {
display: block;
color: #00A5EF;
}
.span {
display: block;
text-align: center;
font-family: OpenSans;
font-size: 36px;
color: #00A5EF;
}
<div class="flex-rectangle">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/281152/Twitter_bird_logo_2012.svg" class="tweet" />
</div>
</div>
<div id="buttons">
<div class="span-content">
<span>Tweet This</span>
</div>
</div>
CSS
I've tried pretty much everything under the sun.
I can't seem to get the rectangle to shrink and widen when I resize the page or go into Dev Tools and use the mobile device pane.
I understand CSS less than I do JavaScript at this point. Not sure if I should use flexbox in this instance or how I would do that.
Here is the CodePen
you can use quotes using pseudo element ::before and a::after
Thank you. This works for the most part. However I can't get the
twitter bird to float left and the text to be beside it. Any
suggestions?
I used flexbox the text will be next to the twitter button on desktop view, and below on mobile view.
#import url(https://fonts.googleapis.com/css?family=Open+Sans|Satisfy);
/*Styles for whole page */
img {
max-width: 100%;
border: 7px solid #00a5ef;
}
#page-wrap {
display: flex;
flex-wrap: wrap;
justify-content: center
}
h1 {
font-weight: bold;
text-transform: uppercase;
font-size: 30px;
margin-top: 50px;
width: 300px;
line-height: 1;
font-family: 'Open Sans', sans-serif;
color: #1485C7;
text-align: center;
letter-spacing: 0;
}
/* On: */
h1 .center {
text-transform: capitalize;
font-weight: normal;
font-family: "Satisfy";
vertical-align: text-bottom;
line-height: 10px;
color: #1485C7;
}
h1 .bigger {
font-size: 46px;
color: #1485C7;
display: block
}
/* Rectangle 1: */
.flex-rectangle {
background: #fff none repeat scroll 0 0;
flex: 1 15%;
margin: 0 15%;
max-width: 300px;
padding: 10px;
position: relative;
quotes: "\201C""\201D";
text-align: center;
top: 0;
}
.flex-rectangle::before {
color: #00a5ef;
content: open-quote;
font-family: Georgia;
font-size: 25vw;
left: -15vw;
position: absolute;
top: 50%;
}
.flex-rectangle::after {
color: #00a5ef;
content: close-quote;
font-family: Georgia;
font-size: 25vw;
position: absolute;
right: -15vw;
top: 50%;
}
.text {
align-self: flex-end
}
.span-content {
display: inline-block;
color: #00A5EF;
margin: 0 auto;
padding: 5px;
border: 3px solid #00A5EF;
}
<div id="page-wrap">
<div class="flex-rectangle">
<div class="heading">
<h1>Random Quotes<span class="center">On</span><span class="bigger">Design</span></h1>
</div>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/281152/Twitter_bird_logo_2012.svg" class="tweet" />
<div id="buttons">
<div class="span-content">
Tweet This
</div>
</div>
</div>
<div class="text">
<h1>Random Quotes</h1>
</div>
</div>
you have to place the bird and the text to one div and code for the image element in order to code for the image part you have to call first the first parent div and other div in one code where the image element is located .flex-rectangle .image-wrapper imgto edit the code for image. and also you have to insert the html code for <span>Tweet This</span> inside the .image-wrapper to make the image go left and your text go center.
CSS CODE :
.flex-rectangle {
float: left;
margin: 0 5px;
max-width: 500px;
text-align:center;
width: 200%;
background: #FFFFFF;
border: 7px solid #00A5EF;
}
/* Styles Twitter Bird png */
.image-wrapper {
padding-top: 10%;
position: relative;
margin: auto;
max-width: 125;
max-height: 50px;
width: 100%;
padding-bottom: 15%;
}
.flex-rectangle .image-wrapper img {
float: left;
max-width: 50px;
max-height: 50px;
width: 100%;
}
/* Tweet This: */
.span-content {
display: block;
text-align: center;
color: #00A5EF;
}
.span {
display: block;
text-align: center;
font-family: OpenSans;
font-size: 36px;
color: #00A5EF;
}
HTML Code:
<div class="flex-rectangle">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/281152/Twitter_bird_logo_2012.svg" class="tweet"/>
<div id="buttons">
<div class="span-content">
<span>Tweet This</span>
</div>
</div>
</div>
</div>
I can't seem to center my div tag within a section tag. I can get it centered from left to right but not top and bottom in the center of the section tag. If I give a margin-top:xxpx then it moves the section tag down and exposes it (not good!)
Here is my css
body
{
background-color: yellow;
margin: 0;
}
header > * {
margin: 0;
float: left;
}
header
{
background-color: white ;
width: 100%;
height: 40px;
}
/*header > input {
margin: 10px 20px 0px 10px;
}*/
#toptext
{
margin: 10px 5px 0px 10px;
width: 245px;
}
article > * {
margin: 0;
}
article
{
background-color: red;
}
#search {
background-color: #a6dbed;
height: 500px;
}
#middlesearch {
background-color: grey;
width: 700px;
margin: 0 auto;
}
#mostdesired
{
background-color: #c7d1d6;
height: 200px;
}
section h2 {
margin:0;
}
.site-title {
color: #c8c8c8;
font-family: Rockwell, Consolas, "Courier New", Courier, monospace;
font-size: 1.3em;
margin: 0px 20px 0px 50px;
margin-top: 7px;
}
.site-title a, .site-title a:hover, .site-title a:active {
background: none;
color: #c8c8c8;
outline: none;
text-decoration: none;
}
Here is my html
<body>
<header>
<p class="site-title">#Html.ActionLink("Site", "Index", "Home")</p>
<input id="toptext" type="text" />
</header>
<article>
<section id="search">
<div id="middlesearch">
<h2>Search Here</h2>#RenderBody()
</div>
</section>
<section id="mostdesired" ><h2>This is the most section</h2></section>
</article>
</body>
Vertically aligning with CSS is notoriously tricky.
Change the CSS to
#search {
position: relative;
background-color: #a6dbed;
height: 500px;
}
#middlesearch {
position: absolute;
background-color: grey;
width: 700px;
top: 50%;
left: 50%;
margin-left: -350px; /* half the width */
}
and add one line of JQuery to up the div to be correctly centered
$('#middlesearch').css("margin-top",-$('#middlesearch').height()/2)
this line can be avoided if you decide to explicitly specify the height of the div at which point you can simply define the top margin in the CSS.
This avoids having to use tables.
The CSS declaration for header isn't closed on line 20
http://www.vanseodesign.com/css/vertical-centering/
Unfortunately, CSS doesn't make it to easy, but it is possible. Since the div height is dynamic, I would recommend the CSS table method. Yes, a total hack, but it does work.
You have to do a little work for block level elements, refer to these examples
http://phrogz.net/CSS/vertical-align/
http://www.vanseodesign.com/css/vertical-centering/
#middlesearch {
display:inline-block;
line-height:500px;
vertical-align:middle;
}
Right now, at the NLCC at Brown University, my mentor and I are trying to include images at the bottom of the psiTurk Stroop task; we are working with the Dev Branch of the project.
Our goal is to make a row of three images display like the following:
http://i.stack.imgur.com/4IjNG.png
Except with a red and green box displayed on the right and left boxes.
However, when I've tried to include the code so that boxes would be displayed on the bottom of the test.html page this is what is appeared in my browser.
http://i.stack.imgur.com/LKGfk.png
The code I'm trying to use is the following:
h1>Test Phase</h1>
<div id="instructions">What color is this word?</div>
<div id="stim"></div>
<div id="query"></div>
<p id="PDisplay"> </p>
<p id="TDisplay"> </p>
<p id="RDisplay"> </p>
<div style = "position: absolute;
left:50;"><img id="Lred" src="static/images/red.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:50;"><img id="Lblank" src="static/images/blank.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:50;"><img id="Lgreen" src="static/images/green.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:370;"><img id="Ccue" src="static/images/cue.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:370;"><img id="Cblank" src="static/images/blank.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:370;"><img id="Ctarget" src="static/images/target.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:690;"><img id="Rred" src="static/images/red.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:690;"><img id="Rblank" src="static/images/blank.jpg" IMG HEIGHT = 150/></div>
<div style = "position: absolute;
left:690;"><img id="Rgreen" src="static/images/green.jpg" IMG HEIGHT = 150/></div>
I think that there may be an element pushing over the images to only be displayed in the left corner. To try to fix the problem, I tried manipulating the css for the page, but I got to the point where I deleted the entire sheet except the CSS for the body and all of the images were still being displayed on the left. Just in case, here is what the css looks like:
#import url(http://fonts.googleapis.com/css?family=Crimson+Text:400,600italic);
body {
/* background: #999; */
background: black; /* #808090; */
color: white;
text-align: center;
font-family: Verdana, Helvetica, sans-serif;
margin: 0 auto;
margin-top: 100px;
width: 800px;
}
h1 {
font-family: "Crimson Text";
font-size: 42pt;
font-style: italic;
}
a {
color: #FFCC90;
}
.warm {
color: #DDAA90;
}
.cool {
color: #ccccff;
}
strong {
font-weight: bold;
color: #DDAA90;
}
/* Instructions */
#main {
margin: 0 auto;
width: 800px;
font-size: 100%;
}
.continue {
font-size: 2em;
width: 5em;
height: 2.5em;
margin: 20px 20px;
}
.instruct p {
text-align: justify;
}
.instruct .prompt {
text-align: center;
font-style: italic;
font-size: 100%;
margin: 0 auto;
margin-top: 30px;
width: 500px;
}
/* Questionnaire */
input {
width: 200px;
height: 50px;
font-size: 22pt;
}
.questionnaire {
text-align: center;
}
.questionnaire .continue {
margin: 0 auto;
margin-top: 20px;
}
.questionnaire h1 {
text-align: center;
}
.questionnaire p {
text-align: left;
}
.questionnaire #warning {
color: red;
font-weight: bold;
}
.questionnaire table {
margin: 0 auto;
/* Border stuff: */
table-layout: fixed;
border-collapse: separate;
border-spacing: 0.25em;
border: none;
}
.questionnaire tr {
display: block;
border-bottom: 1px dashed white;
}
.questionnaire tr:last-child { border: 0; }
.questionnaire td {
padding-right: 0.25em;
vertical-align: middle;
border-width: 0 1px;
border: none
margin: 20px;
padding-bottom: 10px;
}
.questionnaire td:first-child, td + td {border-left: 0; }
.questionnaire td:last-child { padding-right: 0; border-right: 0; }
.answer {
text-align: left;
padding-left: 3em;
}
.questionnaire .questiontext {
vertical-align: top;
width: 300px;
margin: 20px;
font-size: 1.2em;
}
.questiontext em {
font-size: 70%;
}
.questionnaire textarea {
width: 320px;
height: 130px;
}
.questionnaire form {
text-align: right;
}
.questionnaire ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.questiontext {
text-align: right;
}
/* Debriefing form */
#debriefing {
width: 640px;
margin: 0 auto;
}
#debriefingtext {
margin: 0 auto;
padding: 10px 20px;
font-size: 90%;
text-align: justify;
}
#affirmationbox {
position: relative;
margin: 0 auto;
border: 1px dotted white;
padding: 10px 20px;
vertical-align: middle;
}
#affirmationbox p {
text-align: left;
font-style: italic;
}
#affirmationbox table {
border-spacing: 20px;
}
#affirmationbox td {
vertical-align: middle;
font-size: 100%;
color: black;
height: 50px;
cursor: pointer;
}
#affirmative {
background: white;
overflow: hidden;
font-weight: bold;
width: 10em;
}
#negative {
background: white;
font-size: 100%;
width: 25em;
}
I was wondering if there is another element in an HTML or some other attribute of the code that is limiting the placement of the images.
Why don't you just float the elements to the left instead of using position absolute
Try
<div style="float:left;">
instead of <div style = "position: absolute;left:50;">
Rather than having a <div> for each <img> tag, use one <div> for each row and change the positioning to inline-block.
For example, rather than having this:
<div style = "position: absolute;left:50;">
<img id="Lred" src="static/images/red.jpg" IMG HEIGHT = 150/>
</div>
<div style = "position: absolute;left:50;">
<img id="Lblank" src="static/images/blank.jpg" IMG HEIGHT = 150/>
</div>
<div style = "position: absolute;left:50;">
<img id="Lgreen" src="static/images/green.jpg" IMG HEIGHT = 150/>
</div>
Do this:
<div style = "position:inline-block;left:50;">
<img id="Lred" src="static/images/red.jpg" IMG HEIGHT = 150/>
<img id="Lblank" src="static/images/blank.jpg" IMG HEIGHT = 150/>
<img id="Lgreen" src="static/images/green.jpg" IMG HEIGHT = 150/>
</div>
Notice how I changed position:absolute to position:inline-block as well as encased all three images into one <div> element, instead of three total <div> elements.
UPDATE
This will create a 3x3 grid of images on the page if you duplicate the code to all 9 images. If you are looking to make a 3x1 grid where the three sets of images "stack" on top of each other, then leave the position:absolute; as-is. This would be best if you are dynamically hiding/showing a series of three images and want them to appear in the same place.