I have trouble to generate the following layout using DIV element, fighting with alignement and box style
Desire layout is here
Any help would be helpfull
regards
Try something like this
DEMO
.element {
margin: 50px;
box-sizing: border-box;
}
.remaining, .sold {
display: table;
border: 1px solid #999999;
padding: 10px;
width: 20%;
position: relative;
float: left;
height: 200px;
box-sizing: border-box;
}
.remaining {
border-right: none;
border-top: none;
}
.remaining:before {
position: absolute;
top: -30px;
height: 30px;
background: #FF7F7E;
content: "SHOES - STOCK";
border: 1px solid #999999;
color: white;
width: 100%;
left: 0;
line-height: 30px;
padding-left: 10px;
font-size: 13px;
font-weight: bold;
right: 0;
box-sizing: border-box;
}
.top, .center, .bottom {
display: table-row;
}
.top .inner {
display: table-cell;
width: 100%;
vertical-align: top;
}
.center {
display: table-cell;
width: 100%;
vertical-align: middle;
text-align: center;
}
.center span {
display: block;
}
.bottom .inner {
display: table-cell;
width: 100%;
vertical-align: bottom;
}
.inner-content {
display: table;
}
.top .inner span,
.bottom .inner span{
display: table-cell;
width: 100%;
}
.top .inner span:last-child,
.bottom .inner span:last-child {
text-align: right;
font-weight: bold;
width: 60px;
float: left;
}
.center span:first-child {
font-size: 70px;
font-weight: bold;
line-height: 1;
}
span u {
text-decoration: none;
border-bottom: 1px solid red;
}
#media(max-width: 1200px) {
.remaining, .sold {
display: table;
width: 30%;
height: 200px;
}
}
#media(max-width: 768px) {
.remaining, .sold {
display: table;
float: none;
width: 100%;
height: 200px;
}
.remaining {
border-right: 1px solid #999999;
border-bottom: none;
}
}
<div class="element">
<div class="remaining">
<div class="top">
<div class="inner">
<div class="inner-content">
<span>TOTAL</span>
<span>250 <u>pcs</u></span>
</div>
</div>
</div>
<div class="center">
<span>200</span>
<span>REMAINING</span>
</div>
<div class="bottom">
<div class="inner">
<div class="inner-content">
<span>USED</span>
<span>50 <u>pcs</u></span>
</div>
</div>
</div>
</div>
<div class="sold">
<div class="center">
<span>50</span>
<span>SOLD</span>
</div>
</div>
</div>
Related
The purple Navbar at the top of the page pushes the container "container2" off screen. Is there any possible way I can make it so the "container2" div does not overflow with the proper padding of 5px at the bottom?
#import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
/*QuickReset*/ * { box-sizing: border-box; margin: 0; }
html {
height: 100%;
width: 100%
}
body {
background: black;
height: 100%;
position: relative;
overflow: hidden;
}
.navbar {
background: purple;
padding: 1em;
width: 100%;
position: relative;
top: 0;
}
.navbar .logo {
text-decoration: none;
font-family: 'Gugi', cursive;
font-weight: bold;
font-size: 1.5em;
color: white;
}
.navbar .container {
display: grid;
grid-template-columns: 100px auto;
justify-content: unset;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
}
.container2 {
display: flex;
width: 100%;
height: 100%;
position: relative;
gap: 5px;
padding: 5px;
}
.one,
.two {
border: 3px solid green;
border-radius: 5px;
}
.one { width: 10%; background: red; }
.two { width: 90%; background: blue; }
<div class="navbar">
<div class="container">
<a class="logo" href="#">Logo</a>
</div>
</div>
<div class="container2">
<div class="one">
</div>
<div class="two">
</div>
</div>
Resulting Page
I am new to HTML and CSS so any helps greatly appreciated.
Stack overflow wants more content besides code but im not too sure what else to add.
Remove overflow: hidden from body:
#import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
/*QuickReset*/
* {
box-sizing: border-box;
margin: 0;
}
html {
height: 100%;
width: 100%
}
body {
background: black;
height: 100%;
position: relative;
/*overflow: hidden;*/
}
.navbar {
background: purple;
padding: 1em;
width: 100%;
position: relative;
top: 0;
}
.navbar .logo {
text-decoration: none;
font-family: 'Gugi', cursive;
font-weight: bold;
font-size: 1.5em;
color: white;
}
.navbar .container {
display: grid;
grid-template-columns: 100px auto;
justify-content: unset;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
}
.container2 {
display: flex;
width: 100%;
height: 100%;
position: relative;
gap: 5px;
padding: 5px;
}
.one,
.two {
border: 3px solid green;
border-radius: 5px;
}
.one {
width: 10%;
background: red;
}
.two {
width: 90%;
background: blue;
}
<div class="navbar">
<div class="container">
<a class="logo" href="#">Logo</a>
</div>
</div>
<div class="container2">
<div class="one">
</div>
<div class="two">
</div>
</div>
#import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
/*QuickReset*/ * { box-sizing: border-box; margin: 0; }
body {
background: black;
height: 100vh;
position: relative;
overflow: hidden;
}
.navbar {
background: purple;
padding: 1em;
width: 100%;
position: relative;
top: 0;
height: 20%;
}
.navbar .logo {
text-decoration: none;
font-family: 'Gugi', cursive;
font-weight: bold;
font-size: 1.5em;
color: white;
}
.navbar .container {
display: grid;
grid-template-columns: 100px auto;
justify-content: unset;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
}
.container2 {
display: flex;
width: 100%;
height: 80%;
position: relative;
gap: 5px;
padding: 5px;
}
.one,
.two {
border: 3px solid green;
border-radius: 5px;
}
.one { width: 10%; background: red; }
.two { width: 90%; background: blue; }
<div class="navbar">
<div class="container">
<a class="logo" href="#">Logo</a>
</div>
</div>
<div class="container2">
<div class="one">
</div>
<div class="two">
</div>
</div>
you should divide the height of navbar and container 2
I added #media screen and (max-width: 1000px) rule to my code with modifications it would make. I wanted to make boxes stack up on width: 1000px; and I did succeed to do that, however, now when the boxes stack up, there is an extra space to the right of my webpage.
It appears that my boxes somehow conflict with one of the lines of the header style. Tried removing margins and did not pay off. I want that space removed that those boxes add.
Also, it is possible that the header does not have to do anything here and only the boxes are stretching out the website.
body {
margin: 0;
}
.header {
width: 100%;
height: 100vh;
background-color: #262626;
display: table-cell;
vertical-align: middle;
}
.header h1 {
line-height: 50%;
color: white;
text-align: center;
font-size: 5em;
}
.content {
margin-top: 10%;
}
.subcontent div a {
user-select: none;
font-size: 30px;
display: table-cell;
vertical-align: middle;
text-decoration: none;
text-align: center;
color: black;
font-weight: normal;
border: 2px solid #3B3B3B;
font-family: "ALK Rounded Mtav Med", sans-serif;
transition-duration: 0.3s;
}
.subcontent {
display: flex;
justify-content: center;
}
.subcontent div {
display: table;
margin: 15px;
height: 500px;
width: 100%;
transition-duration: 0.15s;
}
#media screen and (max-width: 1000px) {
.subcontent {
display: block;
}
.subcontent div {
height: 300px;
margin-top: 15px;
margin-bottom: 15px;
}
}
<body>
<div style="display: table; width: 100%;">
<div class="header">
<h1>ვისწავლოთ</h1>
<h1>იაპონური</h1>
</div>
</div>
<div class="content">
<div class="subcontent">
<div>
ანბანი
</div>
<div>
გრამატიკა
</div>
</div>
<div class="subcontent">
<div>
ლექსიკონი
</div>
<div>
დიალოგები
</div>
</div>
</div>
</body>
Don't change display:flex to display:block. Instead you can simply change flex-diretion to column and make width:auto to avoid the overflow due to the margin added to the width:100%.
body {
margin: 0;
}
.header {
width: 100%;
height: 100vh;
background-color: #262626;
display: table-cell;
vertical-align: middle;
}
.header h1 {
line-height: 50%;
color: white;
text-align: center;
font-size: 5em;
}
.content {
margin-top: 10%;
}
.subcontent div a {
user-select: none;
font-size: 30px;
display: table-cell;
vertical-align: middle;
text-decoration: none;
text-align: center;
color: black;
font-weight: normal;
border: 2px solid #3B3B3B;
font-family: "ALK Rounded Mtav Med", sans-serif;
transition-duration: 0.3s;
}
.subcontent {
display: flex;
justify-content: center;
}
.subcontent div {
display: table;
margin: 15px;
height: 500px;
width: 100%;
transition-duration: 0.15s;
}
#media screen and (max-width: 1000px) {
.subcontent {
flex-direction:column;
}
.subcontent div {
height: 300px;
width:auto;
margin-top: 15px;
margin-bottom: 15px;
}
}
<body>
<div style="display: table; width: 100%;">
<div class="header">
<h1>ვისწავლოთ</h1>
<h1>იაპონური</h1>
</div>
</div>
<div class="content">
<div class="subcontent">
<div>
ანბანი
</div>
<div>
გრამატიკა
</div>
</div>
<div class="subcontent">
<div>
ლექსიკონი
</div>
<div>
დიალოგები
</div>
</div>
</div>
</body>
It's because of the margin: 15px on the .subcontent which makes a margin of 15px all around the .subcontent
body {
margin: 0;
}
.header {
width: 100%;
height: 100vh;
background-color: #262626;
display: table-cell;
vertical-align: middle;
}
.header h1 {
line-height: 50%;
color: white;
text-align: center;
font-size: 5em;
}
.content {
margin-top: 10%;
}
.subcontent div a {
user-select: none;
font-size: 30px;
display: table-cell;
vertical-align: middle;
text-decoration: none;
text-align: center;
color: black;
font-weight: normal;
border: 2px solid #3B3B3B;
font-family: "ALK Rounded Mtav Med", sans-serif;
transition-duration: 0.3s;
}
.subcontent {
display: flex;
justify-content: center;
}
.subcontent div {
display: table;
/* margin: 15px; This is the villain */
height: 500px;
width: 100%;
transition-duration: 0.15s;
}
#media screen and (max-width: 1000px) {
.subcontent {
display: block;
}
.subcontent div {
height: 300px;
margin-top: 15px;
margin-bottom: 15px;
}
}
<body>
<div style="display: table; width: 100%;">
<div class="header">
<h1>ვისწავლოთ</h1>
<h1>იაპონური</h1>
</div>
</div>
<div class="content">
<div class="subcontent">
<div>
ანბანი
</div>
<div>
გრამატიკა
</div>
</div>
<div class="subcontent">
<div>
ლექსიკონი
</div>
<div>
დიალოგები
</div>
</div>
</div>
</body>
Fiddle here
It's like a post where the title appears on the left and the dropdown settings menu's arrow on the right..
This is what I have till now
<style>
.thread {
background-color: skyblue;
height: 50px;
width: 90%;
align-self: center;
text-align: end;
display: inline-block;
border-radius: 6px;
position: relative;
}
.header {
width: fit-content;
display: inline-block;
align-self: right;
}
.arrow {
display: inline-block;
vertical-align: bottom;
height: 50%;
}
.titletext {
display: inline-block;
text-align: left;
}
</style>
<div class="thread">
<p class="titletext">Title</p>
<div class="header"><img class="arrow" onclick="showPopover(this)" src="https://image.flaticon.com/icons/png/512/7/7584.png" /></div>
</div>
It appears like this
And I'm trying to achieve this
Sorry if the code is too random or if some lines are unneeded but I've been searching and trying many stuff so that's what I have right now.
You can use float:right on the arrow, and text-align:left on the entire header.
.thread {
background-color: skyblue;
height: 50px;
width: 90%;
text-align: left;
display: inline-block;
border-radius: 6px;
position: relative;
}
.header {
display: inline-block;
float: right;
}
.arrow {
display: inline-block;
vertical-align: bottom;
width: 25px;
height: auto;
float: right;
margin: 12px;
}
.titletext {
display: inline-block;
text-align: left;
}
<div class="thread">
<p class="titletext">Title</p>
<img class="arrow" onclick="showPopover(this)"
src="https://image.flaticon.com/icons/png/512/7/7584.png" />
</div>
.titletext {
display: inline-block;
float: left;
}
just use float:left;
.thread {
background-color: skyblue;
height: 50px;
width: 90%;
align-self: center;
text-align: end;
display: inline-block;
border-radius: 6px;
position: relative;
}
.header {
width: fit-content;
display: inline-block;
align-self: right;
padding:15px 10px;
}
.arrow {
display: inline-block;
vertical-align: bottom;
height: 50%;
}
.titletext {
display: inline-block;
text-align: left;
float:left;
padding-left:10px;
}
<div class="thread">
<p class="titletext">Title</p>
<div class="header"><img class="arrow" width="20" onclick="showPopover(this)" src="https://image.flaticon.com/icons/png/512/7/7584.png" /></div>
</div>
Just put you´r class="titletext" like:
.titletext {
position: absolute;
top;
left: 0;
}
You can use float:left on the titletext
<style>
.thread {
background-color: skyblue;
height: 50px;
width: 90%;
align-self: center;
text-align: end;
display: inline-block;
border-radius: 6px;
position: relative;
}
.header {
width: fit-content;
display: inline-block;
align-self: right;
}
.arrow {
display: inline-block;
vertical-align: bottom;
height: 50%;
}
.titletext {
display: inline-block;
float:left;
}
</style>
<div class="thread">
<p class="titletext">Title</p>
<div class="header"><img class="arrow" onclick="showPopover(this)" src="https://image.flaticon.com/icons/png/512/7/7584.png" /></div>
</div>
I have an construction and I can't change a couple of elements.
The meaning is that the modal comes at the top, without changing the location of the div. (Or at least not above box3)
The elements I can change are box3, box4 and modal.
I want the yellow square to overlap over the whole document, now it is stuck in its parent (See snippet or jsFiddle)
Is there any way to do this?
CSS & HTML:
.modal {
position: absolute;
top: 0;
left: 0;
height: 40px;
width: 40px;
background-color: yellow;
}
.box4 {
display: block;
height: 150px;
}
.box3 {
display: block;
position: relative;
margin: 0 auto;
padding-right: 18px;
padding-left: 18px;
clear: both;
border: 2px solid purple;
height: 150px;
}
.box2 {
border: 2px solid green;
padding-right: 10px;
padding-left: 10px;
width: 100%;
position: relative;
float: left;
display: block;
box-sizing: border-box;
min-height: 200px;
}
.upperRow {
display: block;
box-sizing: border-box;
height: 20px;
}
.box1 {
position: relative;
width: 100%;
height: 100%;
background: #fff;
-webkit-transform-style: preserve-3d;
z-index: 2;
border: 2px solid black;
}
header {
position: relative;
background-color: red;
height: 50px;
display: block;
box-sizing: border-box;
}
footer {
height: 50px;
padding-top: 8px;
margin-top: 8px;
float: left;
width: 100%;
background-color: blue;
display: block;
}
<!-- HTML -->
<header>
</header>
<div class="box1">
<section class="upperRow">
</section>
<section class="box2">
<div class="box3">
<!-- box3 CAN BE MODIFIED-->
<div class="box4">
<!-- box4 CAN BE MODIFIED-->
</div>
<div class="modal">
<!-- modal CAN BE MODIFIED-->
</div>
</div>
</section>
</div>
<footer>
</footer>
It's cause the parents have position: relative; or -webkit-transform-style: preserve-3d;. If you remove that, it's fine.
.modal {
position: absolute;
top: 0;
left: 0;
height: 40px;
width: 40px;
background-color: yellow;
}
.box4 {
display: block;
height: 150px;
}
.box3 {
display: block;
margin: 0 auto;
padding-right: 18px;
padding-left: 18px;
clear: both;
border: 2px solid purple;
height: 150px;
}
.box2 {
border: 2px solid green;
padding-right: 10px;
padding-left: 10px;
width: 100%;
float: left;
display: block;
box-sizing: border-box;
min-height: 200px;
}
.upperRow {
display: block;
box-sizing: border-box;
height: 20px;
}
.box1 {
width: 100%;
height: 100%;
background: #fff;
z-index: 2;
border: 2px solid black;
}
header {
position: relative;
background-color: red;
height: 50px;
display: block;
box-sizing: border-box;
}
footer {
height: 50px;
padding-top: 8px;
margin-top: 8px;
float: left;
width: 100%;
background-color: blue;
display: block;
}
<!-- HTML -->
<header>
</header>
<div class="box1">
<section class="upperRow">
</section>
<section class="box2">
<div class="box3">
<!-- box3 CAN BE MODIFIED-->
<div class="box4">
<!-- box4 CAN BE MODIFIED-->
</div>
<div class="modal">
<!-- modal CAN BE MODIFIED-->
</div>
</div>
</section>
</div>
<footer>
</footer>
I am trying to put text over an image, but when I give the text parametr left: it's cut in half.
HTML:
<div class="c-subcat-item">
<div class="pro-img-wrap">
<div class="pro-img-wrap-in">
<div class="img-middle-center">
<a class="img-middle-wrap" href="/Wines/Product/1417">
<img src="/Images/bottle-red.jpg" alt="Produkt">
</a>
</div>
</div>
</div>
<div class="subcat-item-details">
<div class="product-desc-container">
<div class="">
<a class="item-name" href="/Wines/Product/1417">Avilla</a>
<div class="clearfix"></div>
<div class="item-our-price">
<span class="item-sold-out">Chwilowo niedostępny</span>
</div>
<div class="item-detail-price">
<span class="item-price-value">45,00 zł </span>
</div>
</div>
<div class="div-empty-margin"></div>
</div>
<div class="clearfix"></div>
<span class="item-more">
<a class="item-more" href="/Wines/Product/1417">Zobacz więcej</a>
</span>
<div class="div-empty-margin"></div>
<div class="add-to-cart">
</div>
</div>
</div>
CSS:
body {
background-color: #fffff7;
color: #666;
font-family: 'Roboto Condensed',sans-serif;
font-size: 10px;
height: 100%;
margin: 0;}
html, body, .page-wrapper {
width: 100%;
min-width: 1024px;
margin-left: auto;
margin-right: auto;}
.page-wrapper {
height: 100%;
}
.page-content-wrapper {
min-height: 100%;
text-align: center;
}
.main {
display: inline-block;
margin: 20px auto 0;
margin-bottom: 61px;
position: relative;
text-align: left;
width: 965px;
}
.wrapper {
float: left;
margin-bottom: 20px;
width: 100%;
}
.content {
float: left;
width: 100%;
}
.content-main-wrapper1 {
float: left;
width: 100%;
}
.content-main-wrapper2 {
float: left;
position: relative;
right: 767px;
width: 100%;
}
.content-wo-padding {
float: left;
left: 768px;
position: relative;
width: 726px;
}
.pro-img-wrap {
float: left;
}
.c-subcat-item {
float: left;
padding: 20px;
position: relative;
width: 726px;
}
.pro-img-wrap-in {
border: 1px solid #e8e5e5;
float: left;
height: 240px;
overflow: hidden;
width: 160px;
display: table;
}
.img-middle-center {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
display: table-cell;
float: none;
height: 100%;
width: 100%;
text-align: center;
vertical-align: middle;
}
.subcat-item-details {
float: right;
height: 242px;
width: 544px;
position: relative;
}
.product-desc-container {
overflow: hidden;
position: relative;
}
h2.item-name, a.item-name {
color: #333;
float: left;
font-size: 16px;
font-weight: bold;
line-height: 15px;
margin: 2px 0 5px 0;
padding: 0;
width: 100%;
text-transform: uppercase;
}
.clearfix {
clear: both;
}
.item-our-price {
float: left;
margin-top: 10px;
width: 100%;
}
.item-our-price span.item-sold-out {
position: relative;
color: #f00;
background-color: #fff;
padding: 10px;
border: solid 1px #f00;
font-size: 1.3em;
cursor: default;
left: -60px;
}
You can check it here
Remove overflow: hidden; from class .product-desc-container
body {
background-color: #fffff7;
color: #666;
font-family: 'Roboto Condensed',sans-serif;
font-size: 10px;
height: 100%;
margin: 0;}
html, body, .page-wrapper {
width: 100%;
min-width: 1024px;
margin-left: auto;
margin-right: auto;}
.page-wrapper {
height: 100%;
}
.page-content-wrapper {
min-height: 100%;
text-align: center;
}
.main {
display: inline-block;
margin: 20px auto 0;
margin-bottom: 61px;
position: relative;
text-align: left;
width: 965px;
}
.wrapper {
float: left;
margin-bottom: 20px;
width: 100%;
}
.content {
float: left;
width: 100%;
}
.content-main-wrapper1 {
float: left;
width: 100%;
}
.content-main-wrapper2 {
float: left;
position: relative;
right: 767px;
width: 100%;
}
.content-wo-padding {
float: left;
left: 768px;
position: relative;
width: 726px;
}
.pro-img-wrap {
float: left;
}
.c-subcat-item {
float: left;
padding: 20px;
position: relative;
width: 726px;
}
.pro-img-wrap-in {
border: 1px solid #e8e5e5;
float: left;
height: 240px;
overflow: hidden;
width: 160px;
display: table;
}
.img-middle-center {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
display: table-cell;
float: none;
height: 100%;
width: 100%;
text-align: center;
vertical-align: middle;
}
.subcat-item-details {
float: right;
height: 242px;
width: 544px;
position: relative;
}
.product-desc-container {
position: relative;
}
h2.item-name, a.item-name {
color: #333;
float: left;
font-size: 16px;
font-weight: bold;
line-height: 15px;
margin: 2px 0 5px 0;
padding: 0;
width: 100%;
text-transform: uppercase;
}
.clearfix {
clear: both;
}
.item-our-price {
float: left;
margin-top: 10px;
width: 100%;
}
.item-our-price span.item-sold-out {
position: relative;
color: #f00;
background-color: #fff;
padding: 10px;
border: solid 1px #f00;
font-size: 1.3em;
cursor: default;
left: -60px;
}
<div class="c-subcat-item">
<div class="pro-img-wrap">
<div class="pro-img-wrap-in">
<div class="img-middle-center">
<a class="img-middle-wrap" href="/Wines/Product/1417"> <img src="/Images/bottle-red.jpg" alt="Produkt">
</a>
</div>
</div>
</div>
<div class="subcat-item-details">
<div class="product-desc-container">
<div class="">
<a class="item-name" href="/Wines/Product/1417">Avilla</a>
<div class="clearfix"></div>
<div class="item-our-price">
<span class="item-sold-out">Chwilowo niedostępny</span>
</div>
<div class="item-detail-price">
<span class="item-price-value">45,00 zł </span>
</div>
</div>
<div class="div-empty-margin"></div>
</div>
<div class="clearfix"></div>
<span class="item-more">
<a class="item-more" href="/Wines/Product/1417">Zobacz więcej</a>
</span>
<div class="div-empty-margin"></div>
<div class="add-to-cart">
</div>
</div>
</div>
Remove overflow:hidden from .product-desc-container that's the reason for the text not visible over the image
remove overflow:hidden from .product-desc-container
see here : jsfiddle
code
.product-desc-container {
/* overflow: hidden; */
position: relative;
}