I'm a newbie and trying to figure out how to stack these two boxes on top of each other when the browser gets resized. I don't want to use float, I'd rather stick to inline-block unless anyone else has strong suggestion against it. I was thinking I guess in using inline-block that the boxes would stack when the div got resized with the browser but it isn't happening. The boxes are just getting skinner and skinner and the text just wraps and exceeds the box. `
.cp2_maincontainer {
width: 100%;
height: 300px;
font-size: 0;
display: flex;
justify-content: space-between;
padding: 10px 50px 20px 50px;
}
.cp2_container {
width: 47%;
height: 100%;
background: no-repeat center;
display: inline-block;
position: relative;
}
.cp2_subcontainer {
background-color: rgba(211, 211, 211, .8);
height: 100%;
width: 100%;
padding: 10px 15px;
font-size: 16px;
font-family: playfair display;
position: absolute;
outline: solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer ul {
margin-left: 20px;
}
.cp2_subcontainer p {
margin: 10px;
}
.cp2_subcontainer h3 {
padding: 10px 0;
}
.cp2_container2 {
background-color: darkgrey;
background: no-repeat center;
width: 47%;
height: 100%;
display: inline-block;
position: relative;
}
.cp2_subcontainer2 {
background-color: rgba(211, 211, 211, 0.8);
height: 100%;
width: 100%;
padding: 10px 15px;
font-size: 16px;
font-family: playfair display;
position: absolute;
outline: solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer2 ul {
margin-left: 20px;
}
.cp2_subcontainer2 p {
margin: 10px;
}
.cp2_subcontainer2 h3 {
padding: 10px 0;
}
.addtextarea {
color: black;
padding: 10px;
width: 100%;
font-size: 16px;
text-align: justify;
}
<div class="cp2_maincontainer">
<div class="cp2_container" style="background-image:URL(<?php the_field('imageleft'); ?>)">
<div class="cp2_subcontainer">
<h3 style="text-align:center;">Title for Text Box 1</h3>
<p>Text in box # 1</p>
</div>
</div>
<div class="cp2_container2" style="background-image:URL(<?php the_field('imageright'); ?>)">
<div class="cp2_subcontainer2">
<h3 style="text-align:center;">Title for Text Box 2</h3>
<p>Text in box #2</p>
</div>
</div>
</div>
<div class="sectionbreak" align="center"></div>
You gave the divs a width in percentage. That means that as their container grows smaller, so do they, and they never have a reason to break. The obvious solution is to give them a fixed width (px, em).
If for some reason you need the percentages to work up to a certain point (for the purpose of bigger screens for example), two options come to mind:
Give the divs a min-width, so that once they hit that width the percentages will be ignored and the line will break.
Using media queries, define a different width for them based on screen size.
.cp2_maincontainer {
width:100%;
height:300px;
font-size: 0px;
display:flex;
justify-content: space-between;
padding: 10px 50px 20px 50px;
}
.cp2_container {
width:47%;
height:100%;
background: no-repeat center;
display:inline-block;
position: relative;
}
.cp2_subcontainer {
background-color: rgba(211, 211, 211, 0.8);
height:100%;
width:100%;
padding:10px 15px;
font-size:16px;
font-family: playfair display;
position: absolute;
outline:solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer ul{
margin-left:20px;
}
.cp2_subcontainer p{
margin:10px;
}
.cp2_subcontainer h3{
padding:10px 0px;
}
.cp2_container2 {
background-color: darkgrey;
background: no-repeat center;
width:47%;
display:inline-block;
position: relative;
min-width: 300px;
position: absolute;
right: 0;
height:300px;
}
.cp2_subcontainer2 {
background-color: rgba(211, 211, 211, 0.8);
height:100%;
width:100%;
padding:10px 15px;
font-size:16px;
font-family: playfair display;
position: absolute;
outline:solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer2 ul{
margin-left:20px;
}
.cp2_subcontainer2 p{
margin:10px;
}
.cp2_subcontainer2 h3{
padding:10px 0px;
}
.addtextarea {
color: black;
padding: 10px;
width: 100%;
font-size: 16px;
text-align: justify;
}
<div class="cp2_maincontainer">
<div class="cp2_container" style="background-image:URL(<?php the_field('imageleft'); ?>)">
<div class="cp2_subcontainer">
<h3 style="text-align:center;">Title for Text Box 1</h3>
<p>Text in box # 1</p>
</div>
</div>
<div class="cp2_container2" style="background-image:URL(<?php the_field('imageright'); ?>)">
<div class="cp2_subcontainer2">
<h3 style="text-align:center;">Title for Text Box 2</h3>
<p>Text in box #2</p>
</div>
</div>
</div>
<div class="sectionbreak" align="center">
</div>
I think this is what you are trying to accomplish.
I have added/edited the following on .cp2_container2
min-width: 300px;
position: absolute;
right: 0;
height:300px;
You need a min-width in order to have the 2 boxes overlap, otherwise they will always be half the width of the page and never overlap.
Positioning absolutely allows the div to freely pass over the statically positioned one.
Right just tells the div to position at the right edge of whatever it is relative to, in this case the body.
By positioning absolutely the height 100% becomes relative to the entire window, I have solved by using a pixel height, although you could also position the cp2_maincontainer relative and given it a height, making the height 100% of cp2_container2 relative the height of cp2_maincontainer.
Good luck.
Related
I want the text to shrink as the image shrinks. e.g. maintain the same ratio in size relative to the image. I've tried making the text disappear but it simply isn't what I want.
The CSS:
.header{
padding: 0.16px 16px;
position: relative;
box-sizing: inherit;
display: block;
font-size: 15px;
line-height: 1.5;
text-size-adjust: 100%;
content: "";
display: table;
clear: both;
font-family: "Montserrat", sans-serif;
}
.top-left{
padding: 24px 48px;
margin-left: 16%;
position: absolute;
left: 0px;
top: 0px;
box-sizing: inherit;
display:block;
font-size: 15px;
line-height: 22.5px;
text-size-adjust:100%;
}
.header-image{
vertical-align:middle;
border-style: none;
box-sizing: border-box;
width:65%;
height:auto;
margin:30px 250px;
}
#media screen and (max-width: 600px) {
.header-image {
margin-left: auto;
margin-right: auto;
display: block;
width:65%;
}
}
.new-arrivals{
position: absolute;
display:block;
left: 0;
top: 0;
margin:10px 5px 10px 0;
font-size: 4vw !important;
color:black;
padding: 50px 100px;
font-weight: 400;
line-height: 60px;
}
.shop-now{
border:none;
display:inline-block;
padding:12px 24px;
margin: 260px 50px;
vertical-align:middle;
overflow:hidden;
text-decoration:none;
color:white;
background-color:black;
text-align:center;
white-space: nowrap;
font-size: 18px
}
.shop-now:hover{
background-color: #ccc;
color: black;
border-style: ridge;
border-color: black;
border-width: 1px;
}
.designs{
position: absolute;
left: 0;
top: 0;
font-size: 20px !important;
font-family: "Montserrat", sans-serif;
margin: 150px 0;
color:black;
padding: 24px 100px;
font-weight: 400;
}
The HTML:
<div class="header">
<img class="header-image" src="img/jeans.jpg" alt="Jeans">
<div class="top-left">
<h1 class="new-arrivals">New arrivals</h1>
<p><h3 class="designs">Our new season collection is here</h3> </p>
<p>SHOP NOW</p>
</div>
</div>
If you want the text to be responsive as the image, you need to set h1 element style in your CSS file. For example:
.new-arrivals {
font-size:clamp(2em, 4vw, 4em); /* set min, ideal value, max */
}
I was trying to do the same thing for my portfolio. And I end up putting my text imbedded inside the image by using the ms paints. The text inside image can't be responsive if it's not of part of image. I hope that help.
You can accomplish this by setting both the width of the image and the font-size based on the width of the screen. Below is an example of that.
This question is similar, and the answers there may be helpful to you as well.
body {
margin: 0;
}
.container {
position: relative;
color: white;
width: fit-content;
}
.top-left {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 3vw;
}
img {
width: 100vw;
}
<div class="container">
<img src="https://html.com/wp-content/uploads/flamingo.jpg">
<div class="top-left">
<h1 class="new-arrivals">New arrivals</h1>
<h3 class="designs">Our new season collection is here</h3>
<p>SHOP NOW</p>
</div>
</div>
If you don't need the image to scale with the screen width, you can simply set a fixed pixel size for both the image and the text.
CSS for the Text:
.text {
font-size: 15vw;
}
CSS for the Image
img {
width: 10vw;
max-width: /* Set this to 10-15cm if you want to show you page on
mobiles too */
min-width: /* Set this to 8-10cm if you want to show you page on
mobiles too */
}
try these and adjust
font-size: clamp(1rem, 3vw, 2rem)
font-size: max(1rem, 3vw)
font-size: calc(200% + 2vw)
I'm having trouble with creating a transparent box on top of a background image, like this. My code is almost exactly the same, but for some reason, I can't get the transparent box to move away from the top of the image (I'd like the box to be centered with some margin above and below). Adding padding:20px to .background does nothing; adding margin:20px to #transbox only increases the left and right margins by 20px, but does nothing to the top and bottom margins.
HTML & CSS:
.background {
background-image: url("https://source.unsplash.com/5OMTuqOM7bI");
}
#transbox {
background-color: rgba(255, 255, 255, 0.8);
padding: 20px;
margin: 60px;
}
h3 {
text-align: center;
font-weight: 300;
color: #3C5FA3;
}
.container {
width: 80%;
margin: 0 auto;
padding: 0 30px;
}
.clearfix:after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0;
}
<div class="container clearfix background">
<div id="transbox">
<h3>Some text here</h3>
</div>
</div>
Several options to get this. One of them is to set the padding-top/bottom of the container.
padding: 30px;
(instead of padding: 0 30px).
Here is the fix to your code:
.background {
background-image:url("https://source.unsplash.com/5OMTuqOM7bI");
}
#transbox {
background-color:rgba(255,255,255,0.8);
padding:20px;
margin:60px;
}
h3 {
text-align:center;
font-weight:300;
color:#3C5FA3;
}
.container {
width: 80%;
margin: 0 auto;
padding: 30px;
}
.clearfix:after {
visibility:hidden;
display:block;
content:"";
clear:both;
height:0;
}
<div class="container clearfix background">
<div id="transbox">
<h3>Some text here</h3>
</div>
</div>
You don't need a clearfix or anything for this case. All you need is the background opacity. The key here is to give the container:
position: relative;
height: <some>px;
And the transbox:
position: absolute;
top and right values.
If you want it to be centered, it's very easy. Use a dead centre trick like this:
.background {
background-image: url("https://source.unsplash.com/5OMTuqOM7bI");
}
#transbox {
background-color: rgba(255, 255, 255, 0.8);
padding: 20px;
margin: 60px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h3 {
text-align: center;
font-weight: 300;
color: #3C5FA3;
}
.container {
width: 80%;
margin: 0 auto;
padding: 0 30px;
position: relative;
height: 500px;
}
<div class="container background">
<div id="transbox">
<h3>Some text here</h3>
</div>
</div>
Initial Version
Centered Version
padding: 0 30px; is identical to padding-top: 0; padding-right: 30px; padding-bottom: 0; padding-left: 30px;
You say:
Adding padding: 20px; to .background does nothing
That's because later in your CSS you overwrite this padding in .container.
If two or more rules have the same CSS specificity, the one that occurs last wins. Since both selectors have identical specificity, .container definitions win over .background definitions.
I have a problem with a to fixed divs in the right and left bottom corner. On a desktop they look good, the divs are in the corner. However, when on mobile, the divs are fixed and overlap the rest of the content. I tried a margin-bottom but that didn't fix the problem.
What I want is that the two info divs are fixed but when you are on mobile that there is a gap between the info divs and the div class="wrap".
Here's my html
<div class="wrap">
<h1 class="titel">Media Media B.V.</h1>
</div>
<div class="info container">
<div class="row">
<div class="address col-md-6">
<p><strong>Media Media B.V.</strong><br/>
Vriendsgracht 77<br/>
2542AH Utrecht<br/>
The Netherlands</p>
<p><abbr title="Phone">Skype:</abbr> john.doe<br/>
info#media.nl</p>
</div>
<div class="vat col-md-6">
<p><abbr title="Chamber of Commerce">CoC:</abbr> 4444444<br/>
<abbr title="Value Added Tax">VAT:</abbr> NL444444444</p>
</div>
</div>
</div>
This is the css i used
body {
background-color: #1A4C62;
height: 100%;
}
.wrap {
background-color: blue;
margin-bottom: 7.5%;
position: relative;
}
.titel {
color: #fff;
font-family: 'Lato', sans-serif;
text-align: center;
padding-top: 7.5%;
}
.titel2 {
color: #fff;
font-family: 'Lato', sans-serif;
text-align: center;
}
.logo {
margin: 0 auto;
}
.ondertitel {
color: #fff;
font-family: 'Lato', sans-serif;
text-align: center;
}
.info {
color: #fff;
font-family: 'Lato', sans-serif;
}
div.info {
width: 100%;
}
div.info div p {
margin: 2px 0px 5px 0px;
}
div.info div strong {
display: inline-block;
font-size: 13px;
}
div.info .address {
position: fixed;
bottom: 0;
left: 0;
width: 150px;
padding: 10px 25px 10px 15px;
border: 1px solid #fff;
}
div.info .vat {
position: fixed;
bottom: 0;
right: 0;
width: 150px;
padding: 10px 15px 10px 25px;
border: 1px solid #fff;
}
You use only col-md rules, set col-sm and col-xs attributes to your HTML and it should solve the problem for mobiles
<!DOCTYPE html>
<html>
<head>
<style>
/* main elements */
div.body {
display: block;
background-color: Lavender;
border: 0px 20px 0px 20px;
max-width: 1100px;
margin-top: 10px;
margin-right:20px;
margin-left: 20px;
clear: both;
padding: 0px 20px 0px 20px;
}
body {
display: block;
background-color: Lavender;
border: 10px;
max-width:1100px;
margin: 0px 280px 0px 10px;
clear:both;
}
/*Body Divs*/
div.bodycontent{
display:block;
position:absolute;
top: 10px;
width: 1075px;
height: 470px;
background-color: MediumAquaMarine;
margin-right:0;
margin-left:0px;
bottom:10px;
}
div.body1 {
display: inline-block;
background-color: limegreen;
position: absolute;
top: 10px;
width:480px;
height:225px;
margin-left:10px;
padding: 0 10px 0 10px;
}
div.body2 {
display: inline-block;
background-color: Salmon;
position: absolute;
top: 10px;
width:525px;
height:225px;
margin-left:520px;
padding: 0 10px 0 10px;
}
div.body3 {
display: inline-block;
background-color: FireBrick;
position: absolute;
top: 250px;
width:530px;
height:205px;
margin-left:10px;
padding: 0 10px 0 10px;
}
div.body4 {
display: inline-block;
background-color: SeaGreen;
position: absolute;
top: 250px;
width:475px;
height:205px;
margin-left:570px;
padding: 0 10px 0 10px;
}
/*-----------------------------------------------------------------------*/
header {
background-color: Lavender;
}
/*header divs*/
div.header {
display:block;
position:absolute;
width: 1075px;
height:150px;
top:490px;
background-color: PaleGoldenRod;
margin-right:0;
margin-left: 0px;
}
div.backinfo {
display:inline-block;
background-color: lightblue;
position: absolute;
top:80px;
width:455px;
padding:10px 10px 10px 10px;
height:40px;
margin-right:900px;
margin-left:10px;
}
div.digitalbay {
display: inline-block;
background-color: coral;
position: absolute;
width:455px;
height:60px;
top:20px;
margin-top:-10px;
margin-right:560px;
margin-left:180px;
padding: 0 10px 0 10px;
}
div.nav {
display: inline-block;
position: absolute;
background-color: lightblue;
top:10px;
margin-right:0px;
margin-left:665px;
padding: 10px 0px 10px 0px;
height:110px;
width:395px;
}
div.contact {
display: inline-block;
background-color: Chocolate;
position: absolute;
top: 100px;
width:300px;
height:45px;
margin-right:550px;
margin-left:190px;
padding: 0 10px 0 10px;
}
div.contact2 {
display: inline-block;
background-color: DeepPink;
position: absolute;
top: 100px;
width:130px;
height:45px;
margin-right:550px;
margin-left:515px;
padding: 0 10px 0 10px;
}
</style>
</head>
<div class="bodydiv">
<header>
<div class="header">
<div class="backinfo">
</div>
<div class="digitalbay">
<h1>Digital Bay</h1>
</div>
<div class="nav">
</div>
</header>
<body>
<div class="bodycontent">
<div class="body1">
</div>
<div class="body2">
</div>
<div class="body3">
</div>
<div class="body4">
</div>
</div>
</body>
</div>
<aside>
<div class="extrainfo">
</div>
<div class="slideshow">
</div>
</aside>
<footer>
<div class="footer">
</div>
</footer>
</html>
In the elements above, where my <div class=digitalbay>element is located when compiled, the <h1>element nested in the div is too low in the element when compiled. I was wondering if there is a way to make it higher up the div. I already tried changing the margin, but it moves the div up along the page and that doesn't help.
Set a margin on the h1 and it will move up. Example:
h1 {
margin-top: 0.25em;
}
Your .header div has a top: 490px. That is why it is so low.
On other note, here's a bit of feedback on your CSS and HTML.
Never put the <body> tag inside a <div>... it is always supposed to be right after the <head> tag. When the browser parses the HTML, it'll auto correct that for you, but you will have bugs if you start expecting your body tag to be where it is now.
Don't write your CSS as follow div.className. Instead, simply use the class name without the element: .className. This will reduce specificity and make it easier to maintain as it grows. It'll also dramatically reduce your typing.
I don't know what your goal is in the end with this page, but it may be easier to not use position: absolute everywhere. Use position: relative instead.
In HTML, there is a tag called <main>. There can only be one per page, and I use it instead of your <div class="bodydiv">.
You are using <header> and <footer> and putting a <div> inside of it with a class of header and footer... Remove that and put your class directly on the <header> and <footer> tag.
Inside your <div class="bodycontent">, you could use the <section> tag instead of DIVs (if it is semantically correct in your case).
I am trying to place a vote counter inside a div called drop-section. I have managed to create the desired effect, which works perfectly in all cases except when I place the thing inside drop-section. When I do that, the arrows are no longer up against the top and bottom of the container. I can't figure out why the up and down arrows would move like that if they have absolute positioning. I've looked at the drop-section css and can't see any reason why it should be doing that.
Here is the html:
<html>
<body>
<div id="wrapper">
<div id="drop-section">
<div id="menu">
<a class="item" href="drop_index.php">Dead Drop</a>
<a class="item" href="add_topic.php">New Post</a>
<a class="item" href="admin/add_cat.php">New Category</a>
<div id="userbar">Hello, dude.</div>
</div> <!--menu-end-->
<!--vote-box-container up and down elements lose
abs position when vote-box-container is
inside drop section-->
</div> <!--drop-section-end-->
<!--vote-box-container works perfectly here outside the drop section-->
<div id="vote-box-container">
<div id = "vote-box">
<div class="up">
<img src="img/up.png">
</div>
<div class="down">
<img src="img/down.png">
</div>
<div id = "votes">0</div>
</div> <!--vote-box-end-->
</div> <!--vote-box-container-end-->
</div> <!--wrapper-end-->
</body>
</html>
Here is the CSS file:
#wrapper {
width: auto;
}
#menu {
clear: both;
width:88%;
margin: 0 auto;
height:20px;
background: none;
text-align: left;
font-size: .9em;
padding-bottom: 2%;
}
#menu a:hover {
background: #930c0c;
padding: 7px;
color: #fff;
}
.item {
color: #fff;
background-color: #000;
font-family: 'Play', sans-serif;
margin: 7px;
padding: 7px;
text-decoration: none;
}
#userbar {
float: right;
}
#drop-section {
background-image: url(../img/wrapper-bg.png);
background-repeat: repeat-x repeat-y;
border-style: solid;
border-width: 2px;
border-color: #222;
box-shadow: 10px 10px 5px #000;
width: auto;
line-height: 40px;
padding: 10px 25px;
margin-bottom: 1%;
font-family: sans-serif;
overflow: auto;
}
#vote-box-container {
height: 80px;
width: 50px;
float: left;
background: #000;
margin-left: 5px;
position: relative;
}
#vote-box {
height: 80px;
width: 30px;
position: absolute;
left: 10px;
display: table;
padding: 0;
}
#votes {
color: white;
display: table-cell;
vertical-align: middle;
font-weight: bold;
text-align: center;
}
.up {
position: absolute;
top: 0px;
}
.down {
position: absolute;
bottom: 0px;
}
The line-height in your #drop-section css is adding space above and below the arrow images. Try adding line-height:0 to the image containers .up and .down within #drop-section