Responsive tree diagram - html

I'm trying to make a responsive organization chart on desktop and mobile but I'm facing a problem with my code. My diagram exceeds the size of the screen and doesn't display a scroll to see the rest of the diagram as you can see on the image below. Is there a way to put my diagram in a bootstrap container and also if there is a css framework to make diagrams more easily ?
here is the css code used as well as the html code
.tree,
.tree ul,
.tree li {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
.tree {
margin: 0 0 1em;
text-align: center;
}
.tree,
.tree ul {
display: table;
}
.tree ul {
width: 100%;
}
.tree li {
display: table-cell;
padding: .5em 0;
vertical-align: top;
}
.tree li:before {
outline: solid 1px #666;
content: "";
left: 0;
position: absolute;
right: 0;
top: 0;
}
.tree li:first-child:before {
left: 50%;
}
.tree li:last-child:before {
right: 50%;
}
.tree code,
.tree span {
display: inline-block;
margin: 0 .2em .5em;
padding: 3.7em .5em;
position: relative;
height: 150px;
width: 150px;
border-radius: 50%;
background-color: #fefefe;
}
.lineh {
margin-top: -9px !important;
margin-bottom: 0px !important;
border: 0 !important;
border-top: 2px solid !important;
width: 159px;
}
.minus-space {
margin-top: 10px !important;
}
.tree span i {
font-size: 40px
}
.tree span.level1 {
background-color: #1e1e1e;
color: yellow;
padding: 2em .5em !important;
}
.tree span.level2 {
background-color: #ffcc01;
padding: 2em .5em !important;
}
.tree span.linev {
background-color: #666 !important;
width: 2px !important;
border-radius: 0% !important;
padding: 0px !important;
margin: 0px !important;
}
.tree ul:before,
.tree code:before,
.tree span:before {
outline: solid 1px #666;
content: "";
height: .5em;
left: 50%;
position: absolute;
}
.tree ul:before {
top: -.5em;
}
.tree code:before,
.tree span:before {
top: -.55em;
}
.tree>li {
margin-top: 0;
}
.tree>li:before,
.tree>li:after,
.tree>li>code:before,
.tree>li>span:before {
outline: none;
}
<div class="container-fluid">
<ul class="tree">
<li><span class="level1"><i class="mdi mdi-bank"></i><br><b>Group board</b></span>
<ul>
<li><span class="level2"><i class="mdi mdi-bank"></i><br><b>Board committees</b></span>
<ul>
<li> <span>Audit</span>
</li>
<li> <span>Remuneration and human ressources</span>
</li>
<li> <span class="linev"></span>
<ul>
<li> <span class="level2"><i class="mdi mdi-bank"></i><br><b>Compliance
committees</b></span>
</li>
<li> <span class="linev"></span>
<ul>
<li><span>Group searching</span></li>
<li><span>Group operation</span></li>
<li><span>Strategic talent</span></li>
<li><span>Group treasure</span></li>
<li><span>Group transformation</span></li>
</ul>
</li>
<li> <span class="level2"><i class="mdi mdi-bank"></i><br><b>Executive
committees</b></span>
</li>
</ul>
</li>
<li> <span>Social ethics</span>
</li>
<li> <span>Nominations</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Thank you for all your suggestions

For this answer I used some 'CSS only' flowchart code I had lying around. This code is fully responsive and designed to be multipurpose and reusable. Actually, I took the code and basically rewrote it to make it meet your requirements and more developer readable (than only me).
Instead of UL/LI and specific .classes the CSS mainly uses <tag> independend data-* attributes, which, generally speaking, have lower precedence than .classes making them easy to override. data-* attributes are also very easy to access from Javascript.
For positioning and responsiveness, the code heavily relies on flexbox layout.
The code is fully commented, including:
Specifications, how to use the data attributes data-chart, data-knot ('branch','node','step') and data-symbol.
Explanation of the algebra used, definition of a straight line: 'y=mx+b', for responsiveness and scaling of font-size's, width's, height's and spacing (padding, margin). You can find a comprehensible reference on mathisfun (no affiliate).
Rules split after functionality (mechanism vs. styling), for easy extension and theming.
A few tips, alternative uses, quirks (IE11).
Some eye-candy, just because I could...
brief summary
data-chart the type of chart used, only "OC" (Organisation Chart) for now.
data-knot designates the connection type used between data-symbols.
data-knot="branch" (container)
data-knot="node" (horizontal line)
data-knot="step" (vertical line)
data-knot="node.step" (cross line)
data-symbol container holding graphics and text depicting some organisational function. Currently only a colored circle, but can be extended to hold more content (e.g. collapsible card, its original use).
'Landingpage' like responsive page spacing [band] (8px on a 320px screen, 320px on a 1920px screen).
Document reading direction [dir="ltr"] vs. [dir="rtl"] ready (used in <body>).
Two debugging helper rules outlines and hover (used in <body>).
Various kinds of nesting and tree constructions are possible, the one shown here fully matches the responsive chart the OP required/requested (for as far I understood...).
Special care has been taken to fit the chart on a '360x640px' smartphone (portrait) as well as on a "1920x1200px" desktop display (landscape, my own 24").
For now, this code is ONLY available from this Stackoverflow Question. A (more elaborate) codepen version is underway...
note
It might well be possible that you utterly dislike what I did with the code or simply have other requirements than I interpreted. In that case do not downvote the answer, but simply ignore it, as others may find it usefull nonetheless.
extra 'ERS linear equations'
The online tool I created on GeoGebra, ERS linear equations, will hugely simplify finding the proper responsiveness equations for your CSS calc() functions. The tool shows 4 predefined functions of the equations used in the code. Make sure you give it a go (no affiliate, personal work, free, fork it, use it, abuse it)...
The code in the snippet was tested to work on W10 with Chrome, Edge, Firefox and IE11 (+IE10 mode) and on Android 9+ with the default browser and Firefox. For lack of devices, no Apple results.
/******************************/
/* general global preferences */
/******************************/
html,body { box-sizing: border-box } /* [MANDATORY] all size calcs must include padding and border */
*::before,*::after, * { box-sizing: inherit } /* [MANDATORY], ditto, but it WILL inherit any changes */
/*
responsive fontsize:
p1(320,14) p2(1280,20) => 0.00625x + 12
Assumes 16px browser default fontsize and uses
REM to adapt to user modified font settings
In the remainder of this <style> sheet you will find
an explanation of the algebra used in this document.
*/
html { font-size: calc(0.625vmin + 0.75rem) }
body { width: 100%; height: 100%; margin: 0; cursor: default;
font-size: 1rem;
font-family: Roboto,Arial,Helvetica,sans-serif;
background-color: Gainsboro; color: black }
h1 { font-size: 2rem } /* Override of FF+ default nesting behaviour */
/* generic flexbox shortcuts */
[F] { display: flex }
[R] { flex-direction: row } /* horizontal: row of 1:N columns (FBL default) */
[C] { flex-direction: column } /* vertical: column of 1:N rows */
[W] { flex-wrap: wrap }
/* Prevents (inadverted) text selection by user (when double, double clicking) */
[no-select] { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none;
user-select: none; -moz-appearance : none; -webkit-appearance: none }
/* Show element outlines for debugging (use in <body> tag) */
[outlines="1"] * { outline: 1px dashed purple }
/* Color to show nesting level for debugging (use in <body> tag) */
[hover="1"] :not(section) :hover { background-color: rgba(255,0,0,.2) }
/*
KNOT LOGIC
'branch' - 1:N 'node',1:N 'node.step' and 1:N 'step'
'node' - 1:N 'node' and 1:N 'step'
'step' - 1 data-symbol
You can use flexbox shortcut attributes R (horizontal) and C (vertical) to
determine the nesting direction of 'branch'es and 'node's. (R) is optional
as horizontal is the default direction.
(Depending on orientation of the knots, all kinds of nestings might work,
but that will require trial and error, fiddling.)
SPECIFICATIONS
1) 'branch' has no specific rules, but acts as a container for 'node's
and to distinguish from 'node' and 'step'.
Add your own rules for specific 'branch' styling like fonts,colors,border,spacing.
2) 'node' and 'step' only use :before and :after to position and draw
connecting lines.
'node' horizontal line attachement
'step' vertical
'node.step' both
3) 'node.step' can be empty (no 'data-symbol'), in which case it will only
draw cross lines.
4) 'start' and 'stop' values are used to prevent drawing of
starting and ending lines.
5) Knot 'lft', 'ctr' and 'rgt' values define how sibling nodes are connected
'lft' - left hand node, only one
'ctr' - center nodes, can be more than one
'rgt' - right hand node, only one
My motivation for use of 'data-* attributes' instead of classes is they
are easy accessible as javascript variables:
someElement.dataset.chart
someElement.dataset.knot
someElement.dataset.symbol
*/
/***************/
/* Chart Setup */
/***************/
/* If you want the knots distributed as-is, remove 'align-items' */
[data-chart] { display: flex; align-items: center } /* [OPTIONAL], try! */
[data-knot] { display: flex; flex-grow: 1 } /* [MANDATORY] */
/* default alignments */
[data-knot] { justify-content: center }
[data-knot*="node"] { align-items: stretch }
[data-knot*="step"] { align-items: flex-start }
/* this code keeps the lines connect to the symbols */
[data-knot] { position: relative; z-index: 1 } /* new stacking context */
[data-knot]:before,
[data-knot]:after { position: absolute; z-index: -1; content: '' }
/* put some character in 'content' to keep track when debugging */
/* Horizontal lines ('node') setup */
[data-knot]:before { top : 1px } /* adjust -+1 for thickess of outlines */
[data-knot]:after { bottom: -1px }
[data-knot*="node"]:before,[data-knot*="node"]:after
{ height: 0px /* for IE11 */; width: 50% }
/* Vertical lines ('step') setup */
[data-knot*="step"]:before,[data-knot*="step"]:after
{ width: 0px /* for IE11 */; left: 50%; right: 50% }
/* positioning of the lines ('lft','ctr','rgt') */
[data-knot*="ctr"]:before,[data-knot*="ctr"]:after
{ width: 100%; left: 0 }
/* (EITHER) Handles document reading direction (dir="ltr" in <body>) */
[dir="ltr"] [data-knot*="lft"]:before, [dir="ltr"] [data-knot*="lft"]:after { left : 50% }
[dir="ltr"] [data-knot*="rgt"]:before, [dir="ltr"] [data-knot*="rgt"]:after { right: 50% }
[dir="rtl"] [data-knot*="lft"]:before, [dir="rtl"] [data-knot*="lft"]:after { right: 50% }
[dir="rtl"] [data-knot*="rgt"]:before, [dir="rtl"] [data-knot*="rgt"]:after { left : 50% }
/* (OR) For use without [dir]
[data-knot*="lft"]:before, [data-knot*="lft"]:after { left : 50% }
[data-knot*="rgt"]:before, [data-knot*="rgt"]:after { right: 50% }
*/
/* line coloring */
[data-knot*="node"]:before,[data-knot*="node.step"]:after,
[data-knot*="step"]:before,[data-knot*="step"]:after { outline: 1px solid #666 }
/* no line drawing cases */
[data-knot="step"]:after, /* notice the missing '*' */
[data-knot*="start"]:before ,[data-knot*="stop"]:after { outline: none }
/*
responsive sizes: T/B p1(320,6) p2(1280,24) and L/R p1(320,4) p2(1280,16)
modify these to meet specific requirements.
*/
[data-knot*="step"] { padding: 1.875vmin 1.25vmin }
[data-knot*="step"]:before { height : 1.875vmin } /* Same height as [data-step] T/B padding */
[data-knot*="step"]:after { height : calc(100% - 1.875vmin) } /* pct to from below (minus T/B padding) */
/****************/
/* Symbol Setup */
/****************/
/*
Chart 'data-symbol's, flexbox intended use
FBL (V) FBL (H) Any
-------- ------- -------
(S)ymbol -> (H)eader -> content
-> (C)ontent -> content
-> (F)ooter -> content
*/
[data-symbol],
[data-symbol]>* { display: flex } /* S,H,C,F are flexbox parent containers */
[data-symbol]>*>* { flex-grow: 1 } /* sets default to 'fill' for content of H,C,F */
[data-symbol] { flex-direction: column } /* a column of 1:N rows */
[data-symbol]>.header { align-items: center }
/* styling */
[data-symbol] { text-decoration: none; color: currentColor; background-color: transparent }
[data-symbol]>.header {
padding: .25rem .5rem; text-align: center; border-radius: 50%;
/* responsive sizes: p1(320,50) p2(1920,180) */
width : calc(8.125vmin + 24px);
height: calc(8.125vmin + 24px);
/*
responsive fontsize: p1(320,6) p2(1920,20)
Whether this works as expected depends on the minimum browser
fontsize set by the user (content may overflow .header when set >6px)
Tested defaults on W10:
Edge2020 overflows, while Chrome, Firefox and IE11 do not
*/
font-size: calc(.875vmin + 3.2px)
}
[clr="0"] { background-color: Gainsboro; color: black }
.header, /* .header here saves coding html */
[clr="1"] { background-color: #fefefe; color: #1e1e1e }
[clr="2"] { background-color: #1e1e1e; color: Yellow ; font-weight: bolder }
[clr="3"] { background-color: #ffcc01; color: #1e1e1e; font-weight: bolder }
/**************************************/
/* Google Material Component inspired */
/**************************************/
[icon] {
display: inline-flex;
justify-content: center; align-content: center; align-items: center;
/* responsive sizes: p1(320,14) p2(1280,32) */
width : calc(1.875vmin + 8px);
height : calc(1.875vmin + 8px);
line-height: calc(1.875vmin + 8px);
font-size : calc(1.875vmin + 8px);
/*
A bit overdone for just one icon, use inline SVG instead,
or create a small (subset) iconfont at https://icomoon.io
icon list: https://material.io/resources/icons/?style=baseline
*/
font-family: 'Material Icons';
font-weight: normal; font-style: normal; letter-spacing: normal;
text-transform: none; white-space: nowrap; word-wrap: normal;
opacity: 1; /* GMC uses <1 here and 1 on :hover */
-moz-font-feature-settings: 'liga';
font-feature-settings : 'liga';
-moz-osx-font-smoothing : grayscale;
}
/******************/
/* simple banding */
/******************/
[band] { display: flex; flex-flow: row wrap;
justify-content: center; align-content: center;
padding: calc(5vh + 48px) calc(19.5vw - 54.4px) }
/*
responsive padding
T/B: p1(320,64) p2(1920,144) => y = 0.5x + 48
L/R: p1(320, 8) p2(1920,320) => y = 0.195x - 54.4
This construction keeps content nicely center aligned within
given space.
*/
/* [OPTIONAL] */
#media screen and (max-width: 319px) { [band] { padding: 1.5rem 8px } }
#media screen and (min-width:1921px) { [band] { padding: 1.5rem 320px } }
/***********************/
/* Some extra eyecandy */
/***********************/
[data-symbol]>.header {
box-shadow: 0px 2px 1px -1px rgba(0,0,0,.20),
0px 1px 1px 0px rgba(0,0,0,.14),
0px 1px 3px 0px rgba(0,0,0,.12); /* GMC elevation 1dp */
}
[data-symbol]>.header:hover:not(:focus) { transform: scale(1.01) }
[data-symbol]>.header:active:not(:focus) { transform: scale(0.995);
box-shadow: 0px 3px 5px -1px rgba(0,0,0,.2),
0px 5px 8px 0px rgba(0,0,0,.14),
0px 1px 14px 0px rgba(0,0,0,.12); /* GMC elevation 5dp */
}
[data-symbol]>.header:hover {
box-shadow: 0px 3px 5px -1px rgba(0,0,0,.2),
0px 6px 10px 0px rgba(0,0,0,.14),
0px 1px 18px 0px rgba(0,0,0,.12); /* GMC elevation 6dp */
}
/*
ALGEBRA for responsive sizing
ALL responsive sizes in this document use the 'point-slope' variation
of the 'definition of a straight line: y=mx+b':
(https://www.mathsisfun.com/algebra/line-equation-point-slope.html)
y - y1 = y1 + m(x - x1) <=> y = y1 + m(x - x1)
For points:
p1 = (x1,y1) - size at minimum viewport size (x1 default 320px)
p2 = (x2,y2) - size at maximum viewport size (x2 default 1280px)
(using 320px and 1280px will create a full step each 160px)
where:
m = (y2 - y1) / (x2 - x1) ('Slope')
x = fixed value of 100vmin, 100vh or 100vw ('X-intercept')
b = y1 - (m * x1) ('Y-intercept')
X-axis = viewport size
Y-axis = element size
Substituted equation to use:
y = y1 + (y2 - y1) / (x2 - x1) * (x - x1)
NOTES
- Use VMIN for viewport width/height independed results (like fonts)
- Use VW/VH for viewport width/height dependend results (width,height,margin,padding)
- Do not use VMAX for x, it will yield results that are to large.
EXTRA
Helpfull hands-on graphical tool/demo I created on GeoGebra
'ERS linear equations' https://www.geogebra.org/m/gct3bvsp
(E)asy (R)esponsiveness (S)system
*/
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" crossorigin="anonymous">
<body dir="ltr" no-select hover="0" outlines="0">
<section band>
<div data-chart="OC" C>
<div data-knot="branch" C>
<div data-knot="node.step.start">
<div data-symbol>
<div class="header" clr="2"><div><i icon>account_balance</i><br>Group Board</div></div>
</div>
</div>
<div data-knot="node.step">
<div data-symbol>
<div class="header" clr="3"><div><i icon>account_balance</i><br>Board Committees</div></div>
</div>
</div>
</div>
<div data-knot="branch">
<div data-knot="node.lft">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Audit</div></div>
</div>
</div>
</div>
<div data-knot="node.ctr">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Remuneration and Human Resources</div></div>
</div>
</div>
</div>
<div data-knot="node.ctr">
<div data-knot="node.step"><!-- empty data-knot for vertical line --></div>
</div>
<div data-knot="node.ctr">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Social Ethics</div></div>
</div>
</div>
</div>
<div data-knot="node.rgt">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Nominations</div></div>
</div>
</div>
</div>
</div>
<div data-knot="branch">
<div data-knot="node.lft">
<div data-knot="step">
<div data-symbol>
<div class="header" clr="3"><div><i icon>account_balance</i><br>Compliance Committee</div></div>
</div>
</div>
</div>
<div data-knot="node.ctr">
<div data-knot="node.step"></div>
</div>
<div data-knot="node.rgt">
<div data-knot="step">
<div data-symbol>
<div class="header" clr="3"><div><i icon>account_balance</i><br>Executive Committees</div></div>
</div>
</div>
</div>
</div>
<div data-knot="branch">
<div data-knot="node.lft">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Group Searching</div></div>
</div>
</div>
</div>
<div data-knot="node.ctr">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Group Operation</div></div>
</div>
</div>
</div>
<div data-knot="node.ctr">
<div data-knot="node.step.stop">
<div data-symbol>
<div class="header"><div>Group Talent</div></div>
</div>
</div>
</div>
<div data-knot="node.ctr">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Group Treasure</div></div>
</div>
</div>
</div>
<div data-knot="node.rgt">
<div data-knot="step">
<div data-symbol>
<div class="header"><div>Group Transformation</div></div>
</div>
</div>
</div>
</div>
</div>
</section>
</body>

Remove margin: 0 .2em .5em; padding: 3.7em .5em; from .tree code, .tree span classes.
Also is you want the circle to accurate circles then remove margin and padding from the classes level1 & level2.
CodePen Link: https://codepen.io/manaskhandelwal1/pen/XWbpzMx
.tree,
.tree ul,
.tree li {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
.tree {
margin: 0 0 1em;
text-align: center;
}
.tree,
.tree ul {
display: table;
}
.tree ul {
width: 100%;
}
.tree li {
display: table-cell;
padding: .5em 0;
vertical-align: top;
}
.tree li:before {
outline: solid 1px #666;
content: "";
left: 0;
position: absolute;
right: 0;
top: 0;
}
.tree li:first-child:before {
left: 50%;
}
.tree li:last-child:before {
right: 50%;
}
.tree code,
.tree span {
display: inline-block;
position: relative;
height: 150px;
width: 150px;
border-radius: 50%;
background-color: #fefefe;
}
.lineh {
margin-top: -9px !important;
margin-bottom: 0px !important;
border: 0 !important;
border-top: 2px solid !important;
width: 159px;
}
.minus-space {
margin-top: 10px !important;
}
.tree span i {
font-size: 40px
}
.tree span.level1 {
background-color: #1e1e1e;
color: yellow;
}
.tree span.level2 {
background-color: #ffcc01;
}
.tree span.linev {
background-color: #666 !important;
width: 2px !important;
border-radius: 0% !important;
padding: 0px !important;
margin: 0px !important;
}
.tree ul:before,
.tree code:before,
.tree span:before {
outline: solid 1px #666;
content: "";
height: .5em;
left: 50%;
position: absolute;
}
.tree ul:before {
top: -.5em;
}
.tree code:before,
.tree span:before {
top: -.55em;
}
.tree>li {
margin-top: 0;
}
.tree>li:before,
.tree>li:after,
.tree>li>code:before,
.tree>li>span:before {
outline: none;
}
<div class="container-fluid">
<ul class="tree">
<li><span class="level1"><i class="mdi mdi-bank"></i><br><b>Group board</b></span>
<ul>
<li><span class="level2"><i class="mdi mdi-bank"></i><br><b>Board committees</b></span>
<ul>
<li> <span>Audit</span>
</li>
<li> <span>Remuneration and human ressources</span>
</li>
<li> <span class="linev"></span>
<ul>
<li> <span class="level2"><i class="mdi mdi-bank"></i><br><b>Compliance
committees</b></span>
</li>
<li> <span class="linev"></span>
<ul>
<li><span>Group searching</span></li>
<li><span>Group operation</span></li>
<li><span>Strategic talent</span></li>
<li><span>Group treasure</span></li>
<li><span>Group transformation</span></li>
</ul>
</li>
<li> <span class="level2"><i class="mdi mdi-bank"></i><br><b>Executive <br> committees</b></span>
</li>
</ul>
</li>
<li> <span>Social ethics</span>
</li>
<li> <span>Nominations</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

Related

Problem with sizing CSS, and positioning elements, also how to use aspect ratio, for all resolutions

I would appreciate any suggestions/support on couple issues I'm facing. Thanks in advance for your suggestions.
I've been trying to make this game browsing section for my website in a grid in CSS, but I cant seem to find out how to fix this error for example my code result would make this:
It would work for one single current amount of characters like how I did it there, but when I change text in HTML for a new one of those it does something like this:
The icon for the image keeps on changing and moving, I realized this happens when I change the content inside the game category.
Also I want to know how to keep the same basic shape I created, I want it to stay the same on all resolutions, but cant find a way.
This should make a div that holds game image, a play button, a title, and category of game
.Games {
display: grid;
grid-template-columns: repeat(4, 25.7%);
grid-template-rows: repeat:(auto, auto);
grid-gap: auto;
margin: auto;
max-width: 1200px;
}
#GameFrame {
background: #0f101e;
border-radius: 25px;
width: 99%;
max-height: 80%;
display: inline-block;
transition: all 0.3s ease-in-out;
}
#GameImage {
width: 95%;
height: 150px;
border-radius: 25px;
margin-left: 2.5%;
margin-top: 2.5%;
transition: all 0.3s ease-in-out;
}
#GameText {
color: white;
font-size: 100%;
font-family: "Gotham", sans-serif;
text-shadow: 5px 5px 10px black;
margin-left: 60px;
position: relative;
z-index: 1;
}
button {
background-image: linear-gradient(#e23c03, #fa4e12);
border: none;
border-radius: 10px;
height: 18.5%;
width: 13%;
transition: all 0.3s ease-in-out;
position: relative;
top: -86px;
margin-left: 84%;
}
#play {
color: white;
font-size: 100%;
}
button:hover {
transform: scale(1.1);
filter: drop-shadow(4px 2px 4px black);
}
#category {
background: #27211d;
border-radius: 10px;
font-size: 70%;
font-family: "Gotham", sans-serif;
color: #ffc400;
position: relative;
z-index: 3;
padding: 1.2%;
padding-left: 1.5%;
padding-right: 1.5%;
display: inline-block;
margin-left: 20%;
top: -37px;
}
#GameIcon {
width: 45px;
height 45px;
border-radius: 100%;
filter: drop-shadow(4px 2px 4px #08080f);
position: relative;
z-index: 2;
top: -30px;
margin-left: -125px;
}
<link href="https://fonts.cdnfonts.com/css/gotham" rel="stylesheet">
<script src="https://kit.fontawesome.com/faea65eadf.js" crossorigin="anonymous"></script>
<div class="Games">
<div id="GameFrame">
<img src="https://img.redbull.com/images/c_fill,w_1200,h_600,g_auto,f_auto,q_auto/redbullcom/2020/4/28/bjoyslzjb3uxqyg82uz2/minecraft" id="GameImage"></img>
<!--Game Image Above-->
<h1 id="GameText">Minecraft</h1>
<!--Game Name Above-->
<h1 id="category">Adventure</h1>
<!--Game Category Above-->
<img src="https://mojang-studios.gallerycdn.vsassets.io/extensions/mojang-studios/minecraft-debugger/0.6.1/1672951467139/Microsoft.VisualStudio.Services.Icons.Default" id="GameIcon"></img>
<!--Game Circle Image Above-->
<button>
<i id="play" class="fa-solid fa-play"></i>
</button>
</div>
<div id="GameFrame">
<img src="https://pikuma.com/images/blog/game-console-history-for-programmers/thumbnail-990x540.jpg" id="GameImage"></img>
<!--Game Image Above-->
<h1 id="GameText">Example</h1>
<!--Game Name Above-->
<h1 id="category">Casual</h1>
<!--Game Category Above-->
<img src="https://i.pinimg.com/564x/47/aa/1f/47aa1fe9ca114cce1558e1e46a59bdf2.jpg" id="GameIcon"></img>
<!--Game Circle Image Above-->
<button>
<i id="play" class="fa-solid fa-play"></i>
</button>
</div>
</div>
Also I really wanted the button to stay a square and once zoomed in a lot it kinda is a rectangle.
Here it is when its zoomed in a lot for a different res:
I tried alot to go through and read a bunch of articles and could not find out why, I also editted alot in each of sizing values and it did not work either. Someone please help me, thanks.
Also, link to a codepen: https://codepen.io/FreeGames/pen/PoBpamV
There's a few ways to approach this, I'll show a couple of options below and we'll take it step-by-step (as far as possible, within the limits of a Stack Overflow answer).
The first step is to put your HTML together in some form of meaningful, semantic way. To that end I've come up with the following HTML:
<!-- you want to show a list of games in your "game browsing section,"
to that end I'm using an unordered list (you may prefer to use an
<ol> if you'd consider it to be ordered): -->
<ul class="library">
<!-- the <li> elements each wrap one game from the library: -->
<li>
<!-- you want to show an <img> with associated text; the <figure>
element - along with its <figcaption> - seems to fit this
use-case: -->
<figure>
<!-- the <img> to show the game image asset: -->
<img src="https://i.stack.imgur.com/ZeeKUm.jpg" alt="" class="gameTitleScene">
<figcaption>
<!-- the icon/smaller game-image: -->
<img src="https://i.stack.imgur.com/4GZ51s.png" alt="" class="gameIcon">
<!-- game title, I've used an <h3> as there should be only one <h1> in
a page, and the <h2> elements seem a likely choice for section titles;
obviously adjust to whichever element you prefer: -->
<h3 class="gameTitle">Minecraft</h3>
<!-- I wasn't sure if there would only be one, or multiple, categories; so I
wrapped the categories (as <a> elements to allow for easier browsing to
all games of a given category), within <li> elements again within an
unordered-list: -->
<ul class="categories">
<li>Adventure</li>
</ul>
<!-- the 'play' button, with a type of "button" so that if you choose to nest
this within a <form> it won't submit that <form> by default: -->
<button type="button" class="play"></button>
</figcaption>
</figure>
</li>
</ul>
To style the above HTML as you show in the question:
https://i.stack.imgur.com/nDY75.png
We can use the following CSS:
/* a couple of custom CSS properties to allow for consistent theming,
allowing for theme changes in one place that updates all uses at
once: */
:root {
--categoryColor: #f90;
--spacing: 1em;
}
/* a simple reset, to cause the browser to include paddings and border-
sizes within the declared size of the element: */
*,
::before,
::after {
box-sizing: border-box;
/* removing browser default margin and padding: */
margin: 0;
padding: 0;
}
body {
/* setting the font defaults for the page; which will over-write
browser default styles (though user-agent styles will likely
take precedence over these styles if they're set; that's a
feature and not a bug): */
font-family: "Roboto", "Poppins", system-ui;
font-size: 16px;
font-weight: 500;
}
/* setting some basic styles for users that use keyboard navigation, to
show an obvious outline around focused elements: */
:focus-visible {
outline: 0.25em solid currentColor;
outline-offset: 0.25em;
}
/* removing the default list-markers from the listed elements; this
also removes the accessibility feature in which screen-readers
announce the contents as a list; so while we're removing the
list-markers here (and thereby removing that functionality from
the associated elements), we have used an aria-role="list" attribute
on the <ul>, and aria-role="listitem" on the child <li> elements in
order to preserve/restore that functionality; since we only wish to
hide the content from the visual theme: */
ul,
li {
list-style-type: none;
}
main {
/* setting up a grid-display on the <main> element that wraps all
content (in this demo): */
display: grid;
/* making use of the var() function, and the --spacing custom
property to apply a consistent gap: */
gap: var(--spacing);
/* using CSS logical properties to size the element on its inline
axis (the axis on which inline content flows, such as words
in a sentence, equivalent to 'width' in the English language).
We're using the clamp() function to determine the size of the
eleemnt; with a preferred size of 80% of its own parent
containing element's inline size, with a minimum size of 20rem
and a maximum size of 1200px: */
inline-size: clamp(20rem, 80%, 1200px);
/* setting margins on the block axis; this is perpendicular to the
inline axis and equivalent to 'height' in the English language: */
margin-block: var(--spacing);
/* setting inline margins of auto, in order that the content will
be centered within its parent (if enough space exists): */
margin-inline: auto;
}
.library {
/* I left the border in place in order to allow the sizing to be
easily visualised, but it's not necessary for the demo: */
border: 1px solid currentColor;
/* I chose to use display: flex here: */
display: flex;
/* and used the flex-flow shorthand to set:
flex-direction: row;
flex-wrap: wrap;
*/
flex-flow: row wrap;
/* applying the gap between items (again): */
gap: var(--spacing);
/* spreading the elements out across the inline-axis; adjust to
your preferences though: */
justify-content: space-between;
/* assigning a padding, to move the child element(s) away from
the <li> element's boundaries:: */
padding: var(--spacing);
}
.library > li {
background-color: hsl(0deg 0% 0% / 1);
/* using the calc() function to set a border-radius on the
element, based on the theme's --spacing property: */
border-radius: calc(var(--spacing) / 2);
border: 1px solid currentColor;
padding: var(--spacing);
}
/* selecting the descendant elements of the <figure> element that
match the supplied CSS selectors, so here we select all
<img> and <button> elements that are within the <figure> ancestor: */
figure :is(img, button) {
/* setting the border-radius as above, based on the --spacing custom
property: */
border-radius: calc(var(--spacing) / 2);
}
figcaption {
/* setting the color to white using CSS colors 4 syntax and the
hsl() function: */
color: hsl(0deg 100% 100% / 1);
/* using display: grid: */
display: grid;
/* setting the gap between the grid-columns: */
grid-column-gap: calc(var(--spacing)/2);
/* defining 3 columns, the first and last taking a size of 2rem,
with the central taking 1 fraction of the remaining space: */
grid-template-columns: 2rem 1fr 2rem;
/* using CSS logical properties to place a margin (again using the
custom property, and var() function) to the start-edge of the
element's block-axis (in English, equivalent to margin-top): */
margin-block-start: var(--spacing);
}
/* using the :is() pseudo-class to select elements matching the supplied
CSS selectors (.gameTitle, .categories) within a figcaption ancestor: */
figcaption :is(.gameTitle, .categories) {
/* positioning those elements in grid-column 2: */
grid-column: 2;
}
figcaption :is(.gameIcon, .play) {
/* putting these elements in grid-row 1: */
grid-row: 1;
/* with a maximum inline size ('width,' in the English language) of
100%, so the element can't/won't extend beyond the assigned space: */
max-inline-size: 100%;
/* using object-fit to scale the element(s) in a way that they'll fill
their available space in a manner which preserves their aspect-ratio: */
object-fit: cover;
}
.gameTitle {
font-size: 1.5em;
}
.gameIcon {
/* we could use border-radius: 50%, but clip-path() is well-supported and
actually clips the element as described, to a circle - centered by
default - of radius 50%: */
clip-path: circle(50%);
/* and positioning it within the grid, into grid-column 1: */
grid-column: 1;
}
.play {
background-color: hsl(0deg 95% 50% / 1);
border: 1px solid transparent;
/* inherits from its ancestor: */
color: inherit;
grid-column: 3;
/* I'm using position: absolute on the (following) pseudo-element, so
we're specifying a non-static position on this element, so that it
acts as the containing block: */
position: relative;
}
.play::before {
/* the Unicode right-pointing triangle: */
content: "\25B6";
font-size: 1rem;
/* to allow for the element to be positioned absolutely, with reference
to its containing block (the first element with 'position' set to
something other than 'static' (the default): */
position: absolute;
/* positioning the element's top-left corner with reference to its
ancestor's top-left corner: */
top: 50%;
left: 50%;
/* translating the element -50% of its own size on both the horizontal
and vertical axes, in order to have it centered: */
translate: -50% -50%;
}
.categories {
/* setting the color of text content within the element: */
color: var(--categoryColor);
}
.categories a {
/* setting <a> elements to inherit their color: */
color: inherit;
text-decoration: none;
}
.categories a:is(:hover, :active, :focus) {
text-decoration: underline;
text-underline-offset: 0.3em;
}
<!-- importing fonts from Google Fonts (this is optional, obviously, and only
included because so many people like to use them) -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<main>
<!-- you want to show a list of games in your "game browsing section,"
to that end I'm using an unordered list (you may prefer to use an
<ol> if you'd consider it to be ordered): -->
<ul class="library">
<!-- the <li> elements each wrap one game from the library: -->
<li>
<!-- you want to show an <img> with associated text; the <figure>
element - along with its <figcaption> - seems to fit this
use-case: -->
<figure>
<!-- the <img> to show the game image asset: -->
<img src="https://i.stack.imgur.com/ZeeKUm.jpg" alt="" class="gameTitleScene">
<figcaption>
<!-- the icon/smaller game-image: -->
<img src="https://i.stack.imgur.com/4GZ51s.png" alt="" class="gameIcon">
<!-- game title, I've used an <h3> as there should be only one <h1> in
a page, and the <h2> elements seem a likely choice for section titles;
obviously adjust to whichever element you prefer: -->
<h3 class="gameTitle">Minecraft</h3>
<!-- I wasn't sure if there would only be one, or multiple, categories; so I
wrapped the categories (as <a> elements to allow for easier browsing to
all games of a given category), within <li> elements again within an
unordered-list: -->
<ul class="categories">
<li>Adventure</li>
</ul>
<!-- the 'play' button, with a type of "button" so that if you choose to nest
this within a <form> it won't submit that <form> by default: -->
<button type="button" class="play"></button>
</figcaption>
</figure>
</li>
</ul>
</main>
If we take the above code, though, and add a second <li>/card, then we'll see that the second element – because of the different <img> size – has a different size which causes the 'cards' to be different sizes, and for the grid-rows to be misaligned:
:root {
--categoryColor: #f90;
--spacing: 1em;
}
*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Roboto", "Poppins", system-ui;
font-size: 16px;
font-weight: 500;
}
:focus-visible {
outline: 0.25em solid currentColor;
outline-offset: 0.25em;
}
ul,
li {
list-style-type: none;
}
main {
display: grid;
gap: var(--spacing);
inline-size: clamp(20rem, 80%, 1200px);
margin-block: var(--spacing);
margin-inline: auto;
}
.library {
border: 1px solid currentColor;
display: flex;
flex-flow: row wrap;
gap: var(--spacing);
justify-content: space-between;
padding: var(--spacing);
}
.library>li {
background-color: hsl(0deg 0% 0% / 1);
border-radius: calc(var(--spacing) / 2);
border: 1px solid currentColor;
padding: var(--spacing);
}
figure :is(img, button) {
border-radius: calc(var(--spacing) / 2);
}
figcaption {
color: hsl(0deg 100% 100% / 1);
display: grid;
grid-column-gap: calc(var(--spacing)/2);
grid-template-columns: 2rem 1fr 2rem;
margin-block-start: var(--spacing);
}
figcaption :is(.gameTitle, .categories) {
grid-column: 2;
}
figcaption :is(.gameIcon, .play) {
grid-row: 1;
max-inline-size: 100%;
object-fit: cover;
}
.gameTitle {
font-size: 1.5em;
}
.gameIcon {
clip-path: circle(50%);
grid-column: 1;
}
.play {
background-color: hsl(0deg 95% 50% / 1);
border: 1px solid transparent;
color: inherit;
grid-column: 3;
position: relative;
}
.play::before {
content: "\25B6";
font-size: 1rem;
position: absolute;
top: 50%;
left: 50%;
translate: -50% -50%;
}
.categories {
color: var(--categoryColor);
}
.categories a {
color: inherit;
text-decoration: none;
}
.categories a:is(:hover, :active, :focus) {
text-decoration: underline;
text-underline-offset: 0.3em;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<main>
<ul class="library">
<li>
<figure>
<img src="https://i.stack.imgur.com/ZeeKUm.jpg" alt="" class="gameTitleScene">
<figcaption>
<img src="https://i.stack.imgur.com/4GZ51s.png" alt="" class="gameIcon">
<h3 class="gameTitle">Minecraft</h3>
<ul class="categories">
<li>Adventure</li>
</ul>
<button type="button" class="play"></button>
</figcaption>
</figure>
</li>
<li>
<figure>
<img src="https://i.stack.imgur.com/Ougoom.jpg" alt="" class="gameTitleScene">
<figcaption>
<img src="https://i.stack.imgur.com/w5XDp.jpg" alt="" class="gameIcon">
<h3 class="gameTitle">Example</h3>
<ul class="categories">
<li>Casual</li>
</ul>
<button type="button" class="play"></button>
</figcaption>
</figure>
</li>
</ul>
</main>
This can be fixed – though I wish I could think of a better way – with:
.gameTitleScene {
/* setting a maximum block-size of 160px for the element: */
max-block-size: 160px;
}
:root {
--categoryColor: #f90;
--spacing: 1em;
}
*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Roboto", "Poppins", system-ui;
font-size: 16px;
font-weight: 500;
}
:focus-visible {
outline: 0.25em solid currentColor;
outline-offset: 0.25em;
}
ul,
li {
list-style-type: none;
}
main {
/ display: grid;
gap: var(--spacing);
inline-size: clamp(20rem, 80%, 1200px);
margin-block: var(--spacing);
margin-inline: auto;
}
.library {
border: 1px solid currentColor;
display: flex;
flex-flow: row wrap;
gap: var(--spacing);
justify-content: space-between;
padding: var(--spacing);
}
.library>li {
background-color: hsl(0deg 0% 0% / 1);
border-radius: calc(var(--spacing) / 2);
border: 1px solid currentColor;
padding: var(--spacing);
}
figure :is(img, button) {
border-radius: calc(var(--spacing) / 2);
}
figcaption {
color: hsl(0deg 100% 100% / 1);
display: grid;
grid-column-gap: calc(var(--spacing)/2);
grid-template-columns: 2rem 1fr 2rem;
margin-block-start: var(--spacing);
}
figcaption :is(.gameTitle, .categories) {
grid-column: 2;
}
figcaption :is(.gameIcon, .play) {
grid-row: 1;
max-inline-size: 100%;
object-fit: cover;
}
.gameTitleScene {
max-block-size: 160px;
}
.gameTitle {
font-size: 1.5em;
}
.gameIcon {
clip-path: circle(50%);
grid-column: 1;
}
.play {
background-color: hsl(0deg 95% 50% / 1);
border: 1px solid transparent;
color: inherit;
grid-column: 3;
position: relative;
}
.play::before {
content: "\25B6";
font-size: 1rem;
position: absolute;
top: 50%;
left: 50%;
translate: -50% -50%;
}
.categories {
color: var(--categoryColor);
}
.categories a {
color: inherit;
text-decoration: none;
}
.categories a:is(:hover, :active, :focus) {
text-decoration: underline;
text-underline-offset: 0.3em;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<main>
<ul class="library">
<li>
<figure>
<img src="https://i.stack.imgur.com/ZeeKUm.jpg" alt="" class="gameTitleScene">
<figcaption>
<img src="https://i.stack.imgur.com/4GZ51s.png" alt="" class="gameIcon">
<h3 class="gameTitle">Minecraft</h3>
<ul class="categories">
<li>Adventure</li>
</ul>
<button type="button" class="play"></button>
</figcaption>
</figure>
</li>
<li>
<figure>
<img src="https://i.stack.imgur.com/Ougoom.jpg" alt="" class="gameTitleScene">
<figcaption>
<img src="https://i.stack.imgur.com/w5XDp.jpg" alt="" class="gameIcon">
<h3 class="gameTitle">Example</h3>
<ul class="categories">
<li>Casual</li>
</ul>
<button type="button" class="play"></button>
</figcaption>
</figure>
</li>
</ul>
</main>
CSS subgrid might become an option – once more browsers support it (currently only Firefox and, I believe, Safari has implemented it) – but I'm already running out of space in this answer unfortunately.

Why line-height in Firefox and Chrome is different?

I created multi-line-padded text based on Matthew Pennell's solution (codepen by CSS Tricks). In Chrome all looks fine, but in Firefox height of span elements bigger than height of their ancestor. If I adjust vertical padding for Firefox, in Chrome will be same problem, and vice versa.
Why it happens? What the real technical reasons of this problem?
HTML Code:
<div class="padded-multiline">
<h1>
<strong>How do I add padding to subsequent lines of an inline text element?</strong>
</h1>
</div>
CSS Code:
:root {
font-family: Arial, sans-serif;
font-size: 20px;
}
.padded-multiline {
line-height: 1.3;
padding: 2px 0;
border-left: 20px solid #c0c;
width: 400px;
margin: 20px auto;
}
.padded-multiline h1 {
background-color: #c0c;
padding: 4px 0;
color: #fff;
display: inline;
margin: 0;
}
.padded-multiline h1 strong {
position: relative;
left: -10px;
}
Setting a line-height: 1; on strong will fix the problem also read my comment.
Chrome and Firefox seems to use different text layout system.
In Chrome it will floor the line-height attribute and Firefox seems to use the correct one.
To achieve the same effect for title, just use only the outline.
H1 does not need strong.
.padded-multiline {
line-height: 1.3;
padding: 2px 0;
width: 400px;
margin: 20px auto;
}
.padded-multiline h1 {
background-color: #c0c;
padding:1px;
color: #fff;
display: inline;
outline: 10px solid #c0c;
margin: 0;
font-size:16px;
}
<div class="padded-multiline">
<h1>How do I add padding to subsequent lines of an inline text element?</h1>
</div>
Here is codepen: http://codepen.io/anon/pen/vgRvjM
If you need exactly visual (that means less purple space from top and bottom, you can use for example border from after and before):
.padded-multiline:before{
content:'';
display:block;
border:5px solid #fff;
position:relative;
left:-10px;
top:-3px;
}
.padded-multiline:after{
content:'';
display:block;
border:5px solid #fff;
position:relative;
left:-10px;
bottom:-3px;
}
Codepen for this solution: http://codepen.io/anon/pen/QdmzxK
Unfortunately, there isn't a full and clean crossbrowser workaround. Because different UAs render text different, height of each textline may be taller a bit (or vice verca). So, I create a solution based on SCSS calculations of required box' sizes, and hide artefacts via overflow property.
Here is my solution, if you meet the same problem: http://codepen.io/ifiri/pen/ygEeeL
HTML:
<p class="multiline-text">
<span class="multiline-text__wrapper multiline-text__wrapper--outer">
<span class="multiline-text__wrapper multiline-text__wrapper--left">
<span class="multiline-text__wrapper multiline-text__wrapper--right">Multiline Padded text, which looks great on all browsers. No artefacts, no hacks, all clear and flexy, all alignment support. Change SCSS variables for see how it works.</span>
</span>
</span>
</p>
SCSS:
/*
Variables
*/
$base-line-height: 1.75;
$base-font-size: 1.25em;
$multiline-padding-base: ($base-line-height / 2) * 1em;
$multiline-padding-horizontal: $multiline-padding-base;
$multiline-padding-vertical: $multiline-padding-base - (1em / 2);
$multiline-bg-color: #a5555a;
$multiline-font-color: #fff;
/*
= Snippet Styles
This code is required
*/
.multiline-text {
color: $multiline-font-color;
padding: 0px $multiline-padding-horizontal;
// hide line-height artefacts
overflow: hidden;
position: relative;
}
.multiline-text__wrapper {
background-color: $multiline-bg-color;
padding: $multiline-padding-vertical 0px;
}
.multiline-text__wrapper--outer {
// Inner padding between text lines
line-height: $base-line-height;
}
.multiline-text__wrapper--left {
position: relative;
left: -($multiline-padding-horizontal);
}
.multiline-text__wrapper--right {
position: relative;
right: -($multiline-padding-horizontal / 2);
}

Responsive box with border lines

I am trying to make this exact box with borders lines. you can see after H2 there is new border line and then a paragraph. Please tell me how do I make this? as when I do it with border-bottom:1px solid it just makes a lines but doesn't touch the edges of the main border. here I am attaching the image so you can better understand this here you can see image
my code
<div class="col-sm-8 col-sm-offset-2" id="house">
<h3 class="text">Our house packages include:</h3>
<ul class="lead text" id="list">
<li>Standard site costs (based on 500mm fall to site & ‘M’ Class slab)</li>
<li>Rainwater Tank or connection to recycled water where available.</li>
<li>Concrete driveway (up to 55sqm)</li>
<li>Tiled Front Porch</li>
<li> Internal Floor Coverings</li>
<li> 5+ star gas instantaneous HWS</li>
<li>Wall & Ceiling insulation</li>
<li>‘Classic’ range of inclusions</li>
</ul>
<img src="images/landing.jpg" alt="landing Image">
<p class="note">NB. Please note that all packages are subject to developer and/or council and statutory authorities’ approvals.</p>
</div>
</div>
CSS
#house {
border: 1px solid black;
background:white;
}
#house h3 {
border-bottom:1px solid;
font-size:28px;
font-weight:bold;
margin:10px;
}
#list {
font-size:15px;
margin:15px;
padding:15px;
position:relative;
right:20px;
text-align:left;
}
#house img {
width:40%;
position:relative;
left:500px;
bottom:260px;
}
please tell me how do I make border lines after heading and after list. please take a look into image. It should be responsive.
thank you all
I think your code is missing one div tag on the top, so I'm not able to debug. :/
But this is how I'd solve it if I had to do the same thing:
<style>
html {
background: #EEE;
width: 100%;
height: 100%;
border: 0;
text-align: center;
padding: 40px;
box-sizing: border-box;
color: #AAA;
font-family: calibri;
}
.box{
background: #FFF;
border: 2px solid #DDD;
width: 80%; /*SPECIFY WIDTH HERE*/
display: inline-block;
}
.heading {
border-bottom: 2px solid #DDD;
width: 100%;
padding: 20px;
text-size: 30px;
font-size: 30px;
box-sizing: border-box;
display: inline-block;
}
.content {
border-bottom: 2px solid #DDD;
width: 100%;
padding: 20px;
box-sizing: border-box;
display: inline-block;
}
.footer {
width: 100%;
padding: 20px;
box-sizing: border-box;
display: inline-block;
}
.myList {
display: inline-block;
text-align: left;
padding: 10px;
}
li {
margin: 10px 0;
}
.myImg {
display: inline-block;
padding: 10px;
}
.houseImg {
width: 300px;
}
</style>
<div class='box'>
<div class='heading'>
Our house packages include:
</div>
<div class='content'>
<div class='myList'>
<ul class="lead text" id="list">
<li>Standard site costs (based on 500mm fall to site & 'M' Class slab)</li>
<li>Rainwater Tank or connection to recycled water where available.</li>
<li>Concrete driveway (up to 55sqm)</li>
<li>Tiled Front Porch</li>
<li> Internal Floor Coverings</li>
<li> 5+ star gas instantaneous HWS</li>
<li>Wall & Ceiling insulation</li>
<li>'Classic' range of inclusions</li>
</ul>
</div>
<div class='myImg'>
<img src='http://www.simplyeleganthomedesigns.com/hudson%20cottage%20FL.jpg' class='houseImg'>
</div>
</div>
<div class='footer'>
Some Footer text here
</div>
</div>
The reason h3 is not working the way you want is because you assigned it a margin: 10px; This is going to push the h3 border 10px away from its parent on all sides. If you don't assign it a margin, border-bottom will work fine.
It may be good practice for you to add borders to all elements so you can see how each css rule affects an elements box.
Refer to box model for further information
W3C Box Model
MDN Box Model
1- the border is inside the margin that's img why there is spaces .
try use the padding for h3
padding: 20px;
I fix the list for you as well .
check
jsfiddle

Weird spacing in my HTML that only appears in Chrome and not in IE or Komodo Edit's Preview

I wrote this in jsfiddle. https://jsfiddle.net/s2cq61ko/
Below is the HTML.
<div id="wrapper">
<h2>I am a generalist</h2>
<div id="Boxy">
<div id="GeneralistHeader">Stratgey & Design</div>
<div id="General_List">
<ul>
<li class="Big">systems theory</li>
<li class="Medium">branding</li>
<li class="Small">ethnography</li>
<li class="Small">statistics</li>
<li class="Big">iOS development</li>
<li class="Medium">user experience</li>
<li class="Small">web development</li>
<li class="Small">infographics</li>
</ul>
</div>
</div>
<h2>Here are past projects</h2>
<p>that will let you see my thought process.</p>
</div>
Then this is the CSS...
#wrapper {
max-width: 940px;
margin: 0 auto;
padding: 0 5%;
text-align: center;
}
a {
text-decoration: none
}
#GeneralistHeader {
font-size:2em;
font-weight: 700;
background:#19334c;
color:white;
display:inline-block;
padding: 2px 10px;
margin: -20px 0 0 0;
}
#Boxy {
border: solid;
display:inline-block;
border-width: 1px;
margin-top: 35px;
width:500px
}
#General_List ul {
list-style-type: none;
/*number of columns*/
-webkit-column-count: 2;
/* Chrome, Safari, Opera */
-moz-column-count: 2;
/* Firefox */
column-count: 2;
margin: 10px 0 0 0;
padding: 0;
font-family:'Raleway', serif;
font-weight: 400;
}
Notice the massive spacing after the box. It doesn't appear in IE or Komodo Edit's Preview. But when I open it on Chrome, it shows up like that...
I'm sure it's the CSS, but I could not figure it out.
The easiest solution is to change #Boxy to this:
#Boxy {
border: solid;
display: block; /* from inline-block to block */
border-width: 1px;
margin-top: 35px;
margin-left: auto; /* added this line */
margin-right: auto; /* added this line */
width: 500px;
}
There are a few things going on here. One is that using inline-block can produce odd spacing. If you adjust to using display block and then apply a margin-left auto and margin-right auto you will still center your box. The second thing I noticed is that you have applied a margin top of 1.75em to h2's. If you change this declaration to a class and only target the h2 that you intend to have the margin adjust then that gap goes away.
Look at this link
enter code here
You should make the Boxy on display and use margin: 0 auto; for positioning your box.

Building overlapping, oddly-rotated sprites

My current project involves setting up a bunch of sidebar links, such that the finished design looks like this:
The envelopes are supposed to move and overlap (i.e., change z-index), depending upon which icon/text is currently has :hover state.
I thought each would be a separate PNG file, but I've been given a sprite that looks like this:
Any suggestions how I could achieve this? Normally I'd just change the background position of the list elements each piece of text is in, but I don't think this is possible given the overlapping nature of these. Does he just need to export it differently?
Many thanks...
To me it looks like that sprite would work perfectly. The left most image is for when book is hovered, second image for twitter, third for facebook, forth for email. I'm guessing the last one is just the default state. Its tricky to make this work with pure css and :hover (but possible!), however, it would be extremely easy with javascript.
For the pure css solution, the div with the sprite would have to be the child of all the text elements, so you could change the background based on :hover on the parent (the text). If this isn't clear, I can make you some example code.
Edit:
Its not perfect, but its a proof of concept.
JsFiddle: http://jsfiddle.net/jp6fy/
CSS:
#side{
position:relitive;
height:341px;
width:250px;
}
#link1{
top:0;
}
.link{
position:absolute;
left:0;
top:85px;
height:85px;
padding-left:160px;
width:90px;
}
#image{
position:absolute;
top:-255px;
left:0;
z-index:-1;
background:url(http://i.stack.imgur.com/I2Y4k.png) -720px 0;
height:341px;
width:150px;
}
#link1:hover #image{
background-position:-540px 0;
}
#link2:hover #image{
background-position:-360px 0;
}
#link3:hover #image{
background-position:-180px 0;
}
#link4:hover #image{
background-position:-0px 0;
}
HTML:
<div id='side'>
<div class='link' id='link1'>
email
<div class='link' id='link2'>
facebook
<div class='link' id='link3'>
twitter
<div class='link' id='link4'>
book
<div id='image'></div>
</div>
</div>
</div>
</div>
</div>
It is possible. (But ugly.)
As a :hover selector can only affect elements inside (or directly adjacent) to the triggering element, the solution is to nest the trigger elements: (jsFiddle)
<style>
div {
width: 100px;
height: 100px;
position: absolute;
left: 100px;
}
#image { background: black; }
#trigger1, #trigger1:hover #image { background: red; }
#trigger2, #trigger2:hover #image { background: green; }
#trigger3, #trigger3:hover #image { background: blue; }
</style>
<div id="trigger1">
<div id="trigger2">
<div id="trigger3">
<div id="image"></div>
</div>
</div>
</div>
But preferably, you'd get the envelope sprites exported separately (you can of course still use CSS sprites). That should give you simpler HTML and CSS, a smaller image, and you'll avoid having to muck around with nested absolutely positioned elements, each having its own coordinate system.
I tried an approach which keeps the markup fairly simple, with only one extra non-semantic div per item:
<ul>
<li id="email">
<div class="background"></div>
<em>Email</em> chris
</li>
<li id="facebook">
<div class="background"></div>
<em>Facebook</em> follow us
</li>
<li id="twitter">
<div class="background"></div>
<em>Twitter</em> your life away
</li>
<li id="book">
<div class="background">
</div><em>Book</em> a project
</li>
</ul>
I positioned all the different copies of the background div at the same place, then varied the background position based on the hover states:
/* First, just style the document and the list text in general.
skip on for the important bit */
body {
background-color: black;
color: white;
}
ul {
width: 350px;
margin-top: 40px;
position: relative;
}
li {
margin-right: 40px;
font-family: "Century Gothic", Helvetica, sans-serif;
text-align: right;
margin-bottom: 0px;
padding: 15px 4px 25px 0;
}
li em {
text-transform: uppercase;
display: block;
}
li:hover {
color: red;
}
/* From here down is the important bit */
/* Set up the sprite in all the .background divs */
div.background {
background-image: url(http://i.stack.imgur.com/I2Y4k.png);
position: absolute;
top: 0;
left: 0;
height: 341px;
width: 160px;
}
/* By default, turn off the background in all the divs */
div.background {
display: none;
}
/* Just picking an arbitrary item to show the default, non-hover background */
#email div.background {
display: block;
background-position-x: -737px;
}
/* If we're hovering over the list as a whole, disable the default background,
so it doesn't show up underneath the background we want to display */
ul:hover #email div.background {
display: none;
}
/* For the email item, which shows our arbitrary default background, override
to the email background on hover with more specificity than the default rule */
ul:hover #email:hover div.background {
display: block;
background-position-x: 0px;
}
/* For all other items, override to their background on hover */
#facebook:hover div.background {
display: block;
background-position-x: -375px;
}
#twitter:hover div.background {
display: block;
background-position-x: -189px;
}
#book:hover div.background {
display: block;
background-position-x: -556px;
}
Working, though slightly rough example, in this jsFiddle.
Note that it's okay to have multiple copies of the sprite in multiple different divs; the browser will just grab one copy for its cache and use that for all instances of the image.
Could you create an image map and then hover swaps the image to the one with the correct envelope in front. See this link on an interesting link
google search link on idea
My method with clean HTML.
.nav { position: relative; }
.nav li {
margin-left: 179.8px;
list-style-type: none;
}
.nav li:before {
position: absolute;
left: 0; top: 0;
content: url(http://i.stack.imgur.com/I2Y4k.png);
clip: rect(0 899px 341px 719.2px);
margin-left: -719.2px;
z-index: 1;
}
.nav li:hover:before { z-index: 2; }
.email:hover:before {
clip: rect(0 179.8px 341px 0);
margin-left: 0;
}
.facebook:hover:before {
clip: rect(0 359.6px 341px 179.8px);
margin-left: -179.8px;
}
.twitter:hover:before {
clip: rect(0 539.4px 341px 359.6px);
margin-left: -359.6px;
}
.book:hover:before {
clip: rect(0 719.2px 341px 539.4px);
margin-left: -539.4px;
}
<ul class="nav">
<li class="email">Email</li>
<li class="facebook">Facebook</li>
<li class="twitter">Twitter</li>
<li class="book">Book</li>
</ul>