Create an adaptive background image - html

I want to make text always inside the white block at any screen resolution?
Hence I don't want to add ant media queries for every 100px.
HTML
<div class="wrapper">
<div class="left-wrapper"></div>
<div class="right-wrapper">
<div class="conclusion-block">
<ul class="conclusion-list content-list">
<li>Sincerely yours,/Sincerely,</li>
<li>Best regards,/All the best,</li>
<li>Regards,</li>
<li>Thank you for your consideration,</li>
<li>Respectfully,</li>
</ul>
</div>
</div>
</div>
CSS
.wrapper {
display: flex
}
.left-wrapper {
width: 35%;
}
.right-wrapper {
width: 65%;
}
.conclusion-block {
background: url(https://i.imgur.com/NKTY6Du.png);
background-size: 100%;
background-repeat: no-repeat;
}
ul.conclusion-list {
padding-bottom: 75px;
padding-top: 40px;
padding-left: 100px;
}
.conclusion-list li {
font: 18px/33px Open Sans;
font-weight: 600;
letter-spacing: 0.18px;
color: #333333;
margin-bottom: 0;
}
emphasized text
https://i.imgur.com/7B53HH7.png
right image
https://i.imgur.com/16hTMJ4.png

Use absolute units on your background image, making it the same size regardless of screen size. I just played with some numbers in my snippet below. I also disabled word wrap, so the text stays inside the image at all times.
.wrapper {
display: flex
}
.left-wrapper {
width: 35%;
}
.right-wrapper {
width: 65%;
}
.conclusion-block {
background: url(https://i.imgur.com/NKTY6Du.png);
background-size: 550px;
background-repeat: no-repeat;
}
ul.conclusion-list {
padding-bottom: 75px;
padding-top: 40px;
padding-left: 100px;
}
.conclusion-list li {
font: 18px/33px Open Sans;
font-weight: 600;
letter-spacing: 0.18px;
color: #333333;
margin-bottom: 0;
white-space: nowrap;
}
<div class="wrapper">
<div class="left-wrapper"></div>
<div class="right-wrapper">
<div class="conclusion-block">
<ul class="conclusion-list content-list">
<li>Sincerely yours,/Sincerely,</li>
<li>Best regards,/All the best,</li>
<li>Regards,</li>
<li>Thank you for your consideration,</li>
<li>Respectfully,</li>
</ul>
</div>
</div>
</div>

Try transform: scale(1);
.wrapper { display: flex }
.left-wrapper { width: 35%; }
.right-wrapper { width: 65%; }
.conclusion-block { width: 550px; transform: scale(1); background: url(https://i.imgur.com/NKTY6Du.png); background-size: 100%; background-repeat: no-repeat; }
ul.conclusion-list { padding-bottom: 75px; padding-top: 40px; padding-left: 100px; }
.conclusion-list li { font: 18px/33px Open Sans; font-weight: 600; letter-spacing: 0.18px; color: #333333; margin-bottom: 0; white-space: nowrap; }
<div class="wrapper">
<div class="left-wrapper"></div>
<div class="right-wrapper">
<div class="conclusion-block">
<ul class="conclusion-list content-list">
<li>Sincerely yours,/Sincerely,</li>
<li>Best regards,/All the best,</li>
<li>Regards,</li>
<li>Thank you for your consideration,</li>
<li>Respectfully,</li>
</ul>
</div>
</div>
</div>

If you want to keep your background with only on image you can always try to make the text smaller/wider with vh size and change your padding with % so it can follow.
Here is an exemple:
html
<div class="wrapper">
<div class="left-wrapper"></div>
<div class="right-wrapper">
<div class="conclusion-block">
<ul class="conclusion-list content-list">
<li>Sincerely yours,/Sincerely,</li>
<li>Best regards,/All the best,</li>
<li>Regards,</li>
<li>Thank you for your consideration,</li>
<li>Respectfully,</li>
</ul>
</div>
</div>
</div>
css
.wrapper {
display: flex
}
.left-wrapper {
width: 35%;
}
.right-wrapper {
width: 65%;
}
.conclusion-block {
background: url(https://i.imgur.com/NKTY6Du.png);
background-size: 100%;
background-repeat: no-repeat;
}
ul.conclusion-list {
padding-bottom: 75px;
padding-top: 12%;
padding-left: 20%;
}
.conclusion-list li {
line-height: auto;
font-family: Open Sans;
font-size: 2.1vw;
font-weight: 600;
letter-spacing: 0.18px;
color: #333333;
margin-bottom: 0;
}
You can have a look:
https://jsfiddle.net/jeymchugh/x82aqwou/
Or you can try to separate your background in different pieces so it can stay appart, this would be a better solution.

Related

How do I center my text in div tag I and why does it have a space between the words an and extremely?

How do I center my .peachtext and my .whitetext paragraph tags text within the .headertext1 div? Please help! I'm pretty new to coding. I'd also like to increase the .peachtext size to 30px and the .whitetext to about 20px but it produces a space between the words an and extremely. It seems like my text-align property is not working.
header{
width: 100%;
height: 1229px;
}
div.headerblue{
width: 100%;
height: 505px;
background-color: #323841;
}
div.headerwhite{
width: 100%;
height: 594px;
background-color: #ffffff;
}
div.headerorange{
width: 100%;
height: 130px;
background-color: #f25c43;
}
div.headertext1 {
width: 940px;
margin: auto;
padding-top: 30px;
}
p.peachtext {
color: #f25c43;
font-size: 20px;
text-align: center;
}
p.whitetext {
color:white;
font-size: 10px;
text-align: center;
}
<header>
<div class="headerblue">
<div class="headertext1">
<p class="peachtext">WE PROVIDE AN EXTREMELY</p>
<p class="whitetext">LOW PRICE</p>
</div>
</div>
<div class="headerwhite"></div>
<div class="headerorange"></div>
</header>
if you want to center your .peachtext and, .whitetext inside your div.headertext1
you should set the width of your
.headertext1 from 940px to 100%
div.headertext1 {
width: 100%; //set this to 100%
margin: auto;
padding-top: 30px;
}
or you change the width to max-width if you want to keep 940px
div.headertext1 {
max-width: 940px; //set this to max-width
margin: auto;
padding-top: 30px;
}
and if you want to adjust the font size of your text you may use "VW" instead of "PX"
like this
p.peachtext {
color: #f25c43;
font-size: 4vw;
text-align: center;
}
p.whitetext {
color:white;
font-size: 2vw;
text-align: center;
}
Ran snippet on Firefox and the placements are exactly like you want them to be, both paragraphs nicely in the center of the div. Just increase your font-sizes to get the sizes you want. You sure your css file is correctly linked ?
header{
width: 100%;
height: 1229px;
}
div.headerblue{
width: 100%;
height: 505px;
background-color: #323841;
}
div.headerwhite{
width: 100%;
height: 594px;
background-color: #ffffff;
}
div.headerorange{
width: 100%;
height: 130px;
background-color: #f25c43;
}
div.headertext1 {
width: 100%;
margin: auto;
padding-top: 30px;
}
p.peachtext {
color: #f25c43;
font-size: 30px;
text-align: center;
}
p.whitetext {
color:white;
font-size: 20px;
text-align: center;
}
<header>
<div class="headerblue">
<div class="headertext1">
<p class="peachtext">WE PROVIDE AN EXTREMELY</p>
<p class="whitetext">LOW PRICE</p>
</div>
</div>
<div class="headerwhite"></div>
<div class="headerorange"></div>
</header>
Check the above code.

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

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.

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;

Arrange DIVs in the right position

I'm having huge problems trying to arrage my DIVs, as I found that this thing is not as simple as it seems, just put a DIV and inside that DIV another 2 and you're done. The image bellow shows how I would want my page to be structured:
sur1.
surf2: surfleft, surfright. surf3. surf4 Where . means another line and , means that DIVs should be one next to another.
And also can't center that image vertical and horizontall middle on surfright from surf 2 parent.
#font-face
{
font-family: FONT;
src: url(Montserrat-Regular.ttf);
}
p.title1
{
font-size: 2.5em;
margin: 0;
}
p.title2
{
font-size: 3em;
}
.i1
{
height: 400px;
float: right;
display: block;
margin-top: 150px;
}
div.surf1
{
display: block;
background-image: url("surf1.jpg");
background-position: center;
background-size: cover;
height: 600px;
}
div.surf2 {
width: fit-content;
position:absolute;
background: #41c3ac;
height: 600px;
}
div.surfleft {
float:left;
display: block;
width: 45%;
padding-top: 80px;
height: 600px;
background: #8C78B1;
}
div.surfright {
float: right;
background: #ff6b57;
}
div.surf3
{
background: #ff6b57;
height: 600px;
}
div.surf4
{
background: #8C78B1;
height: 600px;
}
div.text1
{
padding-top: 100px;
color: white;
text-align:center;
font-size: 2.5em;
}
div.button
{
text-align: center;
font-size: 1.5em;
margin: 0 auto;
width: 15%;
padding: 8px;
border: 2px solid;
border-color: #e7dd84;
background-color: rgba(236,229,167,0.2);
color: #e7dd84;
transition: 0.35s;
}
div.button:hover
{
background-color: white;
color: black;
border-color: white;
transition: 0.35s;
}
body
{
margin: 0;
font-family: FONT;
color: white;
}
<!doctype html>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<div class="surf1">
<div class="text1">
<b>Welcome to smartlearning.com, <br>the place where you can <br>learn and practice English</b>
</div>
<br><br><br><br><br>
<div class="button">
Go to site
</div>
</div>
<div class="surf2">
<div class="surfleft">
<p class="title1">Interractive games</p>
<ul style="font-size: 1.5em">
<li>We have different types of games you can play, testing your abilities to recognise objects, multiple choise exercices and also putting you to the test of spotting mistakes.</li>
<li>Those games are designed to help you learn and practice english by combining fun with hard-working.</li>
</ul>
</div>
<div class="surfright">
<img src="console.png" alt="404 Image not Found" height="400px">
</div>
</div>
<div class="surf3"></div>
<div class="surf4"></div>
<body>
</body>
</html>
Please note that you may use correct width values to have fine edges in your design.
div.surf1
{
display: block;
background-color: #cdcdcd;
height: 100px;
}
div.surf2 {
background: #41c3ac;
height: 100px;
}
div.surfleft {
float:left;
display: block;
width: 50%;
height: 100px;
background: #8C78B1;
}
div.surfright {
float: right;
width: 50%
background: #ff6b57;
}
div.surf3
{
background: #ff6b57;
height: 100px;
}
div.surf4
{
background: #8C78B1;
height: 100px;
}
body
{
margin: 0;
font-family: FONT;
color: white;
}
<div class="surf1">
<div class="text1">Surf 1</div>
</div>
<div class="surf2">
<div class="surfleft">Surf left</div>
<div class="surfright">Surf right</div>
</div>
<div class="surf3">Surf 3</div>
<div class="surf4">Surf 4</div>

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>