I am a noob in CSS and i was actually trying to create a table kind of structure using Html Div and CSS, but got stuck in one issue.
Problem is that I have put 4 columns in 1 single row. The last column contains a text area which is expandable.
When I try to expand the text area, only the last column expands instead of the whole row.
Below is the code demo:
http://codepen.io/anon/pen/oIChn
The code isn't working because you arent following a table structure, which should (always) be:
table
-row
--cell
--/cell
-/row
/table
IN your code, you are using some display:tablexx CSS, however often in elements isolated from other aspects of the table structure they are expecting to be next to, as such the layout is broken.
The correct CSS/HTML structure is (e.g):
Demo Fiddle
HTML
<div class='table'>
<div class='row'>
<div class='cell'></div>
<div class='cell'></div>
<div class='cell'></div>
</div>
<div class='row'>
<div class='cell'></div>
<div class='cell'></div>
<div class='cell'></div>
</div>
</div>
CSS
.table {
display:table;
height:100%;
}
.cell {
display:table-cell;
width:50px;
height:100px;
border:1px solid black;
}
.row {
display:table-row;
}
Note that using this there are no specific thead or tbody sections, you can simply adapt your CSS to style headers etc as appropriate.
Add this at the end of your css, should do the trick
.r-tab-head{
display: table-row;
float: none;
}
.divCell {
display: table-cell;
float: none;
}
Related
I have a structure such as :
<div class='container'>
<div class='half-screen'></div>
<div class='half-screen'></div>
<div class='half-screen'></div>
<div class='half-screen'></div>
</div>
I have to add divs dynamically and I'm wondering if there's a way to create the relationship dynamically so that a bar is inserted before every two divs with the half-screen class, i.e. before every 2n+1 div.half-screen.
There may be other ways to restructure and use css for top-border on each half screen but I'm curious to know if I can solve this using the + css adjacent operator
.container {
&.half-screen + .half-screen + .half-screen {
&:before {
border-top: 1px solid #ccc;
display:block;
}
}
}
I think you were on the right track with 2n+1 and :before, just missing a couple steps, unless I'm misunderstanding. Is this what you're trying to achieve?
.half-screen:nth-child(2n+1):before {
content: '';
width: 100%;
margin: 10px 0;
height: 1px;
background: black;
display: block;
}
<div class='container'>
<div class='half-screen'>1</div>
<div class='half-screen'>2</div>
<div class='half-screen'>3</div>
<div class='half-screen'>4</div>
<div class='half-screen'>5</div>
<div class='half-screen'>6</div>
</div>
No, you can't.
I know you're thinking .a + .a + .a matches the third element with a class of a, but keep in mind it also matches the fourth element with a class of a. CSS doesn't really say "Oh, we already used that element for this selector, we won't use it again."
In Wordpress i have two div with different css classes on them but when i inspect it using firefox the css that i have written for the second is not shown in the css section and it is not picking up the css of that class.
here is my code :
<div class="innerContainer">
Inner Container
<div class="whiteBack">
test container
</div>
</div>
its css is :
.whiteBack{
width:100%;
float:left;
background-color: pink;
}
.innerContainer{
width:1170px;
margin:0 auto;
background-color: cyan;
}
I have the following html. I need to align the .faf-text fields to each other vertically without using a table.
<div id="faf-field-2" class="faf-field faf-field-input ">
<div class="faf-name"> Vendor </div>
<div class="faf-text"> Brocade </div>
</div>
<div id="faf-field-6" class="faf-field faf-field-input ">
<div class="faf-name"> Platform </div>
<div class="faf-text"> ADX </div>
</div>
<div id="faf-field-7" class="faf-field faf-field-input ">
<div class="faf-name"> Version </div>
<div class="faf-text"> 12.4 </div>
</div>
An example of what the layout should be like is below :
Vendor Brocade
Platform ADX
Version 12.4
Thanks
You can use the CSS display: table to make your elements act like a table.
Use display: table-row; for the container <div> tags to make it behave like a <tr> and display: table-cell; for the elements inside to make it behave like <td>.
Something like this:
.faf-field-input{
display: table-row;
}
.faf-field-input div{
display: table-cell;
}
.faf-name{
width: 80px; /*for testing*/
}
jsFiddle DEMO
Just use
float: left
for both classes.
An ex:
.faf-name{
width: 200px;
float: left;
/* other CSS may come here */
}
in the same way,
.faf-text{
width: 200px;
float: left;
/* other CSS may come here */
}
It would have been easier and clearer if you have provided jsfiddle. Hope this will work for you
Just Use this css property so faf-text fields to each other vertically without using a table.
.faf-field{display:table-cell;}
DEMO
From your code, it looks to me that you are displaying tabular data.
So it's perfectly good to use a table.
I'm currently updating a pretty old website (last update was around 2001), and have agreed to use HTML5 and CSS3.
For the general design, I'm working on a very clean white and gray tones style, with many paddings and margins. My problem resides in the home page: I'd like to have a 3-column centered layout. But where to start? I've tried some floating, but in vain.
Am I doing this right ?
HTML:
<div class="colwrapper">
<div class="ltcol"></div>
<div class="ctcol"></div>
<div class="rtcol"></div>
</div>
CSS:
.colwrapper { width:1020px; }
.ltcol, .ctcol, .rtcol { width:300px; margin:0 10px; padding:10px; }
.ltcol { float:left; }
.ctcol { margin-left:340px; }
.rtcol { float:right; }
your css should be like this:
.ltcol, .ctcol { float:left; }
.rtcol { float:right; }
The purpose of the CSS float property is, generally speaking, to push a block-level element to the left or right, taking it out of the flow in relation to other block elements. This allows naturally-flowing content to wrap around the floated element. This concept is similar to what you see every day in print literature, where photos and other graphic elements are aligned to one side while other content (usually text) flows naturally around the left- or right-aligned element.
For More details you must have to read this intresting article.
See This Demo: http://jsfiddle.net/akhurshid/YRWLV/
Your HTML is very clean - this is a great step forward.
You need to add a float: left to all the columns. To ensure the float is cancelled after your columns, it is best to add a clear div after the floated columns.
HTML:
<div class="colwrapper">
<div class="ltcol">Column 1</div>
<div class="ctcol">Column 2</div>
<div class="rtcol">Column 3</div>
<div class="clear"></div>
</div>
CSS:
.colwrapper { width:1020px; }
.ltcol, .ctcol, .rtcol { width:300px; margin:0 10px; padding:10px; background-color: #efefef }
.ltcol { float:left; }
.ctcol { float:left; }
.rtcol { float:left; }
.clear { clear: left; }
So you add css3 tag for this questio so I suggest you to make this with css3 column layout:
More info
for example
HTML
<div class="colwrapper">
<div>text</div>
</div>
CSS
.colwrapper div
{
-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
column-count:3;
}
It does not work on IE.
Use one of these tried and tested implementations instead of rolling out your own. In addition to the fact that you'll be getting tested and working code, you'll add responsiveness to your site with almost zero effort.
http://cssgrid.net/
http://960.gs/
http://framelessgrid.com/
http://goldengridsystem.com/
and lots more if you google..
could also use Flexbox property for this now as well so you don't need to worry about floats or clearfix's.
main{
/* .colwrapper{ */
display: flex;
flex-flow: row;
justify-content: center;
}
main > section{
/* .ltcol,.ctcol,.rtcol{ */
display:flex;
flex-flow:column;
align-items:center;
padding:10px; padding:.625rem;
}
main > section:nth-child(2){
/* .ctcol{ */
margin:0 20px; margin:0 1.25rem;
}
http://caniuse.com/flexbox shows the support for it isn't quite as far along as you would probably like, however, there are ways to improve support by mixing old versions of the syntax with the new http://css-tricks.com/using-flexbox/ has a great write up on it from Chris Coyier if you want to play with this for a next project (this post is fairly old). You can also get more details at http://html5please.com/#flexbox
Also, if you're using HTML5 I'd probably go with sections over divs for a more semantic structure, so a comparison would look something like this:
<main>
<section></section><!-- or <nav></nav> -->
<section></section><!-- or <article></article> -->
<section></section><!-- or <aside></aside> -->
</main>
instead of...
<div class="colwrapper">
<div class="ltcol"></div>
<div class="ctcol"></div>
<div class="rtcol"></div>
</div>
Just try putting the rtcol div beofre le ltcol div.
<div class="colwrapper">
<div class="rtcol">X</div>
<div class="ltcol">X</div>
<div class="ctcol">X</div>
</div>
http://jsfiddle.net/EDjpy/
I'm converting an Access application to web, and need to print reports from it. These are letters mailed out and so the bottom of the letter, which is the 'please return' portion, will always be at the bottom of the page, regardless of how big the body of the letter is. I've used DIVs to lay out the letters and mimicked Access quite well, but I don't know how to get each letter's header at the bottom of its page. Using the CSS position: fixed; for the footer just makes every footer show up at the bottom of every page, and we would like to be able to print off multiple letters at once.
If I remove the fixed, it does display each footer on its own page, they weren't aligned to the bottom of it.
Can I have my cake and eat it too? Doesn't need to be cross-browser, and I'll move to PDF if absolutely necessary, but what are my options in CSS/HTML? Somehow converting it all to a table and trying out tfoot? But will that enforce it to be at the bottom of each page?
Edit: A sample of the CSS/HTML:
.reportcontainer {
width: 100%;
page-break-inside: avoid;
page-break-after: always;
position: relative;
}
.reportbody {
float: left;
text-align: left;
}
.reportfooter {
width: 100%;
float: left;
bottom: 0;
position: fixed;
}
<div class="reportcontainer">
<div class="reportbody">
yadda yadda yadda
</div>
<div class="reportfooter">
stuff goes here
</div>
</div>
Try this. I've had to figure out a lot of html printing lately as well. You can figure out how you want to replicate the divs, either backend or using jquery cloning for each report. Borders are just to illustrate containers.
.reportcontainer {
width:8.5in;
height:11in;
page-break-inside:avoid;
page-break-after:always;
border:1px solid red;
}
.reportbody {
width:100%;
height:10in;
border:1px solid yellow;
}
.reportfooter {
width:100%;
height:1in;
border:1px solid blue;
}
</style>
<div class="reportcontainer">
<div class="reportbody">
yadda1 yadda1 yadda1
</div>
<div class="reportfooter">
footer 1 goes here
</div>
</div>
<div class="reportcontainer">
<div class="reportbody">
yadda2 yadda2 yadda2
</div>
<div class="reportfooter">
footer 2 goes here
</div>
</div>
<div class="reportcontainer">
<div class="reportbody">
yadda3 yadda3 yadda3
</div>
<div class="reportfooter">
footer 3 goes here
</div>
</div>
I would recommend using PDF. If you need that level of control for printed material, you're going to be fighting to get HTML to work across browsers and this is really what PDF is designed for.
tfoot would not help, it only ensures that the footer is at the bottom of the table, not the bottom of the page.