How to get the overlaps effect when the width is reduce? - html

I imitate a website: https://open.weixin.qq.com/
You see the overlaps is my requirement, if I reduce the width of browser.
But in my project when I reduce the browser width, I will get the this irksome effect:
My code is bellow, the images can not shows up but this is not the point:
.header {
width: 100%;
height: 68px;
background-color: #363636;
}
.container {
margin-left: 40px;
margin-right: 40px;
}
.container > div {
display: inline-block;
}
.logo {
height: 100%;
width: 240px;
}
.logo img {
width: 100%;
height: 100%;
}
.nav {
display: inline-block;
}
.nav li {
width: 96px;
height: 100%;
color: #afafaf;
line-height: 68px;
float: left;
}
.nav li :hover {
color: #fff;
text-align: center;
}
.nav .selected {
color: #fff;
}
.right-buttons {
float: right;
}
.login-logout {
float: right;
display: inline-block;
height: 68px;
color: #ffffff;
line-height: 68px;
}
.qrcode {
float: right;
display: inline-block;
width: 68px;
height: 68px;
align-content: center;
line-height: 68px;
}
.qrcode img {
line-height: 68px;
width: 14px;
height: 14px;
}
<div class="header">
<div class="container">
<div class="logo">
<img src="../../assets/img/common/logo.png">
</div>
<ul class="nav">
<li class="nav-item selected">首页</li>
<li class="nav-item">数据中心</li>
</ul>
<div class="right-buttons">
<div class="login-logout">
<button>登录/注册</button>
</div>
<div class="qrcode">
<img src="../../assets/img/home/little-qrcode.png">
</div>
</div>
</div>
</div>
How can I get the upper effect?

As I understood, you need right-buttons div overlapped to nav ul instead of going to next line.
Apply "position:absolute" and "right: 0" to right-buttons instead of "float: right".
But in smaller widths, overlapping will confuse the user. So its better you make it responsive for all devices.

Related

Image is not being responsive even with 100% width/max-width

1 2 I am trying to make the Google Search Page in HTML & CSS. However, when I try to center the Google Logo, the image re-adjusts itself when the device width is changed. I've been stuck in this section for quite a while now, and cannot seem to find any answers to my inquiry. Some assistance would be appreciated.
body {
width: 100%;
max-width: 100%;
background-color: #202124;
overflow: hidden;
}
.navbar {
display: flex;
float: right;
position: relative;
word-spacing: 11px;
padding-top: 13px;
padding-right: 129px;
}
.navbartxt a {
text-decoration: none;
color: white;
font-family: arial, sans-serif;
font-size: 13px;
}
.navbartxt a:hover {
text-decoration: underline;
}
.dots {
width: 16px;
position: absolute;
margin-left: 123px;
margin-top: 1px;
}
.pfp {
position: absolute;
border-radius: 100%;
margin-top: -7px;
margin-left: 163px;
}
.searchbox {
display: flex;
position: absolute;
}
.searchsections {
width: 100%;
max-width: 100%;
display: flex;
position: relative;
}
.Google {
position: absolute;
margin-top: 72px;
margin-left: 240px;
}
<nav>
<div class="navbar">
<div class="navbartxt">
Gmail
Images
</div>
<img class="dots" src="/CSS/CSS Images/9 dots.png" />
<img class="pfp" src="/CSS/CSS Images/MyPfpGoogle.png" />
</div>
</nav>
<section class="searchsections">
<div class="Google">
<img src="/CSS/CSS Images/Google Logo.png" />
</div>
</section>
Just replace your .Google class with this :-
.Google {
display: flex;
justify-content: center; /* for horizontal center */
align-items: center; /* For Vertical Center */
}
.Google > img {
display: block;
}
How it works learn Here

Content spills out of DIV's bottom

Content of two DIVs spills out of the bottom.
This problem arises not with all browsers. Chrome, IE, Edge - works fine but Firefox, Safari and Chrome for mobile (Android) reflects this problem.
Screenshot: chrome for Android (tablet device)
What's wrong with the code?
html {
height: 100%;
}
body {
background-image: url("background.jpg");
background-size: cover;
background-position: center center;
background-repeat: repeat;
height: 100%;
font-family: 'Times New Roman', Times, sans-serif;
font-size: 16px;
}
#open-hours {
float: left;
}
#contacts {
float: right;
}
.ins {
width: 4%;
height: 4%;
}
hr {
background-color: black;
}
#first-row-1 {
width: 362px;
height: 264px;
margin-right: -4px;
}
#first-row-1 img {
width: 100%;
height: 100%;
}
#first-row-2 {
width: 360px;
height: 262px;
border: 1px solid black;
vertical-align: top;
}
#first-row-2 h4 {
margin-top: 5px;
}
#first-row-1,
#first-row-2,
#second-row-1,
#second-row-2 {
display: inline-block;
}
#first,
#second,
h2 {
text-align: center;
}
#first-row-2 ul,
#second-row-1 ul {
text-align: left;
}
#logo {
width: 358px;
height: 34px;
}
#logo img {
width: 68px;
height: 34px;
}
#second-row-1 {
width: 360px;
height: 262px;
border: 1px solid black;
vertical-align: top;
margin-right: -4px;
}
#second-row-2 {
width: 362px;
height: 264px;
}
#second-row-2 img {
width: 100%;
height: 100%;
}
#second {
margin-top: -4px;
}
#media only screen and (max-width: 766px) {
#first-row-1,
#second-row-2,
#hide,
.ins,
.free-space {
display: none;
}
#open-hours,
#contacts {
float: none;
text-align: center;
}
#first-row-2,
#second-row-1 {
border: 1px solid black;
margin: 0 auto;
display: block;
width: 100%;
}
#second {
margin: 0px;
}
span {
display: block;
}
h2 {
font-size: 18px;
}
h4 {
margin: 5px 0px -10px 0px;
}
#logo {
margin: auto;
}
}
#media only screen and (max-width: 393px) {
#logo {
display: none;
}
#first-row-2,
#second-row-1 {
min-width: 285px;
}
}
<div>
<div id="open-hours">пн-пт 10.00-20.00</div>
<div id="contacts">
<img class="ins" src="phone_pic.png"> text
<img class="ins" src="envelope_pic.png"> <span>text</span>
</div>
<br class="free-space">
<hr>
<br class="free-space">
<h2>Успешный опыт продаж <span id="hide">кондиционеров и климатической техники</span> с 2007 года</h2>
<div id="first">
<div id="first-row-1">
<img src="photo_1.jpg">
</div>
<div id="first-row-2">
<h4>Мы предлагаем широкий спектр оборудования</h4>
<ul>
<li>бытовые кондиционеры</li>
<li>кондиционеры для коммерч. применения</li>
<li>тепловые насосы</li>
<li>осушители воздуха</li>
<li>мультизональные VRF системы</li>
<li>системы бытовой, полупромышленной и промышленной вентиляции</li>
<li>приточно-вытяжные агрегаты</li>
<li>тепловые завесы</li>
</ul>
<div id="logo">
<img src="logo.gif">
<img src="logo.png">
<img src="log.png">
<img src="logo.png">
<img src="logo.jpg">
</div>
</div>
</div>
<div id="second">
<div id="second-row-1">
<h4>Оплата</h4>
<ul>
<li>наличный расчет - в пункте выдачи или по факту доставки продукции</li>
<li>безналичный расчет - оплата физическими и юридическими лицами</li>
</ul>
<h4>Доставка</h4>
<ul>
<li>самовывоз</li>
<li>собственным транспортом компании</li>
<li>почтовыми, курьерскими службами Украины</li>
</ul>
</div>
<div id="second-row-2">
<img src="photo_2.jpg">
</div>
</div>
</div>
Try to replace height of first row and second row divs to min-height and height to auto
#first-row-1{
width: 362px;
height:auto;
min-height: 264px;
margin-right: -4px;
}
#first-row-2{
width: 360px;
height:auto;
min-height: 262px;
border: 1px solid black;
vertical-align: top;
}
I tried to fix your issue without making too many changes, but really the issue is, that you are setting fixed height to child elements and they overflows their parents. I'd suggest to make the layout responsive to save yourself headaches in the future when you'll want to write longer paragraphs.
Without changing the code too much, you could
do following changes to the first and second divs
display: flex;
Desired width, e.g. 2*362
margin: auto;
Following to first-row-1, first-row-2 and the same for second row
delete width and height attributes (or change height to min-height for design purposes)
flex: 1 0 0;

stack the 2nd element first and then the 3rd element

I have three divs. I want them to be in one line so I used inline-block. When I resize the window the third element (nav) stacks and then the 2nd element (searchBar). I want the 2nd element stacks first and then the 3rd one. For undoing, the 3rd element and then the 2nd element.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-eight: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</header>
You could use an inline-block wrapper with a min-width, wrapping the nav and searchBar. That would give the result you wanted in with the code sample supplied, but might cause problems in the real world, depending on your requirements.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-height: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
.wrapper {
min-width: 50%;
display: inline-block;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div class="wrapper">
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</div>
</header>

Mobile Page Full-width - Centering Text with Icon

I don't know why I'm struggling with what seems to be such a simple thing. Right now I have a mobile page (which can also be viewed on desktop) which is using a full-width layout.
Inside it, I'd just like to center my text (of indeterminable size) and an icon that is 30x30 px.
<div id="contact-info">
<div class="email">
<div class="icon-left">
<img src="image/mobile/message-dark.png" />
</div>
<div class="info-right">
myverylongemailmyverylongemail#gmail.com
</div>
</div>
</div>
As the e-mail grows longer on the right, I'd like the to increase in width but the whole thing stays centered.
#contact-info {
padding: 15px 0;
color: #F7F8F8;
font-size: 20px;
}
#contact-info .email {
height: 48px;
width: 300px;
margin: 0 auto;
}
#contact-info .icon-left {
width: 50px;
height: 100%;
float: left;
}
#contact-info .icon-left img {
width: 30px;
height: 30px;
}
#contact-info .info-right {
min-width: 240px;
height: 50%;
padding-top: 10px;
font-size: 12px;
float: right;
}
The flexible box technique is best suited for your solution. Not need to define the fixed width for it using this method.
Check the browser compatibility table for Flexbox
#contact-info {
padding: 15px 0;
color: #F7F8F8;
font-size: 20px;
}
#contact-info .email {
height: 48px;
display: flex;
justify-content: center;
}
#contact-info .icon-left {
width: 50px;
height: 100%;
float: left;
}
#contact-info .icon-left img {
width: 30px;
height: 30px;
}
#contact-info .info-right {
min-width: 240px;
height: 50%;
padding-top: 10px;
font-size: 12px;
float: right;
color: black;
}
<div id="contact-info">
<div class="email">
<div class="icon-left">
<img src="http://placehold.it/30x30" />
</div>
<div class="info-right">
myverylongemailmyverylongemail#gmail.com another
email#gmail.com
</div>
</div>
</div>

How to stick bars to the bottom in this chart

I made a chart with html+css (i really need it to work in all browsers)
its ok but the bars are on the top and i need them to stick to the bottom
i tried vertical-align and tried some other things but neither of them worked
Here is a jsfiddle (if you see it you'll know what i mean)
JsFiddle
Code:
CSS:
.clear {clear:both; line-height: 0; width: 0; height: 0}
#chart {
width: 100%;
height: 220px;
font-family: Arial,sans-serif;
font-size: 12px;
line-height: 17px;
color: #777777;
}
#scale, #chartwrap, #description {
float: left;
margin-right: 7px;
}
#scale {
margin-top: -7px;
}
#scale i {
display: block;
text-align: right;
}
#chartbox {
height: 170px;
display: inline-block;
border: 2px solid #C7C7C7;
border-right: 0;
border-top: 0;
}
.thisday {
display: inline-block;
height: 170px;
margin: 0 18px;
width: 40px;
vertical-align: bottom;
}
.vbottom {
display: block;
}
.thisday .in, .thisday .out {
width: 18px;
display: inline-block;
vertical-align: bottom;
}
.thisday .in span, .thisday .out span {
text-align: center;
font-size: 11px;
color: #2F6D91;
display: block;
}
div.inbar, div.outbar {
width: 18px;
float: left;
background: #41799F;
}
div.outbar {
background: #A5D2F0;
}
div#days {
margin-top: 5px;
}
div#days i {
font-size: 11px;
float: left;
width: 36px;
margin: 0 18px;
}
#description {
margin-left: 7px;
}
#outdes {
margin-top: 1px;
}
#indes i, #outdes i {
float: left;
display: inline-block;
width: 12px;
height: 12px;
background: #40779D;
}
#outdes i {
background: #A5D2F0;
}
#indes span, #outdes span {
float: left;
margin-left: 3px;
line-height: 12px;
font-size: 11px;
}
HTML:
<div id="chart">
<div id="scale">
<i>500</i>
<i>450</i>
<i>400</i>
<i>350</i>
<i>300</i>
<i>250</i>
<i>200</i>
<i>150</i>
<i>100</i>
<i>50</i>
<i>0</i>
</div>
<div id="chartwrap">
<div id="chartbox">
<!-- DAILY -->
<div class="thisday">
<div class="vbottom">
<div class="in">
<span>50</span>
<div class="inbar" style="height:20px;"></div>
</div><div class="out">
<span>10</span>
<div class="outbar" style="height:5px;"></div>
</div>
</div>
</div>
<!-- /DAILY -->
<!-- DAILY -->
<div class="thisday">
<div class="vbottom">
<div class="in">
<span>50</span>
<div class="inbar" style="height:20px;"></div>
</div><div class="out">
<span>10</span>
<div class="outbar" style="height:5px;"></div>
</div>
</div>
</div>
<!-- /DAILY -->
<br class="clear">
</div>
<div id="days">
<i>02-17</i>
<i>02-18</i>
<br class="clear">
</div>
</div>
<div id="description">
<div id="indes"><i></i><span>Received</span><br class="clear"></div>
<div id="outdes"><i></i><span>Sent</span><br class="clear"></div>
</div>
<br class="clear">
</div>
here is your new CSS code :
.clear {clear:both; line-height: 0; width: 0; height: 0}
#chart {
width: 100%;
height: 220px;
font-family: Arial,sans-serif;
font-size: 12px;
line-height: 17px;
color: #777777;
}
#scale, #chartwrap, #description {
float: left;
margin-right: 7px;
}
#scale {
margin-top: -7px;
}
#scale i {
display: block;
text-align: right;
}
#chartbox {
height: 170px;
display: inline-block;
border: 2px solid #C7C7C7;
border-right: 0;
border-top: 0;
}
.thisday {
display: inline-block;
height: 170px;
margin: 0 18px;
width: 40px;
vertical-align: bottom;
position: relative;
}
.vbottom {
display: block;
position: absolute;
bottom:0px;
}
.thisday .in, .thisday .out {
width: 18px;
display: inline-block;
vertical-align: bottom;
}
.thisday .in span, .thisday .out span {
text-align: center;
font-size: 11px;
color: #2F6D91;
display: block;
}
div.inbar, div.outbar {
width: 18px;
float: left;
background: #41799F;
}
div.outbar {
background: #A5D2F0;
}
div#days {
margin-top: 5px;
}
div#days i {
font-size: 11px;
float: left;
width: 36px;
margin: 0 18px;
}
#description {
margin-left: 7px;
}
#outdes {
margin-top: 1px;
}
#indes i, #outdes i {
float: left;
display: inline-block;
width: 12px;
height: 12px;
background: #40779D;
}
#outdes i {
background: #A5D2F0;
}
#indes span, #outdes span {
float: left;
margin-left: 3px;
line-height: 12px;
font-size: 11px;
}
To sum up, I just added position: relative; to the end of .thisday, and I also added position: absolute; and then bottom:0px; to .vbottom.
Also, this method will still work if one day you enlarge your graphic. It will stick to the bottom of your graph and you will not have to reajust from top. If you want the bars to go a pixel more or less from the bottom, just do bottom:-1px; or bottom:1px; instead of 0px and it will be readjusted !
This will make the bars always align along the bottom of the chart. It's a nice solution as long as you don't need to support earlier versions of IE than 8.
.thisday {
display: inline-table;
height: 170px;
margin: 0 18px;
width: 40px;
}
.vbottom {
display: table-cell;
vertical-align: bottom
}
.thisday is the container and has been given display: inline-table, and the area supposed to be in the bottom has display: table-cell and vertical-align: bottom.
EDIT: since .vbottom is not absolutely positioned, width on .thisday can be left out altogether, in case you might want to add more bars per day or so. That's one clear advantage of this method.
Forked fiddle: http://jsfiddle.net/7VvZA/1/
Add position relative for chartbox class:
position: relative;
and position absolute for vbottom class:
position: absolute;
bottom: 0;
UPDATE (I work in devtools and don't save changes here is updated version):
http://jsfiddle.net/QzHzT/2/