CSS - making a div to have same width as the parent - html

I have a page which is split into 3 main parts, header, inner body, and footer as noted in the css code. i'm trying to make the page responsive and fit into a 420px max width screen, so i used a media query for this, however when i do that, the inner body's width is smaller than the width of the footer and the header, it doesnt match, but rather way too small, i would like to make it fit the overall width of the page.
#media screen and (max-width:430px) {
//header:
div.logo {
width: 900px;
height: 400px;
background-color: rgb(147, 235, 238);
-ms-flex-item-align: center;
}
.content {
width: 100%;
height: 100vh;
padding: 0;
}
//inner body
div.inner-body {
height: auto;
border-style: solid;
margin-top: 15px;
margin-bottom: 15px;
width: 235%;
position: relative;
}
div.navi {
width: 900px;
font-size: 28px;
padding-bottom: 90px;
}
form {
font-family: Verdana, Geneva, Tahoma, sans-serif;
align-items: center;
border-radius: 40px;
width: 525px;
height: 700px;
background-color: rgb(99, 198, 223);
box-shadow: 0px 15px 20px rgba(0,0,0,0.5);
margin-top:500px
}
.userlogo {
width: 200px;
border-radius: 100px;
margin-top: -35px;
}
.area {
width: 280px;
height: 30px;
border-radius: 20px;
font-size: 25px;
padding: 5px;
font-style: oblique;
}
.btn {
width: 400px;
height: 60px;
font-size: 30px;
border-radius: 20px;
background-color: rgb(54, 88, 238);
cursor: pointer;
}
//footer
footer {
display: block;
width: 900px;
padding: 0;
list-style: none;
background-color: rgb(126, 226, 230);
font-size: 20px;
height: 300px;
}

First of all you are trying to use logo with width: 900px when your screen max-width:430px. Try to avoid using px and use % or rems, and than your design will be much more responsive. Anytime you are using pixels, you always need to be sure that everything fits perfectly and you need to write the code for any occasion when % or rems will help you to adjust the sizes by themselves.
Also use box-sizing: border-box; in your body. In that way padding and border are included in the width and height, so you will have more control.

Related

I'm trying to round a image and the top of the circle isn't rounding. I believe it's due to a padding issue but I need the padding for spacing

problem photo
I'm trying to make this image a circle I believe I might have too much padding. When I adjust the border-radius it doesn't round correctly. I have added the html and a link to see the problem.
button
{
background-color: #433966;
border: 5px solid #5d596a;
border-radius: 10px;
box-shadow: 8px 8px 8px rgba(65, 62, 62, 0.2);
margin: 0px auto;
display: block;
color: rgb(205, 187, 162);
font-size: 20px;
padding: 15px 20px;
transition: all 300ms ease;
text-align: justify;
font-weight: bold;
font-family: Optima;
}
img
{
border-radius: 50%;
perspective: 8px;
padding-bottom:5%;
padding-top: 20%;
border-color: silver;
width: 300px !important;
height: 300px !important;
}
<div class="fade-in-image">
<img src="images/rachel.jpg" alt="Avatar" class="center"
width= 100%>
<button>Portfolio</button>
</div>
You should wrap your image in another element and add padding and other styles to it
div
{
border-radius: 20%;
perspective: 8px;
padding-bottom:5%;
padding-top: 20%;
border-color: silver;
width: 300px !important;
height: 300px !important;
}
div img{
width: 100%;
height: 100%;
}
you can use a margin instead of padding to add space and it will work fine
img
{
border-radius: 20%;
perspective: 8px;
margin-bottom:5%;
margin-top: 20%;
border-color: silver;
width: 300px !important;
height: 300px !important;
}
image for padding
vs
image for margin

CSS padding overflowing HTML table even with border-box sizing but not overflowing anything else

I've been reading non-stop about sizing and I still cannot seem to apply it to my code. I figured out that padding was causing my HTML table to overflow, but that it can be stopped with box-sizing: border-box;
So I added border-box to the elements I thought needed it, then to everything, trying to change width settings, but to no avail. When I remove border-box my header and navbar are affected, but the html table overflows the screen no matter what.
All my elements seem to fit on the screen perfectly fine, except the table. I assume that it is something I added that it countering the box sizing, but I commented out lines one by one and didn't find anything.
I put the full code into fiddle: https://jsfiddle.net/atpzw32L/
The CSS in question:
html, body, h1 {
margin: 0;
padding: 0;
}
html, body { min-height: 100%; }
body{
background-image: url("agaricus.png");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
font-size: 100%;
padding: 20px;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
width: 100%;
}
/* Style the header */
.header {
padding: 10px;
text-align: center;
background: #832bfd7c;
color: white;
}
/* Increase the font size of the h1 element */
.header h1 {
font-size: 40px;
}
/* Style the top navigation bar */
.navbar {
overflow: hidden;
background-color: #333;
margin-bottom: 20px;
}
/* Style the navigation bar links */
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
/* Right-aligned link */
.navbar a.right {
float: right;
}
/* Change color on hover */
.navbar a:hover {
background-color: #ddd;
color: black;
}
/* CSS to hide key columns */
th:nth-child(4), th:nth-child(5), th:nth-child(6), th:nth-child(8), th:nth-child(11), th:nth-child(12), th:nth-child(13), th:nth-child(15) {
display: none
}
td:nth-child(4), td:nth-child(5), td:nth-child(6), td:nth-child(8), td:nth-child(11), td:nth-child(12), td:nth-child(13), td:nth-child(15) {
display: none
}
/* CSS for checkboxes*/
.dropdown-check-list {
display: inline-block;
position: relative;
font-family: Verdana, sans-serif;
padding: 5px;
margin-top: 10px;
background-color: rgb(255, 255, 255);
}
.dropdown-check-list .anchor {
position: relative;
cursor: pointer;
display: inline-block;
padding: 5px 50px 5px 10px;
border: 1px solid #ccc;
min-width: 100px;
}
.dropdown-check-list .anchor:after {
position: absolute;
content: "";
border-left: 2px solid black;
border-top: 2px solid black;
padding: 5px;
right: 10px;
top: 20%;
-moz-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
-o-transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
transform: rotate(-135deg);
}
.dropdown-check-list .anchor:active:after {
right: 8px;
top: 21%;
}
.dropdown-check-list ul.items {
padding: 5px;
display: none;
margin: none;
border: 1px solid #ccc;
border-top: none;
position: absolute;
background-color: #f1f1f1;
}
.dropdown-check-list ul.items li {
list-style: none;
padding: 5px;
}
.dropdown-check-list.visible .anchor {
color: #0094ff;
}
.dropdown-check-list.visible .items {
display: block;
}
input {
float: right;
height: 18px;
width: 18px;
}
/* CSS for table */
table, th, td {
border: 2px solid;
box-sizing: border-box;
}
table {
border-collapse: collapse;
margin-top: 30px;
font-family: Verdana, sans-serif;
padding: 15px;
background-color: rgb(255, 255, 255);
}
th{
text-align: center;
height: 80px;
vertical-align: bottom;
padding: 2px;
border-bottom: 4px solid rgb(0, 0, 0);
font-size: 16px;
background-color: rgba(4, 100, 156, 0.278);
}
td {
text-align: center;
height: 100px;
width: 90%;
padding: 15px;
}
/* th{
text-align: center;
height: 100px;
vertical-align: bottom;
padding: 15px;
border-bottom: 4px solid rgb(0, 0, 0);
font-size: 16px;
background-color: rgba(4, 100, 156, 0.278);
} */
/*
td{
text-align: center;
height: 100px;
vertical-align: left;
padding: 15px;
font-size: 15px;
} */
tr:hover {background-color: rgba(4, 100, 156, 0.089);}
I aim for my end result to have all columns visible, and the table fitting within the screen, so when I add padding to the table it will fit within the screen. I would also like to keep the padding within th and td.
Please let me know how to go about this, I am out of ideas. Thank you
Concerning the width and the horizontal overflow of your table, this is simply caused by its contents: The cells (for example the header cells) contain (single) words that stretch the width of those cells (and therefore the columns) to fit into them, and so the overall width of the table becomes as wide as it is. Examples are the words "description", "information" and "identification" in the header cells.
Words won't be divided automatically, so those wordlenghts determine your minimum widths, expanding the column width and therefore the overall width of the table.
There are three methods to change that:
1.) (IMO the best) Use a smaller font size for the text. That way those longer words and with them the cells and columns won't be that wide and (maybe) fit into the screen.
2.) (also okay) Use hyphenation: Apply hyphens: auto; to td and th. The automatic hyphenation will divide words at know possible hyphenation positions.
3.) (IMO a bad solution) Apply word-break: break-word; to the cells. This will divide longer words, but at "incorrect" positions, i.e. simply at the end of the given cell width. As I wrote, not good, only to be used if nothing else works.
I would combine methods #1 and #2.

DIV's side by side within a container

I am working on an internal program for work that is essentially built on PHP. My problem is that I have a a header, a side navigation, the main content (to the right of the nav) and a footer. Rough Layout Picture
My issue is that I have two DIV's within a container, the nav is set to a percentage with a minimum width, and the content section is set to take the remaining space. In total both the nav and content should take about 91% of the screen real estate. Whats Happening after shrinking the browser a bit
My CSS looks like this for the fields I think are relevant:
.container{
width: 100%;
float: inline-block;
}
.header{
float: left;
text-align: left;
background-color: lightblue;
width: 100%;
vertical-align: middle;
display: block;
border-radius: 15px;
}
.header h1{
font-weight: bold;
font-size: 40px;
text-indent: 50px;
}
.msg_alert{
background-color: green;
color: white;
width: 95%;
padding: 5px;
border-radius: 10px;
}
.err_msg_alert{
background-color: red;
color: white;
width: 95%;
padding: 5px;
border-radius: 10px;
}
.menu{
float: left;
width: 13%;
border: 3px solid grey;
padding: 5px;
background-color: lightgrey;
border-radius: 15px;
margin-top: 20px;
margin-right: 20px;
min-width: 200px;
}
.menu a{
float: left;
color: black;
text-align: left;
padding: 14px;
text-decoration: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
margin: 3px;
background-color: lightblue;
width: 40%;
min-width: 150px;
border-radius: 15px;
}
.menu a:hover{
background-color: grey;
color: black;
}
.menu ul{
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li{
padding: 8px;
margin-bottom: 7px;
}
.content{
float: left;
width: 78%;
padding: 20px;
margin-top: 20px;
margin-left: 20px;
/*border: 3px solid red;*/
}
.footer{
display: inline-block;
width: 100%;
background-color: lightgrey;
border-radius: 15px;
font-size: 12px;
text-align: center;
margin-top: 5px;
padding-bottom: 10px;
}
I'm not sure what I've done wrong. Everything displays properly if the browser is in full screen but when I shrink it down to about 3/4's of the browser size the nav stays where it should be but the contents move below.
I have setup a mobile version which works perfectly but the desktop mode is what I am having issues with.
Thank you for the help in advance.
here is the solution-
<div class="header"></div>
<div class="menu_content">
<div class="menu"></div>
<div class="content"></div>
</div>
<div class="footer"></div>
.menu{
width: 13%;
border: 3px solid grey;
padding: 5px;
background-color: lightgrey;
border-radius: 15px;
margin-top: 20px;
margin-right: 20px;
min-width: 200px;
}
.content{
width: calc(100% - 21.7%);
padding: 20px;
margin-top: 20px;
margin-left: 20px;
border: 3px solid red;
}
.menu_content {
display: flex;
align-items: flex-start;
}
.menu_content::after {
content: '';
clear: both;
display: block;
}
Well, although the widths of .menu and .content might add up to 100% or less in a wider format, due to the min-width pixel setting of .menu, they will become wider than 100% when you decrease the window width, since the 200px of min-width: 200px; will become much more than the 13% width you define for it. So (since both are floats), .content will go below .menu, because there isn't enough space anymore for it next to .content.
To avoid that, you can wrap both of these in a div container and assign display: flex to that. Additionally, add flex-shrink: 0; (= allowed to get smaller) to .content. This should basically do the trick. (There are other details , but just check out some tutorial about flex - it's really not complicated at all.)
Another approach would be to define the menu width as 200px (fixed) and the width for .content as width: calc(100% -200px) - The full width of the parent minus 200px, whatever the width of the parent is.
(This doesn't calculate padding, margins etc. - you would have to consider that in the "real" values you use)

Navigation bar breaks into a new line instead of resizing

So basically I have made a bunch of conflicting divs, but they all managed to work except for my navigation bar. I've tried sitting the different containers inside my top container to automatically fit to the screen by using percentage instead of pixels. But whenever I open up my site on smaller screens the icons in the bar ends up jumping down to the next line?
How do I achieve resizing the buttons and the image automatically so they can all fit into one line, by using pure CSS? Also the main div for the navigation bar is supposed to be above the background split.
If you take a look at my CSS I've also tried setting
.navbar>li {
display: inline-block;
This turned out to have no effect at all
CSS:
.top {
background-color: ;
margin-left: 3%;
margin-right: 3%;
margin: 0 auto;
}
.navbar {
background-color: #FDF3E7;
border-radius: 5px;
margin-left: 15%;
margin-right: 15%;
border: 10px double #C63D0F;
padding-top: 1px;
padding-left: 10%;
padding-right 10%;
padding-bottom: 0px;
position: relative;
display: inline-block;
width: 60%;
}
.navbar>li {
display: inline-block;
margin: 0 auto;
}
.hot-container {
min-height: 40px;
margin-top: 20px;
width:80%;
text-align: center;
position: relative;
display: inline-block;
margin: 0 auto;
}
a.btn {
display: inline-block;
color: #666;
background-color: #eee;
text-transform: uppercase;
letter-spacing: 2px;
font-size: 12px;
padding: 10px 15px;
border-radius: 2px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border: 1px solid rgba(0,0,0,0.3);
border-bottom-width: 1px;
position: relative;
width: 78%
}
Heres the fiddle: https://jsfiddle.net/z400tzkb/

perfect circle in css with border-radius doesn't work

the circle tend be oval, what I want is perfect circle. border-radius 100% isn't work I wonder why..
http://jsfiddle.net/8gD2m/1/
.badge {
display: inline-block;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: lighter !important;
line-height: 1;
color: #fff !important;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
background-color: #d73d33;
border-radius: 50px;
position: relative;
top: -3px;
}
Here is a JSfiddle with some changes:
JSFiddle for round badge
The main changes are:
padding: 0px;
width: 50px;
height: 50px;
line-height: 50px;
Having a line-height equal to the container height will center the text vertically. This only works if the text fits on a single line.
Edit: (copied code from JSFiddle)
.badge {
display: inline-block;
padding: 0;
width: 50px;
height: 50px;
line-height: 50px;
font-size: 12px;
font-weight: lighter !important;
color: #fff !important;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
background-color: #d73d33;
border-radius:50px;
position: relative;
top: -3px;
}
<span class="badge badge-success">8</span>
if it's not perfect circle check display: inline-block and border-radius: 50%:
.cirlce {
height: 20px;
width: 20px;
padding: 5px;
text-align: center;
border-radius: 50%;
display: inline-block;
color:#fff;
font-size:1.1em;
font-weight:600;
background-color: rgba(0,0,0,0.1);
border: 1px solid rgba(0,0,0,0.2);
}
check this out
.badge {
display: inline-block;
min-width: 10px;
padding: 7px;
font-size: 12px;
font-weight: lighter !important;
line-height: 1;
color: #fff !important;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
background-color: #d73d33;
border-radius: 50px;
position: relative;
top: -3px;
}
The main trick for making it a perfect circle is distributing the padding of the element(container) evenly => then setting border-radius: 50% or border-radius: 100%.
So you can get rid of the height and width declaration and use absolute positioning and padding to control the height and width
or same height and width and uniform padding value
.element-class {
Position: absolute;
padding: 10em or 10% or with any unit;
border-radius: 50% or 100%;
}
OR
.element-class {
height: 10em;
width: 10em;
padding: 10em; **
border-radius: 50%;
}
I had the same issue. When I added a 100% border-radius, my picture turned into an oval. That is because my picture is wider than it is tall. Imagine smoothing the edges of a rectangle. If you want your image to be circular, you have to make sure the height and width dimensions are the same. You could try setting them by doing the following:
css height: 200px; width: 200px; (so the point is having equal height and with in your CSS)
This will make sure that your image is circular, however, it may cause your image to stretch and become distorted because your originally image is NOT a perfect square I presume.
You can use vw unit for width and height.
Like the sample below:
div {
background-color: green;
width: 20vw;
height: 20vw;
border-radius: 100%;
text-align: center;
line-height: 20vw;
color: white;
}
<div>resize device</div>