Using CSS to arrange divs within accordion structure - html

Hi there, I am designing a questionnaire which is embedded into an Accordion widget structure. Originally, I started it using table for layout (I know, I know) which was ok.
Question text goes to accordion panel and user's guidance and responses go to accordion content area.
Now I would like get rid of table and use pure css, maintaining the same layout. The problem is - I cannot put two major blocks (div=Guidance and form=Response) together on the same line (flow does not help). I can move "Response" up to line it up with Guidance but only if I use negative top: -250px which seems wrong.
So, here is HTML for a single question:
<div id="Q08150"> <!-- BEGIN OF PANEL -->
<div class="Question">
<span class="QNumber">8.150</span>
<span class="QText">Question text</span>
</div>
</div> <!-- END OF PANEL -->
<div class="PanelContent"> <!-- BEGIN OF CONTENT -->
<div class="Guidance">
<p>Guidance text1</p>
<p>"Guidance text 2</p>
</div>
<form class="Response">
<div class="ResponseControls">
<label><input type="radio" name="RadioXXXX" value="Y" id="RXXXXY">Yes</label>
<label><input type="radio" name="RadioXXXX" value="N" id="RXXXXN">No</label>
<label><input type="radio" name="RadioXXXX" value="NS" id="RXXXXNS">Not Seen</label>
<label><input type="radio" name="RadioXXXX" value="NA" id="RXXXXNA">Not Applicable</label>
</div>
<div class="responseDetails">
<div class="Observation">
<label for="ObsXXXX">Observation:</label>
<textarea name="observation" id="ObsXXXX" rows="6" disabled></textarea>
</div>
<div class="DueDate">
<label for="DueDateXXXX">Due date:</label>
<input name="DueDate" class="DueDate_in" type="text" id="DueDateXXXX"/>
</div>
<div class="actions">
<label for="paXXXX">Actions required to correct and/or prevent this observation:</label>
<textarea name="actions" id="paXXXX" rows="6"></textarea>
</div>
</div> <!-- end of div class="responseDetails" -->
</form> <!-- end of class="Response" -->
</div> <!-- END OF CONTENT -->
and the following CSS
.Question {
width: 100%;
}
.PanelContent {
width:100%
}
.QNumber {
font-weight: bold;
}
.QText {
font-weight: bold;
padding-left: 20px;
}
.Guidance {
width:55%;
padding-right: 20px;
}
.Response {
position: relative;
left:60%;
width: 45%;
}
textarea[name="observation"] {
resize:none;
width: 530px}
textarea[name="actions"] {
resize:none;
width: 530px}
Now, because it is accordion - I cannot wrap the entire question in a div, otherwise it will not work; so I have to keep question and response parts separated.
The top picture is what I would like to have and lower one shows current look using table.
Thanks in advance!

Surely, set these two major "players" as below:
.Guidance {
position: absolute;
width:55%;
padding-right: 20px;
}
.Response {
position: relative;
width: 37%;
float: right;
position: absolute will do the trick.

Related

Images dont float right next to contact form css

For a school project a need to make a website. I have a contact form page and to the right I want three images. See picture for how it looks now. The images float under the form and not on the right of it. Here is some html and css code:
#contact-img1,
#contact-img2,
#contact-img3 {
width: 20%;
height: auto;
float: right;
}
#contactform {
width: 70%;
height: 500px;
float: left;
}
.shoes {
float: right;
}
<fieldset id="contactform">
<legend>If you have a question you can ask it here:</legend>
<p> <label for="name">Name:</label> </p>
<input type="text" name="name">
<p> <label for="email">Email:</label> </p>
<input type="text" value="placeholder#gmail.com" name="email">
<p> <label for="message">Message:</label> </p>
<input type="text" name="message">
<p>
<form action="contact.html">
</p>
<input type="submit" value="send question!" />
</form>
</fieldset>
<section class="shoes">
<aside class="img-inno1">
<img id="contact-img1" src="images/inno-img1.webp" alt="first sport image">
</aside>
<aside class="img-inno2">
<img id="contact-img2" src="images/inno-img2.webp" alt="second sport image">
</aside>
<aside class="img-inno3">
<img id="contact-img3" src="images/inno-img3.webp" alt="third sport image">
</aside>
</section>
Floating an element allows content that follows it to bubble up beside it.
It does not cause the floated element to bubble up beside content before it.
To get the form next to the images using floats you would need to either:
Change the source order
Float the form instead of the images
That said. The point of float is to achieve this sort of effect (as shown in the CSS specification):
Using them to make blocks of content site beside each other is a hack.
We have Flexbox for that type of layout now.
Try this
.shoes {
float:right;
width:20%;
}
.shoes aside {
display: inline-block:
}
.shoes img {
max-width: 100%;
}

How do I make flexbox even begin to work? It's doing nothing

I cannot get flexbox to work. I've tried all sorts of CSS properties, but it doesn't want to work. display-flex doesn't seem to do anything to the page at all. I tried various tags, like flex-direction:column, and text-align: center, but nothing works. Why won't flexbox do anything?
Expected result:
My current result:
https://replit.com/#elliotsFinal/what-to-study#index.html
My HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class=flex-container>
<h3>WHAT TO STUDY</h3>
<h1>What are your interests?</h2>
<fieldset>
<legend>Pick one from this list</legend>
<div>
<input type="radio" id="data" name="list-1" value="data"
checked>
<label for="data">data</label>
</div>
<div>
<input type="radio" id="math" name="list-1" value="math">
<label for="math">mathy</label>
</div>
<div>
<input type="radio" id="theory" name="list-1" value="theory">
<label for="theory">theory</label>
</div>
</fieldset>
<fieldset>
<legend>And one from this list</legend>
<div>
<input type="radio" id="people" name="list-2" value="people"
checked>
<label for="people">people</label>
</div>
<div>
<input type="radio" id="problem solving" name="list-2" value="problem solving">
<label for="problem solving">problem-solving</label>
</div>
<div>
<input type="radio" id="art" name="list-2" value="art">
<label for="art">art</label>
</div>
</fieldset>
<script src="script.js"></script>
</div>
</body>
<footer>
<P>Please select one choice in each list</P>
</footer>
</div>
</html>
My CSS:
html, body {
height: 100%;
width: 100%;
}
.flex-container {
font-family: Arial, Helvetica, sans-serif;
display: flex
flex-direction: column
background-color: DodgerBlue
}
.flex-container > div {
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
.list-1 {
}
.list-2 {
}
There's various issues here.
<div class=flex-container> should be <div class="flex-container">.
.flex-container > div means "target DIVs that are direct children of .flex-container", but your container's direct children are headings and fieldsets.
Not related to your issue, but <h1>What are your interests?</h2> is invalid markup - make sure your opening and closing tags match.
I hope this helps: https://replit.com/#MatijaJanji/what-to-study#style.css
Besides the issues by geat, you're targeting the wrong element with the flex property. In the example above, I'm targeting all the divs that have fieldset as the parent. I'm not sure if that's what you were after.
You have quite a few errors and omissions in your code that need to be corrected:
CSS
Flexbox goes only one level deep (FBL parent vs. flexed child) => the fieldsets need to be a flexbox parent row inside .flex-container parent for the <div> inside.
.flex-container => two missing semi-colons
.flex-container > div => should be .flex-container > fieldset > div
.list-1, .list-2 => should be [name="list-1"] and [name="list-2"] as you don't use the classes in your HTML tags.
HTML
missing </body>
orphaned </div>
error <div class=flex-container> should be <div class="flex-container">
h1 vs h2 => <h1>What are your interests?</h2>
given the example image => <h3> and <h1> should come before the <div class=".flex-container">, not be a part of it.
Semantics (a11y = accessibility)
<h3> and <h1> => should be <div> with different font settings
In below snippet you will find the corrected code with some comments. I did not provide anything even resembling 'responsive design' nor did I attempt to create the final design, leaving it up to you to implement.
html, body {
height: 100%;
width: 100%;
}
h1,h3 { text-align: center }
h3 { letter-spacing: 0.3rem } /* 'stretch' the text */
.flex-container {
font-family: Arial, Helvetica, sans-serif;
display: flex; /* had missing semi-colon */
flex-direction: column; /* dito */
background-color: DodgerBlue;
width : max-content; /* restrict W/H to its content => the fieldset */
height: max-content;
margin: 5rem auto; /* some top/bottom space, 'auto' centers horizontally */
}
.flex-container > fieldset {
display: flex;
}
.flex-container > fieldset > div {
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
[name="list-1"] { /* rule for radio group named 'list-1' */ }
[name="list-2"] { /* rule for radio group named 'list-2' */ }
<h3>WHAT TO STUDY</h3>
<h1>What are your interests?</h1>
<div class="flex-container">
<fieldset>
<legend>Pick one from this list</legend>
<div>
<input type="radio" id="data" name="list-1" value="data" checked> <label for="data">data</label>
</div>
<div>
<input type="radio" id="math" name="list-1" value="math"> <label for="math">mathy</label>
</div>
<div>
<input type="radio" id="theory" name="list-1" value="theory"> <label for="theory">theory</label>
</div>
</fieldset>
<fieldset>
<legend>And one from this list</legend>
<div>
<input type="radio" id="people" name="list-2" value="people" checked> <label for="people">people</label>
</div>
<div>
<input type="radio" id="problem solving" name="list-2" value="problem solving"> <label for="problem solving">problem-solving</label>
</div>
<div>
<input type="radio" id="art" name="list-2" value="art"> <label for="art">art</label>
</div>
</fieldset>
</div>
</body>
<footer>
<p>Please select one choice in each list</p>
</footer>

How can I make the mdl tooltip to stick to the icon?

I am using the mdl tooltip on a an material icon, what can I do to make the tooltip stick to the icon.
Normally the tooltip looks like this but when scrolled the tooltip is on a wrong div:
But upon scroll it looks like this:
Code:
HTML
<div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="headerLogoLinkField" onchange="updateHeaderLogoLink()" >
<label class="mdl-textfield__label" for="headerLogoLinkField">Header Logo Link...</label>
</div>
<div id="header-logo-reset" class="icon material-icons toinline">replay</div>
<div class="mdl-tooltip toinline" for="header-logo-reset">
Reset To Default
</div>
</div>
CSS
.toinline {
display: inline;
}
So, as I said in the comments, to avoid this kind of behavior you can put your absolute position tooltip inside a relative parent.
Here's a fiddle for example with content text above and below the input text. When you hover your input and scroll, you can see the tooltip stay at the same place and don't move.
HTML part
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="headerLogoLinkField" onchange="updateHeaderLogoLink()" >
<label class="mdl-textfield__label" for="headerLogoLinkField">Header Logo Link...</label>
<div class="mdl-tooltip toinline" for="header-logo-reset">
Reset To Default
</div>
</div>
CSS Part
.toinline {
background: #333;
position: absolute;
color: #fff;
padding: 5px;
display: none;
top: -30px;
left: 50px;
}
.mdl-textfield:hover .toinline {
display: block;
}
.mdl-textfield { position: relative; }
Fiddle

Vertically align right divs if another div to the left causes them to stack

This page has questions on the left, and radio buttons for ranking/scale answers on the right. It's designed so that if the question text is too long too fit in the left pane it just keeps going and pushes the radio buttons down a line beneath the question text. I emphasized if because I want to keep it that way, so it only moves if the text is long, I don't want to set something fixed so that every question does the same thing.
The problem is, the N/A radio button doesn't adjust like the other radio buttons. Is there a way to force it to move down with the others? I've tried surrounding the two sections with a div with vertical align bottom but that didn't work. Maybe I am doing something wrong but whatever I've read with regards to vertically aligning inner divs doesn't seem to accomplish this. Is it possible to fix this?
https://jsfiddle.net/x5y49d0n/
.qg {
width: 700px; /* this is only to demonstrate a smaller screen */
padding-top: 10px;
margin-top: 0;
}
.qg-row {
margin-left: 10px;
margin-bottom: 10px;
overflow: auto;
}
.qg-head {
padding-top: 5px;
padding-bottom: 5px;
background-color: #fcfcfc;
}
[class*="qg-guide"] {
font-size: 11px;
min-height: 10px;
text-align: center;
float: left;
}
[class*="qg-right-section"] {
float: right;
width: 500px;
}
.qg-right-section-1 {
width: 60px;
}
.qg-right-section-5 {
width: 300px;
}
[class*="qg-guide-"] {
word-wrap: break-word;
}
.qg-guide-1 {
empty-cells: hide;
width: 100%;
min-width: 100%;
}
.qg-guide-5 {
/* replicate in mobile */
empty-cells: show;
width: 20%;
min-width: 20%;
}
.qg-guide-7 {
empty-cells: show;
width: 14.28%;
min-width: 14.28%;
}
.qg-label {
font-size: 13px;
float: left;
margin-bottom: 10px;
}
[class*="qg-input"] {
font-size: 11px;
width: 60px;
text-align: center;
float: left;
}
<div class="qg">
<div class="qg-table">
<div class="qg-row qg-head">
<div class="qg-guide-label"></div>
<div class="qg-guide qg-right-section-1">
<div class="qg-guide-1"> </div>
</div>
<div class="qg-guide qg-right-section-5">
<div class="qg-guide-7">High7</div>
<div class="qg-guide-7"></div>
<div class="qg-guide-7"></div>
<div class="qg-guide-7">Neutral4</div>
<div class="qg-guide-7"></div>
<div class="qg-guide-7"></div>
<div class="qg-guide-7">Low1</div>
</div>
</div>
<div class="qg-row">
<div class="qg-label">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia.</div>
<div class="qg-guide qg-right-section-1">
<div class="qg-input-1">
<input type="radio" name="0LoMVa" value=""><br>
N/A<br>
</div>
</div>
<div class="qg-right-section-5">
<div class="qg-input-5"><input type="radio" name="0LoMVa" value="5"><br>5<br></div>
<div class="qg-input-5"><input type="radio" name="0LoMVa" value="4"><br>4<br></div>
<div class="qg-input-5"><input type="radio" name="0LoMVa" value="3"><br>3<br></div>
<div class="qg-input-5"><input type="radio" name="0LoMVa" value="2"><br>2<br></div>
<div class="qg-input-5"><input type="radio" name="0LoMVa" value="1"><br>1<br></div>
</div>
</div>
</div>
</div>
<div class="qg">
<div class="qg-table">
<div class="qg-row qg-head">
<div class="qg-guide-label"></div>
<div class="qg-guide qg-right-section-1">
<div class="qg-guide-1"> </div>
</div>
<div class="qg-guide qg-right-section-5">
<div class="qg-guide-5 qg-guide-item-0">High0</div>
<div class="qg-guide-5 qg-guide-item-1"></div>
<div class="qg-guide-5 qg-guide-item-2">Neutral2</div>
<div class="qg-guide-5 qg-guide-item-3"></div>
<div class="qg-guide-5 qg-guide-item-4">Low4</div>
</div>
</div>
<div class="qg-row">
<div class="qg-label">Far far away, behind the word mountains.</div>
<div class="qg-guide qg-right-section-1">
<div class="qg-input-1">
<input type="radio" name="W1MkXk" value=""><br>
N/A<br>
</div>
</div>
<div class="qg-right-section-5">
<div class="qg-input-5"><input type="radio" name="W1MkXk" value="5"><br>5<br></div>
<div class="qg-input-5"><input type="radio" name="W1MkXk" value="4"><br>4<br></div>
<div class="qg-input-5"><input type="radio" name="W1MkXk" value="3"><br>3<br></div>
<div class="qg-input-5"><input type="radio" name="W1MkXk" value="2"><br>2<br></div>
<div class="qg-input-5"><input type="radio" name="W1MkXk" value="1"><br>1<br></div>
</div>
</div>
</div>
</div>
This is what I want it to do:
Also, these questions are created programmatically using a template, so the divs used have to be the same, IOW I can't add a div (with an additional class) to the 1st question that fixes the issue without the 2nd question having the same div. This is the critical requirement which is making it difficult for me to find a solution. Can this be solved?
Is it possible to change DOM structure?? If yes then just try pushing
<div class="qg-guide qg-right-section-1"></div> inside
<div class="qg-guide qg-right-section-5">
code
<div class="qg-row qg-head">
<div class="qg-guide-label"></div>
<div class="qg-guide qg-right-section-5">
<div class="qg-guide-5 qg-guide-item-0">High0</div>
<div class="qg-guide-5 qg-guide-item-1"></div>
<div class="qg-guide-5 qg-guide-item-2">Neutral2</div>
<div class="qg-guide-5 qg-guide-item-3"></div>
<div class="qg-guide-5 qg-guide-item-4">Low4</div>
<div class="qg-guide qg-right-section-1">
<div class="qg-guide-1"> </div>
</div>
</div>
</div>
and change css
.qg-right-section-5 {
width: 360px;
}
.qg-right-section-1 {
width: 60px;
float: left;
}
You can achieve the effect you want by adding a clear-fix after the .qg-label class. I did this in the fiddle by manually inserting an empty <div> with the style clear:both;. You could instead use the clear-fix class of your favorite library or create you own such as:
(This is a classic clearfix example from this answer)
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
Another solution is to include all radio buttons in the same parent element, give it a fixed width, and add float:right; to it and the radio element children. This should be a simple fix. I showed this in comparison to your original fiddle here - fiddle.

CSS sidebars not showing up

I'm working on a very very simple template. Or so I thought. The template didn't originally come with sidebars so I tried to sneak them in there myself. It's not working at all- I don't see my test text show up at all.
Can someone please point me to what I did wrong?
You can see the page in question at http://www.stfuisland.com/add.html
The code is posted below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>STFU Island</title>
<style type="text/css">
a.header:link {
color:#ffffff;
text-decoration:none;
hover {color:#ffcc00;}
}
body{
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
height: 100%;
max-height: 100%;
}
#framecontent{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 70px; /*Height of frame div*/
overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color: navy;
color: white;
}
#maincontent{
position: fixed;
top: 75px; /*Set top value to HeightOfFrameDiv*/
//left: 0;
//right: 0;
bottom: 0;
overflow: auto;
background: #fff;
}
#leftbar {
float: left;
width: 30%;
}
#rightbar {
float: right;
width: 30%;
}
.innertube{
margin: 15px; /*Margins for inner DIV inside each DIV (to provide padding)*/
}
* html body{ /*IE6 hack*/
padding: 130px 0 0 0; /*Set value to (HeightOfFrameDiv 0 0 0)*/
}
* html #maincontent{ /*IE6 hack*/
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="leftbar">
<div class="innertube">
<p>test</p>
</div></div>
<body>
<div id="rightbar">
<div class="innertube">
<p>test</p>
</div></div>
<div id="framecontent">
<div class="innertube">
<center><h3><font color="white"><a class="header" href="index.html">home</a> | Are You on an Island? | About</font></h1></center>
</div>
</div>
<div id="maincontent">
<div class="innertube">
<center>
<form class="pure-form">
<fieldset class="pure-group">
<input type="text" class="pure-input-1-2" placeholder="Your Name" name="creatorname" size="50">
<input type="text" class="pure-input-1-2" placeholder="Your Email" name="creatoremail">
<input type="email" class="pure-input-1-2" placeholder="Relationship to people being sent to island" name="relationship">
</fieldset>
<fieldset class="pure-group">
<input type="text" class="pure-input-1-2" placeholder="Name of first person sent to STFU Island" name="person1">
<input type="text" class="pure-input-1-2" placeholder="Their email address" name="email1">
</fieldset>
<fieldset class="pure-group">
<input type="text" class="pure-input-1-2" placeholder="Name of second person sent to STFU Island" name="person2">
<input type="text" class="pure-input-1-2" placeholder="Their email address" name="email2">
</fieldset>
<fieldset class="pure-group">
<input type="text" class="pure-input-1-2" placeholder="Name of third person sent to STFU Island" name="person3">
<input type="text" class="pure-input-1-2" placeholder="Their email address" name="email3">
</fieldset>
<fieldset class="pure-group">
<input type="text" class="pure-input-1-2" placeholder="Tell them why they're being sent to STFU Island!" cols="40" rows="5" name="reason">
</fieldset>
<button type="submit" class="pure-button pure-input-1-2 pure-button-primary" name="submit">Send them to STFU Island!</button>
<br>aaaaEmail addresses are sacred and we will treat them that way. Email addresses collected are only used to send emails when people are added or are being set free from STFU island. No other company will ever see or use them for any reason. Period.
</form>
</center>
</div>
</div>
</body>
</html>
Add to your CSS: (for #leftbar and #rightbar)
z-index: 2;
position: relative;
That works for me, also you might want to use color:#fff so you can see it.
Use text-align:center instead of center,
Use 1 div instead of multiple divs inside each other..
The source is very busy and messy; too messy for something which is pretty simple.
I'll make a clone which shows how simplified it can be and update later.
Your left side bar and right side bar are underneath your title. I imagine you want them inside the maincontent and next to your innertube. moving your divs next to the inner tube will show up in the layout you want.
<div id="leftbar">
...
</div>
<div class="innertube">
...
</div>
<div id="rightbar">
...
</div>
also add a float: left to your inner tube
Your header is position: absolute, which takes it out of the normal flow and hides your sidebars.
A typical three column layout with header and footer might look like
HTML
<div class="header">Header</div>
<div class="wrapper">
<div class="nav left">Left Navigation</div>
<div class="nav right">Right Navigation</div>
<div class="content">
</div>
</div>
<div class="footer">Footer</div>
CSS
.nav {
background: green;
width: 100px;
}
.nav.left {
float: left;
}
.nav.right {
float: right;
}
.content {
margin-left: 100px;
margin-right: 100px;
}
See full JSFiddle
Looking at your codes, I can't quite tell what you are after. Is it a three column layout with left and right bars and middle content has framecontent on top and maincontent at the bottom OR left bar | framecontent | right bar and have maincontent sitting under all three?
If you are trying to achieve a basic 3-column layout, there really is no need to have that div with a width of 100% plus an absolute position. The result will be the div sitting on top of the left and right bars.
just float left bar to the left (float:left), float the middle content to left as well and float the right content to right, and you will have 3 column layout. If you want both framecontent and maincontent to sit in the middle, then you can put maincontent inside the framecontent div.
I hope my explanation is not too confusing.