I have the following code:
#superheader {
width: auto;
height: 100px;
position: relative;
}
#superheader p {
font-family: Sansation;
font-size: 50px;
}
#superheader table {
border: solid;
height: 100px;
}
#header {
height: 140px;
box-shadow: 0em 0.5em 0.5em grey;
position: relative;
background-color: #E6E6E6;
padding-left: 70px;
padding-right: 70px;
font-family: sans-serif;
}
.menuelement {
width: 100px;
height: 40px;
text-align: center;
padding-left: 10px;
padding-right: 10px;
float: left;
position: relative;
}
.menuelement:hover {
background-color: dimgrey;
}
#header>a {
line-height: 2.5;
}
<div id="header">
<div id="superheader">
<div style="margin: auto; width: 630px;">
<table>
<tr>
<td><img src="images/memoji.png" width="100px" height="100px" alt="Icon"></td>
<td>
<p>A TITLE</p>
</td>
</tr>
</table>
</div>
</div>
<a href="template.html">
<div class="menuelement">Page1</div>
</a>
<a href="index.html">
<div class="menuelement">Page2</div>
</a>
<a href="not_found.html">
<div class="menuelement">Page3</div>
</a>
</div>
The table in this example should be 100px in height, however it won't get smaller than 170px.
Where is my mistake?
Well, actually you can't control height or width of the elements with display: table; because by default if their cells height or width is larger than the height or width of the element with display: table; the element will grow. So you need to control the dimension of the cells instead of the table itself.
In your particular case, there are two approaches to overcome this situation.
Controlling the cells: since you used p tag in your table and this tag has a default margin of 1em on top and bottom you can simply override it and because the inner cells are no longer larger than the table itself you can control its dimensions (As long as they do not smaller than cells). Also, keep in mind the font-size and line-height will make your cells bigger than usual, but if you want to keep them as it is, you should drop the default margin.
p {
font-family: Sansation;
font-size: 50px;
margin: 0;
}
table {
border: solid;
height: 100px;
}
<table>
<tr>
<td><img src="images/memoji.png" alt="Icon"></td>
<td>
<p>A TITLE</p>
</td>
</tr>
</table>
Using display: block;: You can simply override the display of the table and make it work as block but you still need to control the inner elements to do not override the table itself. Also, keep in mind you should control the width of the table also because block element by default will fill the available space.
p {
font-family: Sansation;
font-size: 50px;
margin: 0;
}
table {
border: solid;
height: 100px;
display: block;
}
<table>
<tr>
<td><img src="images/memoji.png" alt="Icon"></td>
<td>
<p>A TITLE</p>
</td>
</tr>
</table>
Add the border-spacing: 0px; to your table style to remove spaces between cells:
#superheader table{
border: solid;
height: 100px;
border-spacing: 0px;
}
and then remove white spaces inside cells:
td, td *{
display: table-cell;
margin: 0px;
padding: 0px;
}
Related
After two month of learning to code I've decided to code a simple bug-tracker on my own with no code-along videos. Managed to do a JS-part, but now I am really stuck on the problem of div overflowing its container and its quite a specific one.
Here is an image of result I've got.
I'll leave html and css samples down.
Add task shows modal and creates a card. Cards are always firstly added to backlog section and can be dragged between columns.
As I create more then two cards with tasks they overflow their container. I planned tbody "#task-list" to be scrollable, but not the whole body or container. I've tried limiting every container's height - it still overflows. I've tried adding "overflow: scroll" onto tbody "#task-list" and on its child tr - no effect, nothing changed. It stops to overflow only if I add "overflow: scroll" onto "#task-list" tr td div. But then I get scrollbar on every column, which is not what I wanted. What is the reason I cant make content of tbody "#task-list" stay in container and be scrollable?
<main class="main">
<side class="sidebar">
<div class="main-tabs">
<div class="overview">Overview</div>
<div class="my-tasks">My Tasks</div>
<div class="projects">My Projects</div>
<div class="reports">Reports</div>
</div>
<div class="technical-tabs">
<div class="settings">Settings</div>
<div class="logout">Log out</div>
</div>
</side>
<div class="content" >
<div class="project-name">Project Name</div>
<div>Add a Task</div>
<button id="add-btn" class="add-task">+</button>
<table class="tracker-board" id="overview">
<thead>
<tr>
<th>Backlog</th>
<th>To Do</th>
<th>In Progress</th>
<th>Done</th>
</tr>
</thead>
<tbody id="task-list">
<tr>
<td id="backlog-list"><div class = "card-holder empty"></div></td>
<td><div class="empty"></div></td>
<td><div class="empty"></div></td>
<td><div class="empty"></div></td>
</tr>
</tbody>
</table>
</div>
</main>
The div with class "card-holder" gets another div ".card" when task is created.
/* Main Content */
.main {
background-color: #fff;
color: var(--secondary-color);
width: 90%;
max-height: 800px;
margin: 20px auto;
border-radius:20px;
display: grid;
grid-area: main;
grid-template-areas:
"side tracker";
grid-template-columns: 1fr 5fr;
}
/* Tracker Window */
.content {
grid-area: tracker;
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
height: 600px;
}
.content > div {
font-size: 28px;
font-weight: 600;
margin-top: 10px;
}
.add-task {
width: 80px;
padding: 3px;
border-radius: 8px;
font-weight: 700;
background: var(--primary-color);
color: #fff;
cursor: pointer;
font-size: 24px;
font-weight: 30px;
}
.tracker-board {
height: 500px;
width: 100%;
overflow: auto;
}
.tracker-board #task-list {
height: 100%;
font-size: 20px;
}
#task-list > tr {
height: 600px;
width: 100%;
overflow: auto;
}
thead th{
font-size: 24px;
border-bottom: var(--secondary-color) solid 2px;
max-width: 250px;
}
tr > td {
padding: 0;
width: 260px;
}
td .empty {
height: 100%;
}
#task-list td > div {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
flex: 1 0 250px;
}
.card-holder {
height: 100%;
}
.card {
margin:15px;
border: var(--secondary-color) 2px solid;
color: var(--secondary-color);
border-radius: 20px;
box-shadow: -5px 10px 10px rgba(0, 0, 0, 0.3);
font-size: 24px;
font-weight: 500;
max-width: 250px;
}
I'll be grateful if you point out any other mistakes I made as well. Thanks!
You can try to separate the header and contents of the table into different entities (create different tables for the two).
I'm trying to make a table with only images in the table without any sort of padding or border (totally seamless) and can get vertical with no border/padding/spacing at all… however, the horizontal: there are gaps and spaces… no matter what I try… sorry I couldn't find an answer regarding this. Excuse the messy code, please!
table {
border-collapse: collapse;
vertical-align: top;
margin-left: auto;
margin-right: auto;
}
table.a {
table-layout: auto;
width: 1000px;
height: 600px;
margin-right: 100%;
margin-left: 0%;
}
td {
padding: 0px;
text-align: left;
}
img {
vertical-align: top;
padding: 0px;
}
tr.spaceUnder>td {
padding-bottom: 0px;
border: none;
padding: 0px;
}
<table class="a">
<tr class="spaceUnder">
<td>
<img src="mcu.jpg" alt="info">
</td>
<td><img src="fill1.jpg"></td>
</tr>
<tr class="spaceUnder">
<td><img src="fill2.jpg"></td>
<td><img src="mcu41.jpg"></td>
</tr>
<tr class="spaceUnder">
<td><img src="fill3.jpg"></td>
<td><img src="news.jpg"></td>
</tr>
</table>
you have already set the height and width of a class element of table class
Change the width and height to auto:
table.a {
table-layout: auto;
width: auto;
height: auto;
margin-right: 100%;
margin-left: 0%;
}
check :
https://jsfiddle.net/sugandhnikhil/q8m1n57h/1/
Use border and padding in td to get border and spacing
table td {
border: 1px solid;
padding: 5px;
background: #333;
}
For Bootstrap add class for table table-bordered
<table class="table-bordered"></div>
SOLVED.
This is an example:
HTML:
<table>
<tbody>
<tr style="height: 100%;">
<td class="lefttd">
<img src="http://www.numbeo.com/images/Menu1.svg">
</td>
<td></td>
<td class="righttd"><img src="http://www.online-utility.org/icons/gear_64.png" style="margin-right: 0.5em;">Online-Utility.org </td>
</tr>
</tbody>
</table>
CSS:
table {
border-bottom: 1px solid black;
border-spacing: 0;
background-color: #bcf;
width: 100%;
}
table > tr, table > tr > td {
padding: 0;
margin: 0;
border: 0;
border-spacing: 0;
}
.lefttd {
height: 100%;
vertical-align: middle;
}
.righttd {
width: 95%;
height: 32px;
text-align: right;
font-size: 22px;
line-height: 30px;
vertical-align: middle;
}
a.mmenu {
border: 0;
text-decoration: none;
background-color: #aaa;
height: 100%;
vertical-align: middle;
display: inline-block;
}
img {
width: 32px;
border: 0;
text-decoration: none;
vertical-align: middle;
}
https://jsfiddle.net/adamovic/sw6c3z91/
In Chrome I see this table computed with height 35px... What causes this table to grow height more than 32px and how to fix it?
Add vertical-align: middle; to your image
<img src="http://www.online-utility.org/icons/gear_64.png" style="width: 32px; margin-right: 0.5em; vertical-align: middle;">
Also, you shouldn't be inlining styles like this. It's a terrible practice. Uses classes and stylesheets instead.
Edit: you can try a few other values too. It looks like vertical-align:bottom might work even better. It appears with the font size and line height that that will get you closer to 32px. With middle it's at about 33px
The problem is solved. I haven't properly marked to img vertical-align: middle and also padding: 0 to tr/td.
I am creating a web page with 2 <div>s side by side. Each <div> will have 2 sections.
I want to center them (bring them to the middle of the <div>). I am trying to make this <div> responsive. In the website, 2 <div>s will be in one line, while in mobile one <div> will appear on one line and the other <div> will appear on a second line. I am trying to center the image and text of each section.
How can I accomplish that?
.wrapper {
width: 100%;
overflow: hidden;
}
.wrapper div {
min-height: 45px;
padding: 1px;
}
#one {
background-color: gray;
float: left;
width: 50%;
}
#two {
background-color: red;
overflow: hidden;
min-height: 45px;
}
#media screen and (max-width: 400px) {
#one {
float: none;
margin-right: 0;
width: auto;
border: 0;
}
}
<div class="wrapper">
<div id="one">
<img src="http://livebodybuilding.com/images/fast-delivery.png" height="26" width="55" style="float:left; margin-top: 6px;" />
<p style=" font-size:13px; color:#fff; line-height:1.5; font-family: 'Montserrat',sans-serif;"><strong> FREE DELIVERY </strong>ORDERS OVER $100</p>
</div>
<div id="two">
<img src="http://livebodybuilding.com/images/free-gift.png" height="26" width="31" style="float:left; margin-top: 6px;" />
<p style="font-size:13px; color:#fff; line-height:1.5; font-family: 'Montserrat',sans-serif;"><strong> FREE GIFT</strong> ORDERS OVER $100</p>
</div>
</div>
My fiddle: https://jsfiddle.net/4okxw32v/
First of all, the use of floats in layout design is discouraged. It is generally not a good way of doing things, and usually if you're having a layout issue it comes down to a float problem. Instead you should use the display: inline-block setting. When using inline-block there are a couple of things to take into consideration.
Any white space between elements will be shown. To combat this you can set font-size: 0 on the wrapper and then set font-size: 1rem on the children. This will set the font size in the content to the same size as that of the html selector.
You can prevent line-breaking if you set white-space: nowrap on the parent and then set white-space: initial on the children.
Next instead of adding an image and floating it inside the child you can use the css pseudo element ::before (or css2 :before) on the text container inside the element.
Finally to center the contents use text-align: center on the parent
*, *::before, *::after {
box-sizing: border-box;
}
html,
body {
padding: 0px;
margin: 0px;
}
.wrapper {
font-size: 0;
}
.wrapper div {
font-size: 1rem;
min-height: 45px;
padding: 1px;
text-align: center;
font-size: 13px;
color: #fff;
line-height: 1.5;
font-family: 'Montserrat', sans-serif;
overflow: hidden;
display: inline-block;
width: 50%;
}
#one {
background-color: gray;
}
#one p:before {
content: "";
display: inline-block;
width: 4em;
height: 2em;
background-image: url(http://livebodybuilding.com/images/fast-delivery.png);
background-size: cover;
vertical-align: middle;
margin-right: 5px;
}
#two {
background-color: red;
overflow: hidden;
min-height: 45px;
}
#two p:before {
content: "";
display: inline-block;
width: 2.5em;
height: 2em;
background-image: url(http://livebodybuilding.com/images/free-gift.png);
background-size: cover;
vertical-align: middle;
margin-right: 5px;
}
#media screen and (max-width: 620px) {
.wrapper div {
width: 100%;
}
}
<div class="wrapper">
<div id="one">
<p><strong>FREE DELIVERY</strong> ORDERS OVER $100</p>
</div>
<div id="two">
<p><strong>FREE GIFT</strong> ORDERS OVER $100</p>
</div>
</div>
I want to have a small, either 1 or 2 pixel line down part of the middle of my page to seperate navigation text from content. I want the line to fade to the background color (okay, just fade transparent) at the top and bottom of the line, but I want the middle, solid black part of the line, to expand with the size of the content div on the right.
Is that confusing to read, do I need to elaborate?
EDIT: I've done everything with a table now, I figure that'll be easier. Now my problem is getting the middle part of the line to expand with the other table cell named "content". Everything works with the exception of the sep_mid cell, because I don't want to set a fixed height for the cell, I want it to size based on the "content" cell.
Here's my code:
HTML:
<body>
<div id="wrapper">
<table align="center">
<tr>
<td class="nav" rowspan="3"><p>test</p></td>
<td class="sep_top" rowspan="1"></td>
<td class="content" rowspan="3"><p>Content here!</p></td>
</tr>
<tr> <td class="sep_mid" rowspan="1"></td> </tr>
<tr> <td class="sep_bot" rowspan="1"></td> </tr>
</table>
</div>
</body>
CSS:
body {
background-color: #bbc2c7;
background-image: url('/images/bg.png');
background-repeat: repeat-x;
}
body p {
font-family: Delicious;
}
#font-face {
font-family: "Delicious";
src: url('/fonts/delicious.ttf');
}
#font-face {
font-family: "Delicious";
src: url('/fonts/delicious_bold.ttf');
font-weight: bold;
}
#wrapper {
margin: 0 auto;
width: 1000px;
}
#wrapper p {
font-weight: bold;
font-size: 16px;
font-family: Delicious;
}
.nav {
text-align: right;
padding-right: 20px;
}
.sep_top {
background-image: url('/images/sep_top.png');
background-repeat: no-repeat;
float: left;
padding: 0px;
margin: 0px;
width: 1px;
height: 15px;
}
.sep_mid {
background-color: #000;
float: left;
padding: 0px;
margin: 0px;
width: 1px;
}
.sep_bot {
background-image: url('/images/sep_bot.png');
background-repeat: no-repeat;
padding: 0px;
margin: 0px;
width: 1px;
height: 15px;
}
.content {
padding-left: 20px;
}
table {
border-collapse: collapse;
}
table td {
border-collapse: collapse;
}
I think the empty table cells should contain at least some content, even if it's just