I'm designing a webpage, but I'm a total HTML/CSS newbie. I want the following format:
A top half, and a bottom half.
The top half contains 6 big boxes, organized into two columns of 3 boxes.
The bottom half contains some other content, whatever I want.
Right now I (somehow) have it working, but the only thing is the "bottom_half" is too close to the "top_half" -- I just want to add a bit more of a margin in between. But when I tried doing that weird things would happen and I don't understand what I'm doing wrong.
Here's an outline of my html layout:
<div class="top_half">
<div class="left_half">
<div class="big_box">
<!-- box 1 content -->
</div>
<div class="big_box">
<!-- box 2 content -->
</div>
<div class="big_box">
<!-- box 3 content -->
</div>
</div> <!-- left-half -->
<div class="right_half">
<div class="big_box">
<!-- box 4 content -->
</div>
<div class="big_box">
<!-- box 5 content -->
</div>
<div class="big_box">
<!-- box 6 content -->
</div>
</div> <!-- right-half -->
</div> <!-- top-half -->
<div class="bottom_half">
<!-- bottom-half content -->
</div>
My CSS for top and bottom half look like this:
.top_half {
height: auto;
width: auto;
margin-top: 70px;
padding-top: 70px;
background: lightgreen
}
.bottom_half {
height: auto;
width: auto;
margin-top: 70px;
padding-top: 70px;
background: lightyellow;
}
Oddly, the top_half div is just a pretty tiny bar at the top of the page, and bottom_half div is taking basically the entire page.
Is my layout bad? Should I be doing it differently? I really have no experience with this at all, so I'm learning as I go along.
Thanks!
EDIT:
Fixed some typos. Take a look at this to see what I mean: https://jsfiddle.net/d7ejv3ad/3/
^^ why aren't the grey boxes staying inside the green bar???
Demo: https://jsfiddle.net/d7ejv3ad/
HTML
<main>
<div>
<div>
<div class="boxes"></div>
<div class="boxes"></div>
<div class="boxes"></div>
</div>
<div>
<div class="boxes"></div>
<div class="boxes"></div>
<div class="boxes"></div>
</div>
</div>
<div>
Content
</div>
</main>
CSS
main > div:first-child {
height: 50vh;
width: auto;
background: lightgreen
}
main > div:first-child > div { display: inline-block; height: 100%; width: 49%; }
main > div:first-child .boxes {
margin: 2.5% 0 0 2.5%;
width: 28%;
height: 28%;
background: #fff;
}
main > div:last-child {
height: 50vh;
width: auto;
padding: 50px;
background: lightyellow;
}
there is a typing error in second line of HTML code <div class="left_half> this should be like <div class="left_half">
additionally add this one line in your CSS
.big_box{display:inline;}
Related
I want to display it like this:
.
However the container wont center / cover the entire screen for the other columns to be side by side (I left out the left/right column in css, because I'm trying to find out how to make it work + the container just defaults to the top left of the screen.) Also how do I get them side by side like the layout, inside the entire screen container?
#container {
text-align: center;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.title {
color: #eee;
font-size: 30px;
font-weight: bold;
letter-spacing: 4px;
}
<div class="container">
<div id="leftColumn">
<div class="center">
<h1 class="title">requiem.moe</h1>
<div id="center_wrap">
<div id="yt">
> youtube <
</div>
<div id="steam">
> steam <
</div>
<div id="hub">
> old theme+hub <
</div>
<div id="sharex">
> New ShareX Server <
</div>
<div id="tracks">
tracklist N/A
</div>
<div id="user">
user system N/A
</div>
<div id="aura">
aura sys TBA
</div>
</div>
<div id="rightColumn">
test
</div>
</div>
</div>
</div>
You put the rightColumn inside the leftColumn.
I recommend you using FlexBox. This is modern and most wanted.
* {
padding: 0;
margin: 0;
box-sizing: border-box
}
.container {
width: 100vw;
height: 100vh;
display: flex;
border: 2px solid black
}
.container #leftColumn {
width: 25%;
height: 100%;
background-color: green;
}
.container #rightColumn {
width: 75%;
height: 100%;
background-color: red
}
<div class="container">
<div id="leftColumn">
<div class="center">
<h1 class="title">requiem.moe</h1>
<div id="center_wrap">
<div id="yt">
> youtube <
</div>
<div id="steam">
> steam <
</div>
<div id="hub">
> old theme+hub <
</div>
<div id="sharex">
> New ShareX Server <
</div>
<div id="tracks">
tracklist N/A
</div>
<div id="user">
user system N/A
</div>
<div id="aura">
aura sys TBA
</div>
</div>
</div>
</div>
<div id="rightColumn">
test
</div>
</div>
assign display:flex; flex-direction: row; to your container class. they will cause the left column and right column display in a row.
Don't position your container at all. You even don't need your container. The body element of your html could be the container, but if you do want a container, you could add something like margin: auto (this will center anything relative to its parent element) and height: 100% with width: 100%.
Then, your left column could be something like display: block with width: 30% and your right column display: block with width 70%.
I would consider using a CSS grid layout for this though.
One thing you might find helpful is starting with something like TailwindCSS classes instead of writing your own CSS. It's a good way to learn the underlying CSS as well. For instance, here are the docs for height: 100%.
You can get started with Tailwind by simply including a link to their CND version of the Tailwind stylesheet in the head of your HTML document:
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
Use that as your "stylesheet reset" and start playing around with Tailwind layout properties and I think you'll have a better entry point into learning more complex CSS layout.
here is how to split to 2 parts:
.split {top:0; height:100%; position:absolute;}
.left {width:20%; left:0; background-color:purple;}
.right {width:80%; right:0; background-color:green;}
<div class="split left">
<p>something</p>
</div>
<div class="split right">
<p>something</p>
</div>
To split, you need to write 20% for the left part, and 80% to the right part (as you can see in the CSS).
both of the divs need to have full height (as you can see in the CSS).
I am building a webpage that is divided into 3 sections, a header, a content area and a footer. Each marked up by a div and they all belong to a wrapper div.
<div class="wrapper">
<div class="header">
<div id="logo">
<img id="headerimg" src="assets/media/logos/Full_H.png" />
</div><!-- End of logo -->
<div id="navigation">
<ul>
<li>navigation1</li>
<li>navigation2</li>
</ul>
</div><!-- End of navigation -->
</div><!-- End of header -->
<div class="container">
<p>This is a container.</p>
</div>
<div class="footer">
<p>This is a footer.</p>
</div>
</div> <!-- End of wrapper-->
The styling rules are as follows:
* {
margin: 0;
padding: 0;
border: none;
}
#wrapper {
margin-right: auto;
margin-left: auto;
width: 960px;
/*width: 96%;*/ /* Holding outermost DIV */
}
#header {
/* margin-bottom: 10p;*/
width: 940px;
height: 80px;
outline:green dashed;
}
#logo {
height: 60px;
width: 100%;
outline:blue dashed;
} /*logo - End*/
I am trying to fit the image, Full_H.png, to the top left corner of the page without losing aspect ratio and confined to the header div only. The size of this image is 450 x 50, yet when I run this code the image is not confined to the header, it overflows. Can someone tell me how to contain the image to the size of the div without losing the image's quality? Thank you. Please let me know if my information is inadequate.
Since centring my blog content my right hand sidebar has fallen down below my content.
How can I bring it back it up so it sits to the right of my page? (Between the right side border and the edge of the page).
Live link:
https://www.moneynest.co.uk/how-to-choose-a-broker/
Code:
<html>
<body class="post-template-default single single-post postid-594 single-format-standard logged-in admin-bar no-customize-support nolayout windows chrome override" itemscope itemtype="http://schema.org/WebPage"><div class="site-container">
<div class="site-inner">
<div class="content">
<div id="container">
<div class="central-container">
<div class="middle-content">
<div class="inner-post-head">
</div>
<div class="data-content">
<!--MAIN CONTENT HERE -->
</div><!-- End .middle-content -->
</div>
</div><!-- End #container -->
</div><!-- End #content -->
<aside class="sidebar sidebar-primary widget-area" role="complementary" aria-label="Primary Sidebar" itemscope itemtype="http://schema.org/WPSideBar" id="genesis-sidebar-primary"><h2 class="genesis-sidebar-title screen-reader-text">Primary Sidebar</h2><section id="text-9" class="widget widget_text"><div class="widget-wrap"> <div class="textwidget">
<!--SIDE BAR CONTENT HERE--></div>
<!--<div id="popular-articles">
<p class="popular-articles-text">Popular articles</p>
</div>-->
</div>
</div>
</div>
<section id="text-10" class="widget widget_text"><div class="widget-wrap"
</div></section>
</div>
</aside>
<!--END OF SIDEBAR--!>
<!--FOOTER STUFF-->
</body>
</html>
Running Wordpress with custom Genesis theme and Bootstrap.
Your style sheet is having below code
.site-inner, .wrap {
max-width: 1200px;
}
As you have centered your contents with margin-left, this 1200px is not enough to hold your sidebar. SO please change that to below one so that it will work for you
.site-inner, .wrap {
max-width: 100%;
}
Method 2:
Make your content part centralized through out and make your sidebar positioned to right side. Style as follows:
.site-inner{
position: relative;
}
.content {
width: 792px;
margin: 0 auto !important;
float: none;
}
.sidebar-primary {
position: absolute;
width: 240px !important;
right: 0px;
top: 0px;
}
position: fixed;
right: 0;
top: 0;
or instead make it thinner (width:80%) and give the content display: inline
As well as removing the left margin from .content, I'd also recommend removing padding from .site-inner and adding margin:0 auto;.
I tested in your page and did this. It is working. Just decrease your margin-left property in relative media queries.
#media only screen and (min-width: 1200px)
(index):27
.content {
margin-left: 10%;
}
Please check this two photos
I don't know how to get ".myDivInTheGrid" in boxed bootstrap div. Any suggestions?
I have something like this...
<div class="fluid-container">
<div class="col-md-6"></div><!-- Div with image -->
<div class="col-md-6">
<div class="myDivInTheGrid"></div>
</div><!-- div with content -->
</div>
I have created a working example with a picture in the div you showed in the picture. I made it for col-md-* but you can do the same for larger grid system. If your screen is small, stretch the browser. Check it out HERE
The code is like this:
HTML:
body
<div class="container-fluid">
.fluid-container
<div class="row">
<div class="col-md-6">
.col-md-6
</div>
<div class="col-md-6">
<div class="row">
.col-md-6
</div>
<img class="row" src="http://s22.postimg.org/8z6hs0mch/Chrysanthemum.jpg"/>
</div>
</div>
</div>
CSS:
body{
background:#8EC34D;
color: white;
}
.container-fluid {
background: #81AD4B;
position: relative;
top: 40px;
padding-bottom: 40px;
}
.col-md-6 {
background:#769C47;
height: 300px;
}
img {
width: 256px;
height: 192px;
}
I have a couple of classes there so let me post them first.
HTML:
<div class="content">
<div class="sidebar">
</div>
<div class="area">
</div>
</div><!-- content closed -->
CSS:
.content {
background-color: #eee;
height: auto;
}
.sidebar {
background-color: #555;
width: 250px;
height: auto;
padding: 10px;
float: right;
}
.area {
background-color: #777;
width: 590px;
height: auto;
padding: 10px;
}
So, you can basically see that every single class have height set on "auto". Thats good cause I want content to follow sidebar and area. And they will have plenty of content inside of them.
Now...
.sidebar is set on float:right; so it doesnt really affect to move the content that stands below. Which is footer in my case.
I am wondering how to make the object thats floating, to move the parts that are below of it, depending on auto set height.
I'm not sure I understand your question, but if you are trying to position footer underneath your content that is floated right, you need to clear the float:
<div class="content">
<div class="sidebar">
</div>
<div class="area">
</div>
<div style="clear:both"></div>
This is the footer
</div><!-- content closed -->
Jsfiddle: http://jsfiddle.net/xmw7M/1/