can anyone tell me any guides/hints for the css/html necessary to create a layout similar to the
message part of a forum:
------------------------
[8] User1
Some msg
------------------------
[8] User2
Another message
------------------------
Is this 1 main div and several child divs or something simpler like a css styled listitems or table, etc?
Please let me know the "correct" way to achieve this layout without newest css3/html5/beta code
An Example:
<style>
.message {margin-bottom: 15px; }
.image {float:left; margin-right: 10px; }
.user {float:left; font-weight:bold; color:#009; margin-bottom: 5px; }
.content { margin-left: 30px;font-style:italic; color:#; }
</style>
<div>
<div class="message">
<div class="image"><img src="http://www.gravatar.com/avatar/df125f7b89730a39163bb17c1c18c1d9?s=18&d=identicon&r=PG" /></div>
<div class="user">Silvertiger</div>
<div style="clear:both;"></div>
<div class="content">Does this work as expected?</div>
</div>
<div class="message">
<div class="image"><img src="http://www.gravatar.com/avatar/98d247dcb9453a0d5adc70cd6b3acde9?s=18&d=identicon&r=PG" /></div>
<div class="user">user2309722</div>
<div style="clear:both;"></div>
<div class="content">Indeed sir it appears to, Thank you</div>
</div>
</div>
Something like this would work:
<div id="thread">
<div class="thread-post">
Post #1 contents
</div>
<div class="thread-post">
Post #2 contents
</div>
<div class="thread-post">
Post #3 contents
</div>
</div>
And for CSS, you would do something like:
.thread-post {
padding: 10px
border-bottom: 1px solid #ddd
}
.thread-post:nth-child(even) {
background-color: #eee /* For distinguishing every other post */
}
Modify as needed.
I would go with one div for each couple author info + message, then, inside of each it would be some kind of floating left div for the box containing author info (username, avatar, etc) (as it is usually seen on forums but the style is up to you) along with another div to contain the linked message.
I did it like this : DEMO
<div class="box">
<div class="list">AAAAAAAAAAAAAAA</div>
<div class="list">BBBBBBBBBBBBBBB</div>
<div class="list">CCCCCCCCCCCCCCC</div>
<div class="list">DDDDDDDDDDDDDDD</div>
</div>
With css as :
.box {
position: absolute;
border: 2px solid grey;
}
.list {
line-height: 30px;
}
.list:not(:last-child) {
border-bottom: 1px solid red;
}
Related
I am trying to create a header box in a bigger box like the one in the image but only have an image to go on.
Any code snippets would be appreciated.
.parent {
border: 1px solid #ddd;
background: #fff;
}
.heading {
padding: 10px;
background-color: #0A7CDD;
color: #fff;
margin-top: 0;
}
p {
color: #333;
font-size: 16px;
padding: 0 10px;
}
<div class="parent">
<h3 class="heading">Other terms</h3>
<p>your text1 will go here,put all the text here.</p>
<p>your text2 will go here,put all the text here.</p>
</div>
Although This is wrong way to ask question, You have to try something yourself, but I was just free so here it is for you.
I offer this help because it looks like you are struggling to get started but you really should take note and analyse the code below and try to understand what each element is doing.
Remember StackOverflow is not a coding service and you will struggle to get help if you don't have a basic knowledge of what you are trying to achieve.
.Box {
display: flex;
flex-direction: column;
}
.Head {
background: #0a7cdd;
color: #fff;
padding: 10px;
}
.Body {
border: 1px solid #ddd;
padding: 10px;
}
<div class="Box">
<div class="Head">
<h2>Other Terms</h2>
</div>
<div class="Body">
<p>My credits must remain intact at the bottom of the auction template.</p>
<p>Please email me with any questions or if you need help with template installation.</p>
</div>
</div>
Key html elements you should look at are:
div
h2
p
Here is a good place to start:
https://www.w3schools.com/tags/tag_div.asp
Not an 100% solution to your "problem", where you straigt up get the solution to your problem, but more of a tip on how you can help yourself solve it.
What I tend to do when translating visuals into code is to "think out loud" what I see and try and transcribe it as well as I can into code. In your case you clearly see a blue header-section and below it a text-section. They are both wrapped inside a box with a border.
By defining these different parts it is fairly easy to get an idea as of how to structure it in code:
<div class="box">
<div class="header-section">
<h1> Header Text </h1>
</div>
<div class="text-section">
<p> Heres some text </p>
</div>
</div>
And then you go ahead and style it as you like.
I have a box like this:
<section class="notes-list-box">
<div class="nn">
<div class="heading">Notes</div>
<div class="boxdescription">With our complete study notes, your homework is much easier.</div>
</div>
<div class="ttn">
<div class="heading">Things To Know</div>
<div class="boxdescription">Things to know provides additional information on every topic which enhance the knowledge of the students.</div>
</div>
<div class="vdos">
<div class="heading">Videos</div>
<div class="boxdescription">Reference videos on each topic provides experimental ideas and develops interactive learning technique.</div>
</div>
<div class="sqaa">
<div class="heading">Solved Question and Answer</div>
<div class="boxdescription">With 100's of solved questions solved, now you can easily prepare your exam for free.</div>
</div>
</section>
Adding little bit of styling make it looks like this:
I have tried using vertical-align like this:
.notes-list-box > div {
vertical-align: top;
}
and it works. But I don't know how to align vertical at bottom so that all the white space also comes to bottom.
So the white space below notes and solved question and answer white background comes till bottom.
I want to fill those gaps with white space:
Use flexbox.
I used this CSS:
.notes-list-box {
display: flex;
font-family: sans-serif;
}
.notes-list-box > div {
margin: 0 5px;
background-color: white;
}
.heading {
color: white;
font-weight: bold;
padding: 10px 2px;
text-align: center;
}
.boxdescription {
padding: 5px;
}
.nn .heading {
background-color: #61B5DF;
}
.ttn .heading {
background-color: #41AF43;
}
.vdos .heading {
background-color: #FF8A00;
}
.sqaa .heading {
background-color: #FF1F2D;
}
See the result on JSfiddle.
The easiest way to do what you are trying to do is by using the display: table CSS properties.
JS Fiddle Here
HTML
<div class="table">
<div class="table-row">
<div class="heading table-cell">Notes</div>
<div class="heading table-cell">Things To Know</div>
<div class="heading table-cell">Videos</div>
<div class="heading table-cell">Solved Question and Answer</div>
</div>
<div class="table-row">
<div class="table-cell">With our complete study notes, your homework is much easier.</div>
<div class="table-cell">Things to know provides additional information on every topic which enhance the knowledge of the students.</div>
<div class="table-cell">Reference videos on each topic provides experimental ideas and develops interactive learning technique.</div>
<div class="table-cell">With 100's of solved questions solved, now you can easily prepare your exam for free.</div>
</div>
</div>
CSS
.table {
display: table;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
border: 1px solid;
}
.heading {
vertical-align: middle;
text-align: center;
}
Here is an update with styling similar to yours.
Another alternative using jquery. Here is the fiddle.
JQUERY
$('.parentheight').each(function(){
var maxdivheight = 0;
$('.childheight',this).each(function(){
var divheight = $(this).height();
// compare height
if ( divheight > maxdivheight ) {
maxdivheight = divheight;
} else { }
});
// set all divs to max height
$('.childheight',this).height(maxdivheight);
});
HTML
<section class="notes-list-box parentheight">
<div class="alignbox nn childheight">
<div class="heading">Notes</div>
<div class="boxdescription">With our complete study notes, your homework is much easier.</div>
</div>
<div class="alignbox ttn childheight">
<div class="heading">Things To Know</div>
<div class="boxdescription">Things to know provides additional information on every topic which enhance the knowledge of the students.</div>
</div>
<div class="alignbox vdos childheight">
<div class="heading">Videos</div>
<div class="boxdescription">Reference videos on each topic provides experimental ideas and develops interactive learning technique.</div>
</div>
<div class="alignbox sqaa childheight">
<div class="heading">Solved Question and Answer</div>
<div class="boxdescription">With 100's of solved questions solved, now you can easily prepare your exam for free.</div>
</div>
</section>
CSS
.alignbox {
float: left;
width: 24%;
border: 1px solid red;
}
I got it working by setting everything to 100% height like so: http://jsfiddle.net/sur38w6e/
Your html was untouched.
.notes-list-box>div{
float:left;
width:120px;
background-color:yellow;
margin: 5px;
height:100%;
overflow:auto;
}
.heading{
background-color:red;
}
.notes-list-box{
background-color:green;
overflow:auto;
height:100%;
}
body,html{
height:100%;
}
I have the following elements and css in an html file.
HTML
<div id="eastern">All times are Eastern</div>
<div id="calendar-container">
<div id="calendar">
<div id="saturday"> ... </div>
<div id="sunday"> ... </div>
</div>
</div>
<h2>First event</h2>
CSS
#eastern {
text-align:center;
}
#calendar {
width:700px;
margin:auto;
}
#saturday,#sunday {
width:350px;
float:left;
}
For some reason, the <h2> element is floating up along the right side of the #eastern. The browser is acting like the element is completely empty even though it has plenty of content in the #saturdy and #sunday elements. Since #calendar-container isn't being floated I think it should force the <h2> element beneath.
I know I could just fix it using clear:both, but I feel like I'm missing something. Any help? Please? Thanks!!
please don't forget to clear your float inside of "#calendar" by using a simple:
#calendar {
overflow: hidden;
}
Or even better: you use the cleaner version with an additional class "clearfix".
If you do so, you'll get your lost boxmodel of "#calendar" back.
Now you'll be able to position <h2> underneath your calendar.
If you have any further questions feel free to let me know!
Here a full example:
CSS:
#eastern {
text-align:center;
}
#calendar {
width: 700px;
margin: 0 auto;
outline: 1px solid red;
overflow: hidden; /* dirty version if you don't have a
class "clearfix" in your Stylesheet */
}
#saturday,#sunday {
width:350px;
float:left;
}
HTML: (Cleaner Version with class "clearfix")
<div id="eastern">All times are Eastern</div>
<div id="calendar-container">
<div id="calendar" class="clearfix">
<div id="saturday"> ... </div>
<div id="sunday"> ... </div>
</div>
</div>
<h2>First event</h2>
Please try below code where i have added clear class with clear both left and right:
HTML
<div id="eastern">All times are Eastern</div>
<div id="calendar-container">
<div id="calendar">
<div id="saturday"> ... </div>
<div id="sunday"> ... </div>
</div>
</div>
<div class="clear"></div>
<h2>First event</h2>
CSS
#eastern {
text-align:center;
}
#calendar {
width:700px;
margin:auto;
}
#saturday,#sunday {
width:350px;
float:left;
}
.clear{
clear:both;
}
I want to create a photo gallery for one of my projets but I can't achieve it. What I want is something like that :
I don't know how many photo there will be but basically what it does is:
- Insert first photo in photo_div #1
- Insert 2nd in #2
- Goes to new line
- Insert 3rd in #3
- Insert 4th in #4
- Go to next column and first line
- Insert 5th in #5
- etc.
What I've made so far is the following code :
<div id="scroll_container">
<div id="photo_0" class="div_photo">
<!-- More content inside -->
</div>
</div>
And the CSS code :
scroll_container{
height:100%;
width:550px;
overflow-x:scroll;
overflow-y:hidden;
}
.div_photo{
float:left;
width:250px;
height:250px;
border:1px solid black;
margin:0 5px 5px 0;
position:relative;
display:inline-block;
}
But all I can achieve is a two columns gallery with 3 lines.
Could you help me to solve that ?
Thanks
Looks like your images are always of the same size, and that your problem is just the special order that you want.
In that case, this could be a solution:
.test {
width: 40px;
height: 40px;
border: solid 1px blue;
float: left;
margin: 2px;
}
.test:nth-child(4n+3)
{
border-color: red;
position: relative;
top: 44px;
left: -92px;
margin-right: -44px;
}
.test:nth-child(4n+4)
{
border-color: red;
position: relative;
top: 44px;
left: -46px;
margin-right: -44px;
}
fiddle
The idea is to float the first 2 elements, the 5 and 6, and so on. the 3rd and 4th (and 7th and 8th) are positioned relative to take them to the special positions
CSS
.div_photo{
float:left;
width:250px;
height:250px;
border:1px solid black;
margin:0 5px 5px 0;
position:relative;
display:inline-block;
}
.div_photo_1{
float:left;
width:250px;
height:250px;
border:1px solid black;
margin:0 5px 5px 0;
position:relative;
display:inline-block;
}
#scroll_container_1 {
height:auto;
width:257px;
display:inline-block;
}
#scroll_container {
height:auto;
width:514px;
}
#scroll_container_parent {
height:auto;
width:771px;
overflow-x:scroll;
overflow-y:hidden;
}
HTML
<div id="scroll_container_parent">
<div id="scroll_container">
<div id="photo_1" class="div_photo">1</div>
<div id="photo_2" class="div_photo">2</div>
<div id="photo_3" class="div_photo">3</div>
<div id="photo_4" class="div_photo">4</div>
<div id="photo_6" class="div_photo">6</div>
<div id="photo_7" class="div_photo">7</div>
<div id="photo_9" class="div_photo">9</div>
<div id="photo_10" class="div_photo">10</div>
</div>
<div id="scroll_container_1">
<div id="photo_5" class="div_photo_1">5</div>
<div id="photo_8" class="div_photo_1">8</div>
<div id="photo_11" class="div_photo_1">11</div>
</div>
</div>
Modified HTML...may be this should be good
This way you can write your html:
<div id="scroll_container">
<div id="photo_1" class="div_photo">
<!-- More content inside -->1
</div>
<div id="photo_2" class="div_photo">
<!-- More content inside -->2
</div> <div id="photo_3" class="div_photo">
<!-- More content inside -->3
</div> <div id="photo_4" class="div_photo">
<!-- More content inside -->4
</div> <div id="photo_5" class="div_photo">
<!-- More content inside -->5
</div>
</div>
For the 5th one you can apply additional css with id as :
#photo_5 {
display:inline-block;
margin-left:520px;
margin-top:-510px;
}
As you don't want to use table then you can achieve this with css.
Working Fiddle : jsFiddle Working Demo
I know this is amateur stuff but I've been trying and trying to get this right and i can't seem to get a fix.
Please take a look at the website screenshot. I'm attempting to make the "call..." text to be inline and to the right of the best#flooring logo.
Here's the code HTML:
<div class="level0">
<div class="topbar">
<h1><% title_content %></h1> <div class="facebookbutton"></div>
<div class="phonetop">Customer services: <strong>0844 209 1560</strong></div>
</div>
</div>
<div class="header">
<div class="level0">
<div class="logonumber">
<img src="<% secure_url %>images/logo.png?r=1" alt="<% title_content %>" />
<div class="headernumber">
<h2>Call <br /> 01132 186 212 <br />for the best prices</h2></div>
</div>
<div class="headfloat">This contains all of the content located on the right hand side </div>
CSS
.level0{
width:970px;
margin:0px auto;
clear:both;
}
.topbar{
height:41px;
color:#747474;
/*text-shadow: 1px 1px 2px #000;*/
}
.header{
background:#fff;
height:166px;/*was 126*/
}
.logonumber {
float:left;
display:inline-block;
}
.logo{
display:block;
}
.headernumber{}
contains the nav, the card images, basket and search.
Any help would be much appreciated.
You need
.headernumber {
float: left;
}
and you also need to decrease the size of the .headfloat element because its width does not allow all three elements in the same line
so change the .headfloat rule to
.headfloat {
float: right;
padding-top: 13px;
text-align: right;
width: 350px; /*was 460px*/
}