Css doesn't fit boxes in a box - html

I used figma to build a design and exported css code below. I added some div classes but it still doesn't fit properly.
I tried making the classes a subclass of the main class but it still didn't work.
I assumed this might work the way columns and rows do, the rows comes first then the columns follow.
.pagingg {
position: absolute;
width: 338px;
height: 61px;
left: 88px;
top: 97px;
background: #FBF6F6;
border: 1px solid #F8EBEB;
box-sizing: border-box;
border-radius: 2px;
}
.pagingg.firstpg {
position: absolute;
width: 88px;
height: 19px;
left: 104px;
top: 106px;
background: #FFFFFF;
border: 1px solid #E6C3C3;
border-radius: 2px;
}
.pagingg.pgnum {
position: absolute;
width: 58px;
height: 14px;
left: 223px;
top: 110px;
font-family: Open Sans;
font-style: normal;
font-weight: normal;
font-size: 10px;
line-height: 14px;
/* identical to box height */
color: #000000;
}
.pagingg.lastpg {
position: absolute;
width: 89px;
height: 16px;
left: 214px;
top: 133px;
background: #FFFFFF;
border: 1px solid #E6C3C3;
border-radius: 1px;
}
.nextpg {
position: absolute;
width: 88px;
height: 19px;
left: 319px;
top: 106px;
background: #FFFFFF;
border: 1px solid #E6C3C3;
border-radius: 2px;
}
.pagingg.fpg {
position: absolute;
width: 22px;
height: 15px;
left: 138px;
top: 106px;
font-family: Open Sans;
font-style: normal;
font-weight: 300;
font-size: 11px;
line-height: 15px;
/* identical to box height */
color: #000000;
}
.pagingg.pgnumtext {
position: absolute;
width: 58px;
height: 14px;
left: 223px;
top: 110px;
font-family: Open Sans;
font-style: normal;
font-weight: normal;
font-size: 10px;
line-height: 14px;
/* identical to box height */
color: #000000;
}
.pagingg.lastpgtext {
position: absolute;
width: 21px;
height: 15px;
left: 247px;
top: 133px;
font-family: Open Sans;
font-style: normal;
font-weight: 300;
font-size: 11px;
line-height: 15px;
/* identical to box height */
color: #000000;
}
.pagingg.nextpgtext {
position: absolute;
width: 26px;
height: 15px;
left: 350px;
top: 107px;
font-family: Open Sans;
font-style: normal;
font-weight: 300;
font-size: 11px;
line-height: 15px;
/* identical to box height */
letter-spacing: 0.075em;
color: #000000;
}
<div class="pagingg">
<div class="pagingg firstpg">
First
</div>
<div class="pgnum">
<div class="pgnumtext">2 0f 5</div>
</div>
<div class="lastpg">
<div class="lastpgtext">Last</div>
</div>
<div class="nextpg">
<div class="nextpgtext">Next</div>
</div>
</div>

Do not use position:absolute on every element. Use it only when absolutely necessary. You can read about it here -> CSS Position
For this requirement you can just use flexBox which is the recommended solution for layout purposes.
Read more about flexbox -> a-guide-to-flexbox or here -> MDN Flexbox
See below:
.pagingg {
display:flex;
flex-wrap:wrap;
width: 300px;
justify-content: space-between;
align-items: center;
}
.lastpg {
width: 100%;
text-align: center;
}
.text {
border: 1px solid black;
background-color: grey;
display:inline-block;
padding: 5px 20px;
}
<div class="pagingg">
<div class=" firstpg">
<div class="firstpgtext text">
First
</div>
</div>
<div class="pgnum">
<div class="pgnumtext ">2 0f 5</div>
</div>
<div class="nextpg">
<div class="nextpgtext text">Next</div>
</div>
<div class="lastpg">
<div class="lastpgtext text">Last</div>
</div>
</div>

Figma will generate you only general styles, like font-size, font-weight, color, background, letter-spacing etc.
For position, display, width, height, padding and other specific style you will need to write code.

Everyone is correct. You don't want to use Figma's absolute positioning in your HTML/CSS.
Instead you need to start by understanding the structure you need and figure out the nesting and positioning. You can position elements in HTML/CSS using grids, which are more modern and work better than previous approaches like tables, floats, etc.
A great tool that will help you get started quicker, is Desech Studio which imports your Figma file and positions elements relatively using grids, automatically. You still have to do some adjustments here and there, but it's a better starting point than absolute zero.

Related

DIVs are moving from their positions when zooming out of the page

So basically my problem is when I zoom in-out of the page, some DIVs move out from their position which causes my layout to break. I used the position relative and absolute properties as well as used % instead px as my units in positioning. I've gone through some articles saying that it's not favorable to use position absolute and that this was an expected behavior but I couldn't seem to find an answer to my question. I also tried find a way to do it using CSS Flexbox but i couldn't find a direct answer to my problem.
My expected layout should be something like https://snipboard.io/Mr8sNv.jpg but as I said before, it breaks when zooming in/out.
Here is my HTML.
<div class="Container">
<div class="background">
<div class="Space"></div>
<p class="Branding_Design">BRANDING & DESIGN</p>
<div class="Project_One">Project One</div>
<div class="SliderBOX"></div>
<div style="position:absolute; right: 8%; top: 59%;">
<div class="ProjectDetailsContainer">
<p class="Project_Details">PROJECT DETAILS</p>
</div>
</div>
<div style="position:absolute; right: 12%; top: 62.5%;">
<div class="ViewSlidesContainer">
<p class="View_Slides">VIEW SLIDES</p>
</div>
</div>
</div>
</div>
Here is my CSS
.Container {
width: 100%;
position: relative;
height: 721px;
}
.background {
background: black;
width: 100%;
height: 100%;
}
h3 {
text-align: center;
}
.Space {
width: 1000px;
height: 100px;
background: red;
position: relative;
z-index: -1;
}
.SliderBOX{
height: 525px;
width: 50%;
background: yellow;
margin: 0 auto;
}
.Branding_Design {
font-size: 10px;
font-weight: 500;
font-family: 'Open Sans';
color: #f7ac53;
letter-spacing: 0.5px;
position: absolute;
top: 39%;
left: 12%;
}
.Project_One {
color: white;
font-family: "Merriweather";
font-size: 39px;
font-weight: 300;
position: absolute;
top: 45%;
left: 14%;
z-index: 1;
}
.ProjectDetailsContainer {
position: relative;
}
.Project_Details {
color: white;
font-family: 'Open Sans';
font-weight: 400;
font-size: 11px;
}
.ViewSlidesContainer {
position: relative;
}
.View_Slides {
color: white;
font-family: 'Open Sans';
font-weight: 400;
font-size: 11px;
}
I also included my code in jsfiddle in order to make it easier to go through my code
https://jsfiddle.net/wa3bLx1h/22/
What am I doing wrong?
I think believe the code below, is what you're looking for correct? Flex-box would the solution to remedy this problem. I would suggest just go thru MDN tutorials and mess around with each properties of flex-box. Your problem helped me understand Parent and Child containers better now.
<div class="container">
<div class="background">
<div class="space"></div>
<div class="textCon1">
<div class="p-text-1">
<p class="brandingDesign"> BRANDING & DESIGN</p>
</div>
<div class="p-text-2">
<p class="projectOne">Project One</p>
</div>
</div>
<div class="sliderBox"></div>
<div class="projectDetailContainer">
<div class="p-text-3">
<p class="projectDetails"> PROJECT DETAILS</p>
</div>
<div class="viewSlideContainer">
<p class="viewSlides">VIEW SLIDES</p>
</div>
</div>
</div>
</div>
* {
margin: 0;
padding: 0;
}
.container {
height: 721px;
width: 100%;
}
.background {
height: 100%;
width: 100%;
background: black;
display: flex;
align-items: center;
justify-content: center;
}
.sliderBox {
height: 525px;
width: 50%;
display: flex;
background: yellow;
}
.textCon1 {
display: flex;
flex-direction: column;
margin-right: 10px;
}
.brandingDesign {
font-size: 10px;
font-weight: 500;
font-family: "Open Sans";
color: #f7ac53;
letter-spacing: 0.5px;
margin-right: 100px;
padding: 5px;
}
.projectOne {
color: white;
font-family: "Merriweather";
font-size: 39px;
font-weight: 300;
margin-left: 50px;
padding: 5px;
}
.projectDetailContainer {
display: flex;
flex-direction: column;
margin-top: 200px;
margin-left: 100px;
}
.projectDetails {
color: white;
font-family: "Open Sans";
font-weight: 400;
font-size: 11px;
margin-left: 50px;
padding: 10px;
}
.viewSlides {
color: white;
font-family: "Open Sans";
font-weight: 400;
font-size: 11px;
padding: 5px;
}

Putting an image in above

I'm currently making a project which consists of a website that streams movies and tv shows, in the tv show section I want to insert a image to illustrate each episode. My idea is making a second image that shows which episode that image corresponds to and I'm having a little trouble putting the second image above the first one.
.episode-slidebackground {
width: 950px;
height: 220px;
background: rgba(162, 162, 162, 0.24);
float: left;
margin-left: 15px;
margin-top: 20px;
margin-bottom: 15px;
}
.episode-slidebackground img {
width:182px;
height:136px;
float: left;
margin-left: 7px;
margin-top: 7px;
margin-bottom: 5px;
border-radius: 15px;
}
.episode-slideimgbackground{
width: 925px;
margin-left:10px;
margin-right:10px;
height:145px;
background: rgba(128, 128, 128, 0.24)
}
h1{
font-size: 30px;
color: #f2a223;
font-weight: bold;
margin-bottom: 30px;
margin-top: 10px;
}
h2 {
font-size: 15px;
color: #f2a223;
font-weight: bold;
}
h3 {
font-size: 14px;
color: #fff;
font-weight: bold;
}
h4 {
font-size: 14px;
color: #f3b12b;
font-weight: bold;
}
h5 {
font-size: 12px;
color: white;
}
h6 {
font-size: 20px;
color: white;
padding-left: 5px;
padding-top: 5px;
}
<div class="episode-slidebackground">
<h6>Temporada:1 2 3 4 5 6</h6> <br>
<h2>Episódios:</h2>
<div class="episode-slideimgbackground">
<img src="img/1.jpg">
<img src="img/2.jpg">
<img src="img/3.jpg">
</div>
</div>
This is the page without the second image:
You need to try and work with CSS's position attribute. This will enable you to have more control over your elements.
The two position attribute's you need to make use of are absolute and relative.
Basically, if you have a div that is set to position: relative that means that you can adjust that div's position without changing the layout of your webpage. It also means that any children elements of that div with the position: absolute can be positioned anywhere inside of that relative div.
.videoContainer {
position: relative;
height: 200px;
width: 200px;
}
.videoImage, .videoCaption {
position: absolute;
color: white;
}
.videoCaption {
bottom: 0;
height: 50px;
background: Gray;
width: 100%;
}
<div class="videoContainer">
<img class="videoImage" src="http://placehold.it/200x200"/>
<div class="videoCaption">Some Caption</div>
</div>
You need to set the z-index this is an css attribute that determines which element is on top
https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

Top message box in CSS

I'd like to make a message-alert box in my web app. I created the main style but I have problems on small screen sizes.
Here's the image for the regular 1366x768 computer screen:
And here is for a typical mobile device:
Problems:
The X button has tagled with the message.
The main message wrapper has fixed and wasn't expand when the message came out of the wrapper.
How to fix the two above problems? Do I have to follow another path? I use position: fixed; property-value to keep my message on top.
Here are my HTMl and CSS code:
HTML:
<div class="top-msg">
<div class="top-msg-ico">
!
</div>
<div class="top-msg-inner">
<p>Only letters and nubers are allowed for email. See security for more info.</p>
</div>
<div class="top-msg-close" style=" cursor: pointer;">✕</div>
</div>
CSS:
.top-msg {
width: 100%;
height: 55px;
position: fixed;
background-color: rgba(42,45,50,0.6);
color: rgba(250,251,255,0.95);
font-family: "Lato", sans-serif;
font-size: 18px;
}
.top-msg-close {
float: right;
padding-top: 17px;
padding-right: 30px;
//border: 1px solid white;
//height: 100%;
width: 3%;
}
.top-msg-inner {
top: 15px;
position: absolute;
display: inline-block;
padding-left: 10px;
width: 80%;
//border: 1px solid white;
}
.top-msg-ico {
min-width: 65px;
height: 100%;
background-color: #fff;
display: inline-block;
background-color: rgba(0,0,0,0.7);
text-align: center;
font-size: 45px;
}
FIDDLE:
https://jsfiddle.net/4oLvyajo/
UPDATE -SOLUTION!-
After some help from LGSon answer I manage to finish all the design, so I accepts his answer but the hole solution is in the fiddle below.
FIDDLE:
https://jsfiddle.net/4oLvyajo/4/
Images:
Here is a start for you
.top-msg {
width: 100%;
position: fixed;
background-color: rgba(42,45,50,0.6);
color: rgba(250,251,255,0.95);
font-family: "Lato", sans-serif;
font-size: 18px;
}
.top-msg-close {
float: left;
box-sizing: border-box;
padding-top: 17px;
padding-right: 30px;
width: 45px;
}
.top-msg-inner a {
text-decoration: none;
color: RGBA(0, 0, 0, 0.6);
font-weight: bold;
}
.top-msg-inner a:hover {
color: RGBA(0, 0, 0, 0.5);
}
.top-msg-inner {
float: left;
box-sizing: border-box;
padding: 0 10px;
width: calc(100% - 110px);
}
.top-msg-ico {
float: left;
width: 65px;
height: 57px;
background-color: #fff;
background-color: rgba(0,0,0,0.7);
text-align: center;
font-size: 45px;
}
<div class="top-msg">
<div class="top-msg-ico">
!
</div>
<div class="top-msg-inner">
<p>Only letters and nubers are allowed for email. See security for more info.</p>
</div>
<div class="top-msg-close" style="cursor: pointer;">✕</div>
</div>
replace the width: 80% with margin-right: 40px, and you'll have to play around with the top: 15px as well (at -11 I had it looking right, but you can play around with that)
Here is the updated Fiddle
If you want everything scalable you'll need a completely different approach. First of all, if you place a right floating element under a block element it will float right, but underneath it. You'll need to define the floating close button element first.
Anyway, here's the updated Fiddle
It needs some minor tweaks in the padding and margins, but I think this is very close to what you're looking for

horizontal white space between div tags

Can anyone please let me know why the following code produces white space between the div "content-main', and the two introduction divs, which sit above the main content?
.header {
width: inherit;
background-color: #58614E;
height: 8em;
position: relative;
z-index: 2;
}
.header-logo {
float: left;
display: inline-block;
}
#header-home-link {
color: white;
font-weight: bold;
margin-left: 3em;
position: relative;
top: 1em;
}
.header a:link {
color: #C5EBF9;
position: relative;
top: 1em;
padding-left: 1em;
}
.introduction-left {
background-color: #EEEEEE;
width: 55%;
padding-bottom: 1em;
padding-right: 1.0em;
padding-top: 1em;
border-right-style: dotted;
border-right-width: 1px;
float: left;
overflow: auto;
}
.introduction-left h2 {
color: #57614E;
padding-left: 13em;
}
.introduction-left p {
color: #626262;
padding-left: 2.0em;
z-index: 2;
}
.introduction-right {
background-color: #EEEEEE;
width: 40%;
float: right;
z-index: 0;
padding-right: 3.3em;
padding-top: 2em;
padding-bottom: 3.7em;
}
.introduction-right h2 {
color: #57614E;
font-style: italic;
position: relative;
left: 3em;
bottom: 0.5em;
margin: 0;
}
.introduction-right p {
padding-left: 1em;
color: #57614E;
}
.content-main {
background-color: #E2E2E2;
border-style: solid;
border-width: 1em;
border-color: white;
width: 100%;
overflow: auto;
}
.content-main h3 {
color: #728063;
font-style: italic;
padding-left: 15em;
}
<div class="header">
</div>
<div class="introduction-left">
<h2>Today's News</h2>
<p>This website template has been designed by Free Website Templates for you, for free. You can replace all this text with your own text. You can remove any link to our website from this website template, you're free to use this website template without
linking back to us. If you're having problems editing this website template, then don't hesitate to ask for help on the Forums.</p>
</div>
<div class="introduction-right">
<h2>Testimonials</h2>
<p>"You can remove any link to our website from this website template, you're free to use this website template without linking back to us.”
</p>
</div>
<div class="content-main">
<h3>Main Articles.</h3>
</div>
I think because,you use
.content-main{
border-style: solid;
border-width: 1em;
Try to use
.content-main{
background-color: #E2E2E2;
border-style: none;
width: 100%;
overflow:auto;
In your css, I see (last Chrome in Linux)
when I use border-style: none, I get (second div with main-context without space):
It's what you want?
Quick answer - not necessarily right:
Try removing all padding statements in CSS temporarily and see how it looks...
Then add them back in as desired.
The spaces between your elements are causing the white space to appear. Put in some sort of wrapper and give it font-size: 0, then give the divs with text a font-size: initial, or if you care about making it IE compatible give it font-size: 16px or whatever, since font-size: initial doesn't work on IE.

Div Attached to side of wrapper

I am trying to add a div to the side of my wrapper. It will be a link / button.
I want it to be able to slide up and down, fixed to the right hand side border when scrolling.
The button is:
#booknow {
position: absolute;
right: 0;
margin-left:25px;
text-align:center;
font-family: 'Raleway',sans-serif;
font-size:22px;
color:#ffffff!important;
font-weight:700;
line-height:26px!important;
text-transform:uppercase;
}
And the inner wrapper (Where the border is), is:
.wrapper_inner{
position:relative;
z-index:10!important;
padding:30px!important;
background:#fff!important;
border:1px solid #D4D4D4!important; }
HTML:
<div class="wrapper">
<div class="wrapper_inner">
<div id="booknow">
Book <br> Now
</div>
</div>
</div>
At the minute I have this:
If I set it to fixed it slides up and down but it won't position perfectly to the outside of .wrapper_inner.
The HTML wasn't that helpful, so I just threw something together. The color scheme is to display the elements. I removed .inner_wrapper and added the surrounding layout so it would be possible to demonstrate that #booknow floats. If you click the #booknow it'll scroll down to a faux form at the bottom.
Demo: https://plnkr.co/edit/qACqW4O4rJn7YHoPRWLy?p=preview
Full screen: https://run.plnkr.co/njw73AIIIuHXEooM/
Relevant CSS
body {
position: relative;
overflow-y: scroll;
overflow-x:hidden;
font: 500 16px/1.4 'Arial';
min-height: 100vh;
}
.spacer {
position: absolute;
bottom: -200px;
height: 60%;
}
#booknow {
position: fixed;
top: 30px;
right: 0;
float: right;
margin-left: 25px;
text-align: center;
font-family: 'Raleway', sans-serif;
font-size: 22px;
color: #ffffff;
font-weight: 700;
line-height: 26px;
font-variant: small-caps;
z-index: 10;
background: #fc3;
padding: 10px;
width: 50px;
}
.wrapper {
position: absolute;
top: -110px;
margin: 25px;
padding: 5px 10px;
width: 100%;
border: 3px double grey;
min-height: 70px;
background: #eff999;
}