Design help using css - css

I need to achieve a nice 2 column layout as shown in
So far i could get only: https://jsfiddle.net/8qskxqfh/
code in fiddle link
Could you please suggest me on improving this design.
.myRatingBoxRed {
display: inline-block;
width: 15px;
height: 15px;
background-color: red;
}
.myRatingBoxYellow {
display: inline-block;
width: 15px;
height: 15px;
background-color: yellow;
}
.myRatingBoxGreen {
display: inline-block;
width: 15px;
height: 15px;
background-color: green;
}
.myResourceViewBody {
width: 960px;
position: relative;
margin: 0 auto;
}
.myResourceViewBody.myResourceSideBar {
position: absolute;
left: 0;
width: 240px;
height: 100%;
min-height: 800px;
color: #fff;
}
.myResourceViewInfo {
background: #fff;
padding-left: 300px;
}
.myResourceViewInfo .section-title {
text-transform: uppercase;
font-size: 20px;
font-weight: 500;
color: #2d7788;
position: relative;
margin-top: 0;
margin-bottom: 20px;
}
.myResourceViewInfo .attributes-section .item {
margin-bottom: 15px;
}
.h2.myResourceTitle {
font-weight: bold;
background: #9A3324 none repeat scroll 0px 0px;
width: 66%;
padding-left: 5px;
color: #FFF;
font-size: 18px;
vertical-align: middle;
display: inline-block;
position: relative;
height: 50px;
padding-top: inherit;
margin-top: 4px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.myResourceViewBody ul {
font-size: 1.2em;
font-weight: bold;
list-style-type: none;
margin-left: 300px;
padding: 0 0 0 10px;
}
<div id="myResourceHeader">
<h2 class="header-title myResourceTitle">Test article 1</h2>
</div>
<div class="myResourceViewBody">
<div class="myResourceSideBar">
<div class="myImageBox"></div>
<div class="myEvaluationArea">
<div class="myRatingBoxRed"></div>
<div class="myRatingBoxYellow"></div>
<div class="myRatingBoxGreen"></div>
</div>
</div>
<div class="myResourceViewInfo">
<h2 class="myViewInfo section-title"><i class="fa icon-info-sign"></i>Description</h2>
<ul>
<li>demo 1</li>
<li>demo 2</li>
</ul>
</div>
</div>
<div class="myResourceViewFooter"></div>

Check example below:
.row {
display: table;
width: 100%;
}
.row:after {
clear: both;
}
.col {
display: table-cell;
border: 1px solid red;
}
.width-70 {
width: 70%;
}
.width-30 {
width: 30%;
}
<div class="row">
<div class="col width-30">
col1
</div>
<div class="col width-70">
col2
</div>
</div>

Try using col-spans inside row
something like this
<div class="row">
<div class="col-md-6">
//first column
</div>
<div class="col-md-6">
// second column
</div>
</div>
refer to bootstrap classes for more details and how to make it responsive also.

Related

Dropdown div doesn't push down the content

I've got a dropdown from header div which has to push down the content(e.g. when you click This is Icon it appears Blue dropdown which has to push down h1 tags).
The problem is the height of two classes(header-bar__top, header-bar) which I can't change and I need them to be the same height. Is there a way to do that?
I can manipulate only these classes: .header-bar-mobile-drop-down__container, .header-bar-mobile-drop-down__item, .header-bar-mobile-drop-down__icon-button
.header-bar-mobile-drop-down__container {
color: #fff;
display: block;
font-size: 16px;
line-height: 1.5rem;
cursor: pointer;
}
.header-bar-mobile-drop-down__item {
display: none;
align-items: center;
text-align: center;
}
.header-bar-mobile-drop-down__icon-button {
color: #fff;
border: none;
background-color: transparent;
font-size: 1.5rem;
}
.header-bar-mobile-drop-down__icon-button:focus+.header-bar-mobile-drop-down__item {
display: block;
margin-top: 26px;
height: 68px;
color: black;
background-color: blue;
}
.header-bar {
height: 3.5rem;
box-shadow: none;
background-color: orange;
}
.header-bar__top {
height: 3.5rem;
z-index: 100;
}
.header-bar__container {
position: relative;
height: 100%;
margin-right: auto;
margin-left: auto;
max-width: 1152px;
}
.header-bar__container:after {
content: "";
display: table;
clear: both;
}
<div>
<div class="header-bar">
<div class="header-bar__top">
<div class="header-bar__container">
<div class="header-bar-mobile-drop-down__container">
<button class="header-bar-mobile-drop-down__icon-button" tabindex="1">
This is Icon
</button>
<div class="header-bar-mobile-drop-down__item">
This is my drop down
</div>
</div>
</div>
</div>
</div>
<h1>This need to be pushed down</h1>
<h1>But instead</h1>
<h1>The dropdown is getting overlayed</h1>
</div>
use min-height instead of height on the header bar and header bar top otherwise it will stay the same height and the drop down will be show as overflow (which is why the content below doesn't move)
.header-bar-mobile-drop-down__container {
color: #fff;
display: block;
font-size: 16px;
line-height: 1.5rem;
cursor: pointer;
}
.header-bar-mobile-drop-down__item {
display: none;
align-items: center;
text-align: center;
}
.header-bar-mobile-drop-down__icon-button {
color: #fff;
border: none;
background-color: transparent;
font-size: 1.5rem;
}
.header-bar-mobile-drop-down__icon-button:focus+.header-bar-mobile-drop-down__item {
display: block;
margin-top: 26px;
height: 68px;
color: black;
background-color: blue;
}
.header-bar {
min-height: 3.5rem;
box-shadow: none;
background-color: orange;
}
.header-bar__top {
min-height: 3.5rem;
z-index: 100;
}
.header-bar__container {
position: relative;
height: 100%;
margin-right: auto;
margin-left: auto;
max-width: 1152px;
}
.header-bar__container:after {
content: "";
display: table;
clear: both;
}
<div>
<div class="header-bar">
<div class="header-bar__top">
<div class="header-bar__container">
<div class="header-bar-mobile-drop-down__container">
<button class="header-bar-mobile-drop-down__icon-button" tabindex="1">
This is Icon
</button>
<div class="header-bar-mobile-drop-down__item">
This is my drop down
</div>
</div>
</div>
</div>
</div>
<h1>This need to be pushed down</h1>
<h1>But instead</h1>
<h1>The dropdown is getting overlayed</h1>
</div>
If you can't change the height of the two classes, then I would move the drop down outside the header and use a checkbox toggle instead:
.header-bar-mobile-drop-down__container {
color: #fff;
display: block;
font-size: 16px;
line-height: 1.5rem;
cursor: pointer;
}
.header-bar-mobile-drop-down__icon-button {
color: #fff;
border: none;
background-color: transparent;
font-size: 1.5rem;
cursor: pointer;
}
#dropdown-toggle {
display: none;
}
.header-bar-mobile-drop-down__item {
display: none;
align-items: center;
text-align: center;
height: 68px;
color: black;
background-color: blue;
}
#dropdown-toggle:checked+.header-bar-mobile-drop-down__item {
display: block;
}
.header-bar {
height: 3.5rem;
box-shadow: none;
background-color: orange;
}
.header-bar__top {
height: 3.5rem;
z-index: 100;
}
.header-bar__container {
position: relative;
height: 100%;
margin-right: auto;
margin-left: auto;
max-width: 1152px;
}
.header-bar__container:after {
content: "";
display: table;
clear: both;
}
<div>
<div class="header-bar">
<div class="header-bar__top">
<div class="header-bar__container">
<div class="header-bar-mobile-drop-down__container">
<label for="dropdown-toggle" class="header-bar-mobile-drop-down__icon-button" tabindex="1">
This is Icon
</label>
</div>
</div>
</div>
</div>
<input id="dropdown-toggle" type="checkbox">
<div class="header-bar-mobile-drop-down__item">
This is my drop down
</div>
<h1>This need to be pushed down</h1>
<h1>But instead</h1>
<h1>The dropdown is getting overlayed</h1>
</div>

Relative positioned div next to other div makes div offset from top [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 8 months ago.
I have a panel with a bunch of items in list-like fashion. I want 3 different panels, but two on the left next to each other. I styled the panels the way I want, but when I copy-paste it to create another, it makes the div, but offsets it from the top.
Here's what I have right now:
html, body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
color: #ededed;
font-family: Roboto;
}
.panel {
display: inline-block;
width: 15vw;
height: 100%;
border-right: 1px solid #272b3a;
background-color: #e0e0e0;
color: #000000;
margin: 0;
padding: 0;
padding-top: 20px;
padding-left: 15px;
position: relative;
margin-top: 0px;
}
.folder {
display: inline-flex;
align-items: center;
cursor: pointer;
margin: 0;
padding:0;
}
.folder-icon {
width: 30px;
}
.folder-name {
margin: 0;
margin-left: 6px;
top: 12px;
}
.add-folder {
cursor: pointer;
margin-left: -15px;
position: absolute;
bottom: 30px;
text-align: center;
width: calc(100% - 15px);
display:flex;
align-items: center;
justify-content: center;
}
.add-folder-text {
font-size: 15px;
margin: 0;
margin-bottom: 10px;
padding-left: 20%;
padding-right: 20%;
padding-top: 5%;
padding-bottom: 5%;
border-radius: 30px;
}
<div class="panel">
<div class="folder">
<p class="folder-name">Item 1</p>
</div>
<div class="folder">
<p class="folder-name">Item 2</p>
</div>
<div class="folder">
<p class="folder-name">Item 3</p>
</div>
<div class="folder">
<p class="folder-name">Item 4</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>
<div class="panel">
<div class="folder">
<p class="folder-name">Social Networking</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>
I added display: flex to the <body> CSS selector and is working.
because normally the body has a display: block by default. and flex put the element one near the other on the X-axis (and have other behaviors that solve this problem).
body {
display: flex; /*if you want you can use also "inline-flex" like you do for the other elements on your CSS file*/
}
html,
body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
color: #ededed;
font-family: Roboto;
/* what I added */
display: flex;
}
.panel {
display: inline-block;
width: 15vw;
height: 100%;
border-right: 1px solid #272b3a;
background-color: #e0e0e0;
color: #000000;
margin: 0;
padding: 0;
padding-top: 20px;
padding-left: 15px;
position: relative;
margin-top: 0px;
}
.folder {
display: inline-flex;
align-items: center;
cursor: pointer;
margin: 0;
padding: 0;
}
.folder-icon {
width: 30px;
}
.folder-name {
margin: 0;
margin-left: 6px;
top: 12px;
}
.add-folder {
cursor: pointer;
margin-left: -15px;
position: absolute;
bottom: 30px;
text-align: center;
width: calc(100% - 15px);
display: flex;
align-items: center;
justify-content: center;
}
.add-folder-text {
font-size: 15px;
margin: 0;
margin-bottom: 10px;
padding-left: 20%;
padding-right: 20%;
padding-top: 5%;
padding-bottom: 5%;
border-radius: 30px;
}
<div class="panel">
<div class="folder">
<p class="folder-name">Item 1</p>
</div>
<div class="folder">
<p class="folder-name">Item 2</p>
</div>
<div class="folder">
<p class="folder-name">Item 3</p>
</div>
<div class="folder">
<p class="folder-name">Item 4</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>
<div class="panel">
<div class="folder">
<p class="folder-name">Social Networking</p>
</div>
<div class="add-folder">
<p class="add-folder-text plus">Add folder</p>
</div>
</div>

Text stuck in middle of div instead of far left

As you can see i goes straight to the middle instead of the starting point of the div. I have set a margin and width for my div and when I do input an <H1> tag, the text just floats to the middle of the div instead of the far left where the div begins. I have set the width so it can start at that starting point not 45px to the left.
This is the HTML
<div id="topbar">
<div id="logo"> <img src="Pictures/bbc.png"> </div>
<div id="signin" class="border-part"> </div>
<div> <img id="logo-image" src="Pictures/signin.png">
<p class="signin-text">Sign in</p>
</div>
<div id="dash"> <img id="dash-image" src="Pictures/bash2.png"> </div>
<div> <img id="bell"src="Pictures/bell3.png"> </div>
<div class="border-part stuff-section"> News </div>
<div class="border-part stuff-section"> Sport </div>
<div class="border-part stuff-section"> Weather </div>
<div class="border-part stuff-section"> iPlayer </div>
<div class="border-part stuff-section"> TV </div>
<div class="border-part stuff-section"> Radio </div>
<div class="border-part stuff-section"> More </div>
<div class="seacher-border">
<input id="search-box" type="text" placeholder="Search">
<img id="search-pic" src="Pictures/search.png"> </div>
</div>
<div id="second-bar">
<div id="newsbar">
<h1>NEWS</h1>
</div>
</div>
This is my CSS
#topbar {
width: 1080px;
margin: 0 auto;
height: 40px;
}
body {
margin: 0;
padding: 0;
font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
;
}
#logo {
margin-top: 8px;
float: left;
margin-right: 8px;
}
.border-part {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
}
#logo-image {
width: 20px;
margin: 12px;
float: left;
}
.signin-text {
margin: 14px;
font-size: 90%;
font-weight: bold;
float: left;
}
#dash-image {
padding-left: 50px;
float: left;
height: 40px;
}
#bell {
margin: 8px;
height: 28px;
float: left;
}
.stuff-section {
font-weight: bold;
font-size: 90%;
padding: 13px 15px 0 15px;
height: 27px;
}
.seacher-border {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
margin-left: 20px;
}
#search-box {
margin: 10px;
font-weight: bold;
background-color: #E4E4E4;
font-size: 14px;
border: none;
height: 24px;
float: left;
}
#search-pic {
position: relative;
right: 10px;
top: 10px;
height: 25px;
}
#second-bar {
background-color: #BB1919;
width: 100%;
height: 80px;
}
#newsbar {
width: 1080px;
margin: 0 auto;
background-color: blue;
}
h1 {
padding: 0;
margin: 0;
float;
}
A flexbox option for alignment
#second-bar {
display: flex;
background-color: #BB1919;
width: 100%;
height: 80px;
}
#newsbar {
display: flex;
justify-content: flex-start; /* horizontal alignment - change to flex-end or center to see difference */
align-items: center; /* vertical alignment */
width: 100%;
margin:0 auto;
}
h1 {
display: flex;
padding:0;
margin:0;
}
<div id="second-bar">
<div id="newsbar">
<h1>NEWS</h1>
</div>
</div>
fiddle
https://jsfiddle.net/Hastig/zn4qkok2/
A possible non-flexbox solution
#second-bar {
background-color: #BB1919;
width: 100%;
height: 80px;
}
#newsbar {
text-align: left; /* change to center or right to see difference */
vertical-align: middle;
width: 100%;
line-height: 80px; /* match to height of parent for centered vertical alignment */
margin:0 auto;
}
h1 {
display: inline-block;
padding:0;
margin:0;
}
<div id="second-bar">
<div id="newsbar">
<h1>NEWS</h1>
</div>
</div>
fiddle
https://jsfiddle.net/Hastig/zn4qkok2/1/
Just add clear: both to h1:
#topbar {
width: 1080px;
margin: 0 auto;
height: 40px;
}
body {
margin: 0;
padding: 0;
font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
;
}
#logo {
margin-top: 8px;
float: left;
margin-right: 8px;
}
.border-part {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
}
#logo-image {
width: 20px;
margin: 12px;
float: left;
}
.signin-text {
margin: 14px;
font-size: 90%;
font-weight: bold;
float: left;
}
#dash-image {
padding-left: 50px;
float: left;
height: 40px;
}
#bell {
margin: 8px;
height: 28px;
float: left;
}
.stuff-section {
font-weight: bold;
font-size: 90%;
padding: 13px 15px 0 15px;
height: 27px;
}
.seacher-border {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
margin-left: 20px;
}
#search-box {
margin: 10px;
font-weight: bold;
background-color: #E4E4E4;
font-size: 14px;
border: none;
height: 24px;
float: left;
}
#search-pic {
position: relative;
right: 10px;
top: 10px;
height: 25px;
}
#second-bar {
background-color: #BB1919;
width: 100%;
height: 80px;
}
#newsbar {
width: 1080px;
margin: 0 auto;
background-color: blue;
}
h1 {
padding: 0;
margin: 0;
clear: both;
}
<div id="topbar">
<div id="logo"> <img src="Pictures/bbc.png"> </div>
<div id="signin" class="border-part"> </div>
<div> <img id="logo-image" src="Pictures/signin.png">
<p class="signin-text">Sign in</p>
</div>
<div id="dash"> <img id="dash-image" src="Pictures/bash2.png"> </div>
<div> <img id="bell" src="Pictures/bell3.png"> </div>
<div class="border-part stuff-section"> News </div>
<div class="border-part stuff-section"> Sport </div>
<div class="border-part stuff-section"> Weather </div>
<div class="border-part stuff-section"> iPlayer </div>
<div class="border-part stuff-section"> TV </div>
<div class="border-part stuff-section"> Radio </div>
<div class="border-part stuff-section"> More </div>
<div class="seacher-border">
<input id="search-box" type="text" placeholder="Search">
<img id="search-pic" src="Pictures/search.png"> </div>
</div>
<div id="second-bar">
<div id="newsbar">
<h1>NEWS</h1>
</div>
</div>

How to make contents fit to divs using css

How to make the inside divs fit to the contents in the below html
I tried with display:inline-block but it moves the 2nd div to the bottom.
<div class="ms-table">
<div class="tableCol-75">
</div>
<div class="tableCol-25">
</div>
</div>
There you go:
.ms-table {
width: 80%;
}
.tableCol-70 {
float: left;
width: 70%;
border: 1px solid black;
margin-right: 10px;
}
.tableCol-25 {
float: left;
width: 25%;
border: 1px solid blue;
}
<div class="ms-table">
<div class="tableCol-70">
My name is abc and I live in ams.
</div>
<div class="tableCol-25">
I love junk food even though it is unhealthy
</div>
</div>
use display: table
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.ms-table{
display: table;
width: 100%;
height: 100px;
}
.table-cell{
display: table-cell;
vertical-align: top;
padding: 15px;
}
.tableCol-75{
width: 75%;
background: #ccc;
}
.tableCol-25{
width: 25%;
background: #000;
color: #fff;
}
<div class="ms-table">
<div class="table-cell tableCol-75">75%</div>
<div class="table-cell tableCol-25">25%</div>
</div>
use display: inline-block;
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.ms-table{
width: 100%;
min-height: 100px;
}
.table-cell{
display: inline-block;
vertical-align: top;
padding: 15px;
}
.tableCol-75{
width: 75%;
background: #ccc;
}
.tableCol-25{
width: 25%;
background: #000;
color: #fff;
}
<div class="ms-table">
<div class="table-cell tableCol-75">75%</div><!--
--><div class="table-cell tableCol-25">25%</div>
</div>

aligning multiple div, img and text in CSS - problems

I'm trying to align several DIVS, Images and text and I can't figure this out..
Here's what I'm trying to achieve:
Heres' my HTML
<div class="section5">
<div class="outer">
<div class="container1">
<img src="icon.png" width="85">
<div class="title1">Text</div>
<div class="subtitle1">Text</div>
</div>
<div class="container2">
<img src="iphone.png" width="375">
<div class="subtitle2">Text</div>
</div>
</div>
</div>
Here is my CSS:
.section5{ height: 525px; background-color: #5e6172; text-align: center; position: relative;}
.outer{ width: 80%; background-color: #45da45; height: 100%; margin: 0 auto; position: relative;}
.title1{color: #ffffff; font-size: 2.6em; font-family: h35; }
.subtitle1{color: #ffffff; font-size: 1.5em; font-family: h35; margin-top: 0.25em; }
.subtitle2{color: #ffffff; font-size: 1.5em; font-family: h35; margin-top: 0.25em; }
.container1{display: block; background-color: #ccc; }
.container2{display: block; background-color: #fffc1e; }
Here is the JSFIDDLE:
http://jsfiddle.net/mib92/hogwohf8/
My current problems:
1) My text at the bottom needs to be on the right side of the image.. center like in my example image.
2) the bottom of my bottom picture must be align to the bottom of container2 AND the bottom of section5
3) While doing this, the container 1 must remain in the vertical middle of the remaining space of the section5.
Thank you
I hops it's help you.
.section5 {
height: 525px;
background-color: #5e6172;
text-align: center;
position: relative;
}
.outer {
width: 80%;
background-color: #45da45;
height: 100%;
margin: 0 auto;
position: relative;
}
.title1 {
color: #ffffff;
font-size: 2.6em;
font-family: h35;
}
.subtitle1 {
color: #ffffff;
font-size: 1.5em;
font-family: h35;
margin-top: 0.25em;
}
.subtitle2 {
color: #ffffff;
font-size: 1.5em;
font-family: h35;
margin-top: 0.25em;
}
.container1 {
display: block;
background-color: #ccc;
}
.container2 {
display: block;
background-color: #fffc1e;
}
.right-sied {
display: inline-block;
vertical-align: top;
width: 41%;
}
.left-sied {
display: inline-block;
width: 49%;
}
.left-sied img {
max-width: 100%;
}
<div class="section5">
<div class="outer">
<div class="container1">
<img src="icon.png" width="85">
<div class="title1">Text</div>
<div class="subtitle1">Text</div>
</div>
<div class="container2">
<div class="left-sied">
<img src="iphone.png" width="375">
</div>
<div class="right-sied">
<div class="subtitle2">Text</div>
</div>
</div>
</div>
</div>
Live Demo
check this:
.section5 {
height: 525px;
background-color: #5e6172;
text-align: center;
position: relative;
}
.outer {
width: 80%;
background-color: #45da45;
height: 100%;
margin: 0 auto;
position: relative;
}
.title1 {
color: #ffffff;
font-size: 2.6em;
font-family: h35;
}
.subtitle1 {
color: #ffffff;
font-size: 1.5em;
font-family: h35;
margin-top: 0.25em;
}
.subtitle2 {
color: #ffffff;
font-size: 1.5em;
font-family: h35;
margin-top: 0.25em;
}
.container1 {
display: block;
background-color: #ccc;
}
.container2 {
display: block;
background-color: #fffc1e;
}
.container1 .wrapper {
display: inline-block;
float: right;
}
.container2 img {
margin: 0 auto;
}
<div class="section5">
<div class="outer">
<div class="container1">
<img src="http://images.all-free-download.com/images/graphiclarge/daisy_pollen_flower_220533.jpg" width="85">
<div class="wrapper">
<div class="title1">Text</div>
<div class="subtitle1">Text</div>
</div>
</div>
<div class="container2">
<div class="subtitle2">Text</div>
<img src="http://images.all-free-download.com/images/graphiclarge/daisy_pollen_flower_220533.jpg" width="375">
</div>
</div>
</div>

Resources