Formatting Images // HTML - html

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.

Related

How to fit text at the bottom inside a div element?

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

I am trying to make a responsive rectangle with an image to the left inside and text centered

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>

How to inline elements with CSS

I'm trying to make menubar at the top of my website.
It should looke like this:
The red square is my button.
My problem is that my headline and my button are not in the same line. So I tried to use a table but then there are both aligned to the left.
After that I used float: right; for my button.
It is now aligned right but in the next line.
How can I fix it so my button and my headline are in the same line and aligned like my picture.
HTML:
<div id="topbar">
<h1>Fahrplan</h1>
<button type="button" id="settings"></button>
</div>
CSS:
h1 {
height: 44px;
margin: 0;
color:#FFFFFF;
text-align: center;
font-family: Helvetica, sans-serif;
font-size: 16px;
line-height: 44px;
}
#topbar button {
height: 20px;
width: 20px;
float: right;
}
For this kind of scenarios, you might consider using positions.
#topbar {
position: relative;
}
h1 {
margin: 0;
color:#FFFFFF;
text-align: center;
font-family: Helvetica, sans-serif;
font-size: 16px;
line-height: 44px;
background: #99f;
}
#topbar button {
height: 20px;
width: 20px;
position: absolute;
top: 50%;
right: 5px;
margin-top: -10px;
}
<div id="topbar">
<h1>Fahrplan</h1>
<button type="button" id="settings"></button>
</div>
Here I have given position to both #topbar and the button. The #topbar has a relative position and button has an absolute position:
#topbar {
position: relative;
}
button {
position: absolute;
top: 50%;
right: 5px;
margin-top: -10px;
}
And I have also adjusted the button to be vertically centred by using the negative margin of half the height. Hope this helps.
I would rather suggest you to use absolute along with translateY() to align your button vertically middle.
Demo (Note: Am using SCSS on jsFiddle so don't get confused with the syntax)
header {
height: 40px;
background: tomato;
position: relative;
h4 {
line-height: 40px;
text-align: center;
}
button {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 10px;
}
}
Explanation:
I am using position: absolute; to move your button to the right. As far as vertical centering goes for your button, you can use top: 50% and transform to nudge your button exactly in the middle of your header vertically. It will always stay vertically centered without you declaring any static height.
For your interest, here's how to do it with inline-blocks.
div > * {
display:inline-block;
vertical-align:middle;
}
h1 {
width:100%;
text-align:center;
margin-right:-40px;
background-color:#4F81BD;
color:#FFF;
font-family: Helvetica, sans-serif;
font-size: 16px;
height: 44px;
}
button {
height: 30px;
width: 30px;
margin-right:-6px;
border: 3px solid #8C3836;
border-radius:5px;
background-color:#C0504D;
}
<div id="topbar">
<h1>Fahrplan</h1>
<button type="button" id="settings"></button>
</div>
Here is a quick demo of how to do this using http://tachyons.io
<div class="bg-light-gray dt w-100">
<div class="dtc v-mid w3"></div>
<div class="dtc v-mid tc pv3">
<h1 class="mv0 f5">Headline</h1>
</div>
<div class="dtc v-mid tr w3 pr2">
<button class="bg-black br2 h2 w2"></button>
</div>
</div>
CSS:
.br2 {
border-radius: .25rem;
}
.dt {
display: table;
}
.dtc {
display: table-cell;
}
.h2 {
height: 2rem;
}
.w2 {
width: 2rem;
}
.w3 {
width: 4rem;
}
.w-100 {
width: 100%;
}
.bg-black {
background-color: #111;
}
.bg-light-gray {
background-color: #eee;
}
.pr2 {
padding-right: .5rem;
}
.pv3 {
padding-top: 1rem;
padding-bottom: 1rem;
}
.mv0 {
margin-top: 0;
margin-bottom: 0rem;
}
.tr {
text-align: right;
}
.tc {
text-align: center;
}
.f5 {
font-size: 1rem;
}
.v-mid {
vertical-align: middle;
}
Demo:
https://jsfiddle.net/r21mdrzs/
The downside is that you include an empty div. The plus side is that even if you zoom in or out, change font-size or size of button, everything will always be aligned to the middle, not matter what. This is in my experience is less brittle than using magic number values for positioning.
Give your headline float property;
.classNameGiveToHeading {
float: left;
}
.buttonClassName {
float: right;
}
OR give "float:right" to both of them as you like.

Margin: 0 auto; not working on a div the needs to inherit a width from 2 enclosed elements

I am trying to center the flame and the heading to the middle of the white box.
HTML
<div class="contentheading">
<div class="floatmiddle">
<img src="images/flame45x45.png">
<h3>Receive only the email you want.</h3>
</div>
</div>
CSS
.contentheading {
position: relative;
height: 45px;
margin-top: 30px;
width: 636px; //this is the full width of the white box//
}
.floatmiddle {
margin: 0 auto;
height: 45px;
display: block;
}
.contentheading img {
position: absolute;
}
.floatmiddle > h3 {
font-family: "signika";
font-size: 22px;
font-weight: 500;
color: #37434f;
height: 45px;
line-height: 45px;
margin: 0 0 0 60px;
text-align: center;
vertical-align: top;
position: absolute;
}
I need the .float middle to inherit the width of the two enclosing elements - the image (45 x 45px) and the text (which will be different length for each chapter i have) so i need one class/formula so i can just go through and pop in the headings and no matter the headings length the heading and the fireball will be centered within the white div.
You can use display: inline-block; to center this div.
http://jsfiddle.net/d8gyd9gu/
HTML
<div class="contentheading">
<div class="floatmiddle">
<img src="http://www.neatimage.com/im/lin_logo.gif" alt="">
<h3>Receive only the email you want.</h3>
</div>
</div>
CSS
.contentheading {
height: 45px;
margin-top: 30px;
width: 636px;
text-align: center;
}
.floatmiddle {
height: 45px;
display: inline-block;
}
.contentheading img {
float: left;
margin: 20px 10px 0px 0px;
}
.floatmiddle > h3 {
font-family: "signika";
font-size: 22px;
font-weight: 500;
color: #37434f;
height: 45px;
line-height: 45px;
padding: 0px 0px 0px 60px;
}
If you can use flexbox you can do it really simply like this:
.contentheading {
border: 1px dashed #ff0000;
margin-top: 30px;
width: 636px;
display: flex;
justify-content: center;
align-items: center;
}
.contentheading h3 {
font-family: "signika";
font-size: 22px;
font-weight: 500;
color: #37434f;
}
<div class="contentheading">
<img src="images/flame45x45.png" width="45" height="45" />
<h3>Receive only the email you want.</h3>
</div>
If you need to support older browsers make sure you add the prefixed versions.
You can definitely pare your markup and styling down. If you only need to center the text and the image in a div of a fixed width, you can simply use text-align: center on the parent container, and display: inline-block on the two elements within. The following markup and styling is about as little as you need:
HTML
<div class="content-heading">
<img src="images/flame45x45.png">
<h3>Receive only the email you want.</h3>
</div>
CSS
.content-heading {
background-color: #ccc;
height: 45px;
margin: 0 auto; /** Centers on the page **/
text-align: center;
width: 636px;
}
h3 {
display: inline-block;
line-height: 45px; /** Only really works if you can rely on only displaying one line of text **/
margin: 0;
overflow: hidden; /** Need this to keep inline-block elements from staggering **/
padding: 0;
}
img {
background-color: black; /** Purely so we can see this **/
display: inline-block;
height: 45px;
width: 45px;
}
That's really all you need.
Codepen sketch

My </p> tag is affecting the position of my div. Why is this?

I have this div wedged between two bars(other divs), though when I add text into the equation, the div gets repositioned down. It works as intended without the p element and its children. Here's a fiddle to demonstrate the issue: http://jsfiddle.net/57uSQ/
this is the HTML that is causing the problem:
<p>
<span class="name">DOLCE & GABBANA</span>
</br>
<span class="title">THE ONE</span>
</p>
And the correlating CSS:
.videoDesc {
display: inline-block;
border: 1px solid #000000;
border-right: 0px;
height: 200px;
width: 500px;
}
.videoDesc p {
display: inline-block;
margin: 0;
padding: 0;
}
.videoDesc .name {
display: inline-block;
padding: 0px;
}
.videoDesc .title {
display: inline-block;
padding: 0px;
}
.title {
font-family: Lekton;
font-size: 1.25em;
}
.name {
font-family: Oswald;
font-weight: lighter;
font-size: 2.5em;
letter-spacing: 10px;
padding-left: 5px;
}
You need to add vertical-align:top to .videoDesc:
.videoDesc {
display: inline-block;
border: 1px solid #000000;
border-right: 0px;
height: 200px;
width: 500px;
vertical-align:top;
}
jsFiddle example
The default vertical alignment is baseline, which is causing the behavior you see.