How to make two vertical columns in html - html

Is there a way to have two divs in one row or have a two columns of divs. It appears as one div under the other instead of a div next to a div.
CSS
#tacoh {
margin: 200px 20% 40px 0;
float:right;
}
#hamburgerh {
margin: 200px 40px 0 20% ;
float:left;
}
HTML
<div id="hamburgerh" style="width:300px;height:350px;"></div>
<div id="tacoh" style="width:300px;height:350px;"></div>

You can either set a float left for both divs :
#tacoh {
margin: 200px 20% 40px 0;
float:left;
}
#hamburgerh {
margin: 200px 40px 0 20% ;
float:left;
}
or wrap them into a container as Marius Balaj suggested :
.container {
width:100%;
margin: 200px 0 40px;
}
#tacoh {
margin: 200px 20% 40px 0;
float:left;
}
#hamburgerh {
margin: 200px 40px 0 20% ;
float:left;
}
with the following html :
<div class="container">
<div id="hamburgerh" style="width:300px;height:350px;"></div>
<div id="tacoh" style="width:300px;height:350px;"></div>
</div>
Also since your style is the same for both divs, you could also create a class for them like below :
.w_300_h_350{
width:300px;
height:350px;
}
and apply it to you html like this :
<div id="hamburgerh" class="w_300h_350"></div>
<div id="tacoh" class="w_300h_350"></div>

Wrapit inside a container.
http://jsbin.com/qediqoxiwo/edit?css,output
.container {
width:100%;
margin: 200px 0 40px;
}
.col {
float:left;
width: 300px;
height: 350px;
background:blue;
}
.col:last-child {
float:right;
background: red;
}

Related

html/css responsive 3-column layout - stack right column below left column

I'm trying to get the right column of a 3 column layout to move below the left column on smaller screens. Right now the right column moves in the correct direction except that it hangs below the middle column.
I created this basic simulation of my issue. Note the middle column will always be longer than the left and right columns as shown here.
<style>
.container {
max-width:1280px;
width:100%;
height:200px;
margin-left:auto;
margin-right:auto;
display:flex;
flex-wrap: wrap;
}
.leftsidebar {
width:20%;
height:200px;
background-color:gray;
margin-top:15px;
}
.middle {
width:57%;
background-color:blue;
margin-left:15px;
margin-right:15px;
height:800px;
margin-top:15px;
}
.rightsidebar {
width:20%;
background-color:orange;
height:200px;
margin-top:15px;
}
</style>
<div class="container">
<div class="leftsidebar">left</div>
<div class="middle">middle</div>
<div class="rightsidebar">right</div>
</div>
You can't accomplish that with Flexbox, unless setting fixed height's all over.
Here is a solution that combine Flexbox with float, and use a media query to swap between the two, when on narrower screens.
Note, when using percent based width combined with fixed margins, it can at some point cause the item to wrap. Use CSS Calc to avoid that, as showed in the answer.
Stack snippet
.container {
max-width: 1280px;
height: 200px;
margin: 0 auto;
display: flex;
}
.leftsidebar, .rightsidebar {
width: 20%;
background-color: gray;
margin-top: 15px;
}
.rightsidebar {
background-color: orange;
clear: left;
}
.middle {
width: calc(60% - 30px); /* calc for margin */
background-color: blue;
margin: 15px 15px 0 15px;
height: 800px;
}
#media (max-width: 600px) {
.container {
display: block;
}
.leftsidebar, .rightsidebar {
height: 200px;
float: left;
}
.middle {
width: calc(80% - 30px); /* calc for margin */
float: right;
}
}
<div class="container">
<div class="leftsidebar">left </div>
<div class="middle">middle </div>
<div class="rightsidebar">right </div>
</div>
I could come up only with old good floats, no flexboxes at all. If you don't have to use flexboxes and you are interested, with pretty light hustle it might look like this (snap point is 700px):
* {
box-sizing: border-box;
}
.container {
width:90%;
height:200px;
margin:0px auto;
}
div > div {
background-color: orange;
float: left;
color: white;
text-align: center;
padding: 1em;
}
.leftsidebar {
width: 20%;
height: 200px;
margin-top: 15px;
}
.middle{
width:56%;
margin: 15px 2% 0%;
height:415px;
}
.rightsidebar {
width: 20%;
height: 200px;
margin-top: 15px;
}
#media (max-width: 700px) {
div > div:nth-of-type(2n + 1) {
width: 33%;
}
div > div:nth-of-type(2n) {
float: right;
width: 65%;
margin-right: 0%;
}
}
<div class="container">
<div class="leftsidebar">left </div>
<div class="middle">middle </div>
<div class="rightsidebar">right </div>
</div>

Make this div responsive

I have tried width 100% but it didn't make it responsive. Here is link of what I'm trying to make responsive. It is not responsive. Help codepen link
div {
background:url(https://i.stack.imgur.com/EinaJ.png) top center;
width:620px;
margin:auto;
padding:40px 40px 30px;
height:590px;
position:relative;
display:flex;
flex-flow:column;
justify-content:center;
}
img, p, footer {
padding:5px;
margin:0;
background:pink
}
img {
margin:auto auto 0;
}
footer {
bottom:30px;
right:45px;
margin:auto 0 0;
border-radius:0 0 0.25em 0.25em ;
background:rgba(0,0,0,0.2);
}
<div>
<img src="">
<p>here is</p>
<footer>footer</footer>
</div>
The reason this is not responsive is because you have set the div's width and height to a specific pixel. Therefore it is not able to adjust.
Try changing the pixel to a percentage:
For example:
width: 50%;
height: 100%;
:root {
/*the percentage of screen width occupied by a block. 1 = 100% */
--percent: .9;
}
div {
background: url(https://i.stack.imgur.com/EinaJ.png) top center;
background-size: cover;
/* for old browsers */
width: 90vw;
height: 113.61516034vw;
/* for new browsers */
width: calc(100vw*var(--percent));
height: calc((100vw*var(--percent))*866/686);
box-sizing: border-box;
margin: auto;
padding: 40px 40px 30px;
position: relative;
display: flex;
flex-flow: column;
justify-content: center;
}
img,
p,
footer {
padding: 5px;
margin: 0;
/* see me */
background: pink
}
img {
margin: auto auto 0;
}
footer {
bottom: 30px;
right: 45px;
margin: auto 0 0;
border-radius: 0 0 0.25em 0.25em;
/* see me */
background: rgba(0, 0, 0, 0.2);
}
body {
background: #777;
}
<div>
<img src="http://lorempixel.com/200/150" />
<p>here is</p>
<p>some line</p>
<p>of</p>
<p>text</p>
<footer>footer</footer>
</div>
I see what you're trying to do.You're trying to have the div in the middle center and responsive.Set margin:0 auto; and width:50%;.Get rid of other bits of codes in the div.To make it responsive to mobile screen do:
#media only screen and (max-width:set_your_max){
div { width:50%; }
}

Footer is not displaying properly on mobile devices

Website: ifnrussiacisforum.ru
It is 100% width on PC, but there's some empty space on mobile, likt this:
The code is:
HTML:
<div class="footer">
<div class="container">
<img src="images/logo-img.jpg" alt="beeboss" />
</div>
</div>
CSS:
.footer {
height: 60px;
width: 100%;
background: #000;
}
.footer .container {
width: 1003px;
margin: 0 auto;
}
.footer .container img {
margin:19px 0px 0px 20px;
}
Use this CSS code
CSS:
.footer .container {
width: 100%;
margin: 0 auto;
}
.footer .container img {
margin:19px 0px 0px 20px;
}
Solved the issue with this code:
html, body {
min-width: 1003px;
}
Weave: http://kodeweave.sourceforge.net/editor/#58fb912e2d456f902a77b8ebc76aa515
By default the body tag has a margin. You can fix that by either incorporating Normalize into your CSS or remove the margin in from your body.
EDIT: No wonder why your width was so grotesque you defined 800px and 1003px on most of your containers. Plus your CSS fairly very WET!
Change the following classes width to 100%
.footer .container
.main
.header
Then replace min-width/change your width from 800px && 1003px to 80% for the following classes.
.extra-bally
.request-form
.link
.plashka
.bally
.mac
Also focus on making your code more DRY.
body {
margin: 0;
}
.footer {
height: 60px;
width: 100%;
background: #000;
}
.footer .container {
width: 100%;
margin: 0 auto;
}
.footer .container img {
margin: 19px 0 0 20px;
}
<div class="footer">
<div class="container">
<img src="https://forums.gota.io/images/smilies/smile.png" alt="beeboss" />
</div>
</div>

Trying to extend inner div height past container div height

I'm trying to create an effect where the blue section extends past the gray section.
The blue section is currently contained within the gray section, which may be the problem.
http://nufios.com/node
I've got this as the HTML:
<div id="header-wrapper">
<div id="header">
...
</div></div>
And this as the CSS:
#header-wrapper {
width: 100%;
background-color: #686868;
}
#header {
width: 60%;
background-color: #45719E;
margin: 0 auto;
padding: 0 2em 2em 2em;
position: relative;
}
How do I get it so that the blue section is centered within the gray section, and can still go down below the gray section (i.e., the height is greater on the blue section).
Try using z-index and fixed heights:
CSS:
#header-wrapper {
width: 100%;
background-color: #686868;
height:30px;
}
#header {
width: 60%;
background-color: #45719E;
margin: 0 auto;
padding: 0 2em 2em 2em;
position: relative;
z-index:10;
height:50px;
}
jFiddle demo here: http://jsfiddle.net/LynchJustRules/RQV4h/
Just give your #header-wrapper height. If you want to always fit the blue box's height when its height is less than the gray box's, set the max-height
#header-wrapper {
width: 100%;
background-color: #686868;
max-height: 92px;
}

How can I achieve fluid margins on my site with CSS?

On my site, I have a fixed-width central wrapper, which I don't want to change in size, but I do want to margins to be resized depending on the size of the user's screen. I tried wrapping everything in one div called wrapper-outer and then centering it by margin: 0 auto but it doesn't seem to work.
Site: http://antonpug.com/mainepark/
CSS:
body {
font-family: "Nobile", sans-serif;
font-size:0.75em;
text-align:center;
min-width:1550px;
}
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
z-index:-1;
}
h3 {
font-size:1.25em;
}
header h1, header h2 {
font-family: "Ubuntu", sans-serif;
}
header h1 {
font-size:3em;
margin:25px 0 0 0;
}
header h2 {
font-size:2em;
margin:0 0 25px 0;
}
#wrapper-inner {
margin:25px 100px 25px 100px;
padding:15px 0 15px 0;
background-color:rgba(255,255,255,0.75);
moz-border-radius: 10px;
webkit-border-radius: 10px;
border-radius: 10px;
}
#wrapper-outer {
width:1500px; -- that didn't work either!!!
margin: 0px auto;
}
#feature {
display:inline-block;
width:80%;
margin:15px;
}
.column {
display: inline-block;
vertical-align:top;
width:600px;
margin:15px;
}
#col-1 {
text-align:right;
}
#col-2 {
text-align:left;
}
.section {
margin:0 0 25px 0;
height:450px;
}
footer {
color:#909090;
}
footer a {
margin: 0 0 25px 0;
text-decoration:none;
color:#909090;
}
Remove min-width on the body. If the minimum width for the body is greater than your content wrapper, scrollbars will show before the fluid margins can do their thing.
Change the margins on div#wrapper-inner to:
margin: 25px 0; //previous values had 100px margins for left/right which add to width per box model
Finally, adjust div#wrapper-outer to the width of your content like SLaks suggested.
You need to add a fixed width to the centered wrapper.
Just add a percentage margin to your col-1 div so your margins adapt fluidly.
Something like 8% looks good.
CSS
#col-1 {
margin-right: 8%;
}
Also, remove the margin declaration on your col-2 div so your margins adapt proportionally.