CSS - Styling table - html

i need to make something like this:
I am not 100% sure how to make this so i decide for table which can be usefull, but it just terrible scatter what i did, my try looks like:
<table>
<tr>
<td rowspan="2" class="img-position"><img src="images/foto.png"></td>
<td class="topic-name">Název topicu nebo článku </td>
<td class="date">28.8.2014 / 19:30</td>
</tr>
</table>
My CSS:
#sub-content .left{
width: 326px;
height: 145px;
display: inline-block;
float:left;
}
#sub-content img{
width: 122px;
height: 121px;
display: inline-block;
margin-top: 0px;
margin-left: 5px;
}
#sub-content .topic-name{
width: 150px;
height: 14px;
line-height 14px;
margin-bottom: 130px;
margin-left: 10px;
display: inline-block;
vertical-align: top;
text-decoration: underline;
font-weight: 14px;
}
#sub-content table{
width:326px;
height:145px;
}
#sub-content tr{
margin: 10px 0px 0px 0px;
padding: 0px;
height: 36px;
}
#sub-content .date{
}
#sub-content .img-position{
margin: 0px;
padding: 0px;
width: 122px;
height: 121px;
display: inline-block;
}
And i cant move from my position to style atleast one of that part and then just copy it 3 times. I hope i find somebody here who can help me to fix it.
Live preview can be found on: http://funedit.com/andurit/try1/
Thanks for reading my post

First of all I recommend you to read this : Why not use tables for layout in HTML? its about how you should not create your layout.
I prepared you basic jsfiddle example with your given stuff to make you catch up on things faster. Check this out. Example layout
I changed your given layout to divs and spans and it would look more or less like this:
<div class='article-container'>
<div class='article'>
<div class="img-position">
<img src="http://funedit.com/andurit/try1/images/foto.png"/>
</div>
<span class="topic-name">Název topicu nebo článku </span>
<span class="date">28.8.2014 / 19:30</span>
</div>
.
.
.
</div>

Doing this in tables NON Semantic and I not recommend it.
For my opinion you need to use this structure
Html
<div class="block1">block1</div>
<div class="block2">block2</div>
<div class="block3">block3</div>
</div>
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
width: 100%;
}
.wrapper{
width: 100%;
background: #ddd;
}
.block1{
float: left;
width: 33.3%;
background: #c01;
height: 200px;
margin-right: 1px;
}
.block2{
float: left;
width: 33.3%;
background: #c01;
height: 200px;
margin-right: 1px;
}
.block3{
float: left;
width: 33.3%;
background: #c01;
height: 200px;
}

Use bootstrap grids, to achieve tabular style. It's responsive and easy to implement.
Include this CSS file.
<div class='row'>
<div class='col-xs-4 tab'> <!-- 1/3rd size of the parent container -->
<div class='row'>
<!-- Image box -->
<div class='col-xs-4'>
<img src="images/foto.png">
</div>
<!-- Description box -->
<div class='col-xs-8'> <!-- 2/3rd size of parent container -->
<div>Název topicu nebo článku </div>
<div>28.8.2014 / 19:30</div>
<div>Lorem Ipsum</div>
</div>
</div>
</div>
<div class='col-xs-4 tab'> <!-- 1/3rd size of the parent container -->
<div class='row'>
<!-- Image box -->
<!-- ... Follow same structure as above-->
</div>
</div>
<div class='col-xs-4 tab'> <!-- 1/3rd size of the parent container -->
<div class='row'>
<!-- ... Follow same structure as above -->
</div>
</div>
</div>
This will give you 3 columns, in a row of equal width.
For fixed height of each tab, just provide
<style>
.tab{
height: 200px;
}
</style>
For implementation details, See here.

Related

How to get this div with floats responsive?

I made an small html field and now I'm trying to get it responsive.
To make it clear, I made an picture how the fields should move when it's displayed on a smaller screen.
How it should be
After figuring out a few hours I got this solution, whichs works fine on the Desktop but not on a smaller screen. The Logo is not moving to the top but remains on the left side.
Can someone help me with this?
Here is the code:
<div style="background-color: orange; color: white; width: 30%; padding: 4px 4px; text-align: center; margin:0">Stackoverflow</div>
<div style="background-color: #f9f9f9; border: 2px solid orange; max-width:800px; overflow: auto;">
<div style="float: left;width: 30%; overflow: auto;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7A3wAuudoXw8butMA-wxJdWYdUlNbWjC6EOV3iXnrUf08dwX3PA" /></div>
<div style="float:left;width:70%">
<div style="text-align: center; font-size: 12pt; background-color:lightgreen">Some Informations
</div>
<div>
<div style="float: left; background-color: lightblue; width:50%">
<ul>
<li>Owner: Stack Exchange, Inc.</li>
<li>Available in: Englisch, Spanisch, Russian, Portuguese ...</li>
<li>Type of site: Knowledge markets</li>
</ul>
</div>
<div style="float: right; background-color: lightgrey; width:50%; padding:5px">
<ul>
<li>Website: stackoverflow.com</li>
<li>Commercial: Yes</li>
<li>Registration: Optional</li>
</ul>
<div style="float: left; width: auto; background-color:yellow">Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming.
</div>
<div style="clear:both;text-align: center;"> <input type="button" value="Go to the Website" />
</div>
</div>
</div>
In order to change styles according to the screen resolution you can use a media query
#media (max-width: 1024px) {
.logo{
width: 100%;
}
}
Add classes to your elements in order to be able to target them with specific css rules:
<div style="float: left;width: 30%; overflow: auto;">
Becomes
<div class = "logo">
...
<style>
.logo{
float: left;
width: 30%;
overflow: auto;
}
</style>
You can't do responsive with inline styles. Once you have your styles separate, you can you use #media queries to style elements based on screen size
* {
box-sizing: border-box;
}
.tab {
background-color: orange;
color: white;
width: 30%;
padding: 4px 4px;
text-align: center;
margin: 0
}
.wrapper {
background-color: #f9f9f9;
border: 2px solid orange;
max-width: 800px;
overflow: auto;
}
.logo {
text-align: center;
}
#media (min-width: 640px) {
.logo {
float: left;
width: 30%;
overflow: auto;
}
.main {
float: left;
width: 70%
}
}
.row:before,
.row:after {
display: table;
content: " ";
}
.row:after {
clear: both;
}
.row {
margin-left: -5px;
margin-right: -5px;
margin-bottom: 5px;
}
.col {
margin: 0 5px;
width: calc(50% - 10px);
}
.col-left {
float: left;
background-color: lightblue;
}
.col-right {
float: right;
background-color: lightgrey;
padding: 5px
}
.highlight {
float: none;
width: auto;
background-color: yellow;
margin-bottom: 10px;
}
<div class="tab">Stackoverflow</div>
<div class="wrapper">
<div class="logo"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7A3wAuudoXw8butMA-wxJdWYdUlNbWjC6EOV3iXnrUf08dwX3PA" /></div>
<div class="main">
<div style="text-align: center; font-size: 12pt; background-color:lightgreen">Some Informations
</div>
<div class="row">
<div class="col col-left">
<ul>
<li>Owner: Stack Exchange, Inc.</li>
<li>Available in: Englisch, Spanisch, Russian, Portuguese ...</li>
<li>Type of site: Knowledge markets</li>
</ul>
</div>
<div class="col col-right">
<ul>
<li>Website: stackoverflow.com</li>
<li>Commercial: Yes</li>
<li>Registration: Optional</li>
</ul>
</div>
</div>
<div class="highlight">Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming.
</div>
<div style="clear:both;text-align: center;">
<input type="button" value="Go to the Website" />
</div>
</div>
<!-- /.main -->
</div>
<!-- /.wrapper -->
Your HTML structure is not that bad, even though it will be better if your style code was inside a .css file, if is that the case try it.
Anyways, in your mobile structure you have 3 main containers, I will called:
main-container
image-container
content
Your main-container has image-container and content inside, but both has a villain, in your case that is float: left, this thing will set everything to be on left of themselves an others objects around them.
I will suggest you to change your float: left and start to work with display: flex, you can find tons of information in the internet about it, to help you to construct very polish structures that will obey to any rule that you will build to them.
Thank you guys, I made a solution out of your answers.
I made it with display:flex, flex-wrap:wrap and #media.
For this I seperated the whole "body of the box" into a Logo container and a text fields container (almost like before) and gave both flex attributes. In the text fields I used float (like before).
For smaller screens I changed the flex-direction to column and now it works how I wanted it.

Keeping wrapper container a certain percentage of body

I'm having a tough time keeping my content centered within a certain width on my personal website. I have tried many methods such as setting body to a fix width and my wrapper container to a percentage of that. I have attached a picture of my website here and highlighted where I want my content to be contained in the picture shown
.
I want my content of my website centered within that highlighted area, while at the same time keeping the background to be the full size of the screen.
I realize this may be a simple question for many, but I have spent all day looking for and trying out different methods to do this with no avail.
body {
background-color: #F0f0f0;
text-align: center;
margin-right: 0px;
margin-left: 0px;
}
.wrapper {
text-align: center;
}
.topSection {
height: 300px;
border: solid 5px;
}
.mainAbout {
padding-left: 50px;
padding-right: 50px;
vertical-align: middle;
}
.mainAbout h1 {
font-size: 60px;
font-family: arvo, sans-serif;
margin-bottom: 5px;
}
#leftBrace {
vertical-align: middle;
}
#rightBrace {
vertical-align: middle;
}
.projects {
height: 864px;
border: solid 5px;
margin-top: 2px;
background: #0F1217;
}
.projects h2 {
color: #e6e6e6;
font-family: arvo, sans-serif;
font-size: 50px;
}
<link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
<div class="wrapper">
<!---- Wrapper Starts Here --->
<div class="topSection" style="display:block" ;>
<!---- Name Section Starts Here --->
<div id="leftBrace" style="display: inline-block" ;>
<img src="leftbrace.png">
</div>
<div class="mainAbout" style="display: inline-block" ;>
<!--- Main Name and About me Section ---->
<h1> Benjamin Yan </h1>
<p> I am a Senior Year Computer Science student at Sacramento State <br> University, California. I strive to become a professional Web Developer. </p>
</div>
<!--- End mainAbout --->
<div id="rightBrace" style="display: inline-block" ;>
<img src="rightbrace.png">
</div>
</div>
<!--- Wrapper Ends Here --->
<div class="projects">
<h2> Projects </h2>
</div>
<div class="contact">
</div>
</div>
<!--- Wrapper Ends Here --->
<footer>
</footer>
Instead of using background you could style curly-braces using pseudo selector :before and :after, thus it works like font styling, you could use transform:translate to center your intro text container, check below codes.
#box {
width: 100%;
height: 300px;
overflow: hidden;
background: #ccc;
}
#box > .cnt {
width:50%;
text-align: center;
top: 50%;
left: 50%;
position: relative;
transform: translate(-50%, -50%);
}
#box:before {
content:"{";
font-size: 250px;
position: absolute;
top: 0;
left:10%;
}
#box:after {
content: "}";
font-size: 250px;
position: absolute;
top: 0;
right:10%;
}
<div id="box">
<div class="cnt">
<h1> Benjamin Yan </h1>
<p> I am a Senior Year Computer Science student at Sacramento State <br> University, California. I strive to become a professional Web Developer. </p>
</div>
</div>
Apply margin: 0 auto; to your content class. This will work.
You need to make sure add an inner class inside each wrapper and define your desired width. And need to apply margin: 0 auto to the inner. I added demo snippet.If u want specific wrapper full width just remove innerclass that's enough you will get full width. I hope it will help you.
.wrapper {
height: 300px;
width: 100%;
background: orange;
margin-bottom: 20px;
}
.inner {
width: 70%;
margin: 0 auto;
background: pink;
height: 100%;
}
<div class="wrapper">
<div class="inner"></div>
</div>
<div class="wrapper">
<div class="inner"></div>
</div>
<div class="wrapper">
<div class="inner"></div>
</div>
<div class="wrapper">
<div class="inner"></div>
</div>

Responsive text fixed positioning with Button

http://i.imgur.com/Veauoig.png
I am currently trying to work out how to make the 'From £' text to keep in the same position as the buttons above. The page is responsive so I have been unable to keep the text in one position.
The CSS I have used so far -
element.style {position: absolute; width: 97%;}
I put each of the 'From £' parts in their own class. Not sure if there is an easier way?
<div class="price2">From £300</div>
Any help would be great. Thanks!
Add a container for the element for the price and button so that they remain in context with each other.
http://jsfiddle.net/05orkj1a/
.prices{
width: 100%;
}
.price-column{
display: table-cell;
width: 33%;
text-align: center;
margin: 0 auto;
padding: 0 5px;
}
<div class="prices">
<div class="price-column">
<button>Bass</button>
<div class="price2">From £65</div>
</div>
<div class="price-column">
<button>Mid</button>
<div class="price2">From £300</div>
</div>
<div class="price-column">
<button>Treble</button>
<div class="price2">From £715</div>
</div>
</div>
You could also Float the columns left to cause them to collapse vertically as the screen shrinks with the same html. Just change the margin or padding depending on how far apart you want them spaced
http://jsfiddle.net/z6agt11e/
.prices{
width: 100%;
overflow: hidden;
}
.price-column{
display: block;
float: left;
text-align: center;
padding: 5px 5px;
}
You can also add an outer container and then create a inner container for each button-price set.
Here is the HTML code:
<div class="outter">
<div class="block">
<div class="button">button1</div>
<div class="price2">From £65</div>
</div>
<div class="block">
<div class="button">button2</div>
<div class="price2">From £300</div>
</div>
<div class="block">
<div class="button">button3</div>
<div class="price2">From £715</div>
</div>
</div>
Here the CSS:
.outter{
width:100%;
}
.block{
width:33%;
background-color: yellow;
float:left;
text-align: center;
}
And here a jsfiddle:
http://jsfiddle.net/SoniaGM/ej4mdwx9/1/
Hope it helps.
You can use the CSS3 ::after pseudo-selector.
Give at button class:
position: relative;
Then you have to write something lime this:
.button-class::after {
content: 'From £300';
background: transparent;
height: 1%;
width: 3%;
position: absolute;
top: 20px;
left: 0px;
}
Obviously, you have to change height: 1%; width: 3%; and top: 20px; left: 0px;with whatever you want!

HTML & CSS Line up right aligned elements inside and outside of a (sometimes) scrollable div

i have a legend for a graph that sometimes is scrollable and sometimes isn't.
Unfortunately when the scrollbar shows up, it pushes all of the elements over to the left a bit. So they don't line up with a total (outside the scrollable area)
Example: http://jsfiddle.net/3sKVR/
A simple answer would be to just set a fixed width, but unfortunately, it has to be responsive.
Also, i can't use custom scrollbars to maintain consistency with the rest of the site and also bring down page-load times.
Any help would be greatly appreciated (with internet points!)
Cut down version of code:
HTML:
<div id="legend_cont">
<div id="legend_list">
<div id="legend">
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#ffb100"></div>
</div>
<div class="legend_cell">Merch G</div>
<div class="legend_cell legend_value">$1423.24</div>
</div>
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#ed5929"></div>
</div>
<div class="legend_cell">Merch L</div>
<div class="legend_cell legend_value">$1351.07</div>
</div>
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#3f9c35"></div>
</div>
<div class="legend_cell">Merch N</div>
<div class="legend_cell legend_value">$1194.90</div>
</div>
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#009bbb"></div>
</div>
<div class="legend_cell">Merch T</div>
<div class="legend_cell legend_value">$1188.14</div>
</div>
</div>
</div>
<div id="legend_total">Total:<span id="legend_total_value">$0.00</span>
</div>
</div>
CSS:
#legend_cont {
height: 100%;
border-left: 2px solid #ADADAD;
width: 40%;
float: right;
}
#legend_list {
height: 169px;
overflow: auto;
margin: 20px 4% 20px 7%;
}
#legend {
display: table;
width: 90%;
}
.legend_row {
display: table-row;
}
.legend_cell {
display: table-cell;
padding: 5px;
vertical-align: middle;
}
.legend_colour {
width: 10px;
height: 20px;
background-color: #c1c1c1;
border-radius: 3px;
}
.legend_value {
text-align: right;
}
#legend_total {
height: 50px;
line-height: 50px;
width: 88%;
border-top: 1px solid;
margin-left: 8%;
}
#legend_total_value {
float: right;
padding-right: 5px;
}
1) Make sure there is always a scroll bar
CSS
#legend_cont {
overflow-y: scroll;
}
2) Use js to grab the variable width of the scrollbar (example here)
3) Set the padding-right in #legend_total_value equal to that variable in jquery.
JS
$('#legend_total_value').css('padding-right', wScroll);​
Try applying padding-right to compensate for the size of scrollbar when it's not there and position the total accordingly.
#legend_list {
height: 169px;
overflow: auto;
margin: 20px 4% 20px 7%;
padding-right:15px;
}
Demo

where the margin gone?

I have the following html/css code: http://jsfiddle.net/J3YZ8/4/
HTML:
<div id="headerDiv">HeaderPanel</div>
<div id="bodyDiv">
<div id="loginContainer">LoginPanel</div>
<div id="contentContainer">Content</div>
<div id="menuContainer">MenuPanel</div>
</div>
<div id="footerDiv">FooterPanel</div>
CSS:
* {
padding: 0px;
margin: 0px;
}
html {
height: 100%;
}
body {
direction: rtl;
height: 100%;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 75%;
}
#headerDiv {
height: 20%;
margin-bottom: 1%;
}
#footerDiv {
height: 10%;
margin-top: 1%;
}
#headerDiv,
#footerDiv {
clear: both;
background-color: #FF5500;
}
#bodyDiv {
height: 68%;
margin: 0% 2%;
}
#loginContainer {
background: green;
margin-bottom: 1%;
}
#menuContainer {
background: blue;
margin-top: 1%;
}
#loginContainer,
#menuContainer {
display: inline-block;
width: 29%;
margin-left: 1%;
height: 49%;
}
#contentContainer {
width: 69%;
height: 100%;
background: yellow;
float: left;
margin-right: 1%;
}
If you use this code on your browser (without jsfiddle) you will see there is no margin between the blue div (menuContainer) and the footer. In jsfiddle the margin is not equal to the margin between the yellow div (contentContainer) and the footer although it should be the same. How can I fix it?
More details:
this is image from jsfiddle result:
this is image from full screen result:
Does anyone knows how to fix it??
I do see a margin below the blue panel.
A height of 100% the html element does not mean "not higher than the window". If you don't want to scroll the page you could set overflow:hidden on the html. But then you won't see the footer.
<div id="headerDiv">HeaderPanel</div>
<div id="bodyDiv">
<div id="loginContainer">LoginPanel</div>
<div id="contentContainer">Content</div>
<div id="menuContainer">MenuPanel</div>
</div>
</div>
<div id="footerDiv">FooterPanel</div>
One of the main problems is that you have a second closing div with no opening - this can through IE in quirks mode and also cause other issues when working with floats and clears in CSS.
<div id="headerDiv">HeaderPanel</div>
<div id="bodyDiv">
<div id="loginContainer">LoginPanel</div>
<div id="contentContainer">Content</div>
<div id="menuContainer">MenuPanel</div>
</div>
<div id="footerDiv">FooterPanel</div>
Above is corrected code that should fix it - at least a start.
Are you looking to build a fluid height and width layout?
Also you need to clear the floats before you start the footer.
<div id="headerDiv">HeaderPanel</div>
<div id="bodyDiv">
<div id="loginContainer">LoginPanel</div>
<div id="contentContainer">Content</div>
<div id="menuContainer">MenuPanel</div>
</div>
<div style="clear:both;"></div>
<div id="footerDiv">FooterPanel</div>
There is a working sample of the code maintaining your margin.