Trying to create 3 specifically laid out divs - html

I am trying to create some specific divs to hold content and I'm stuck trying to just create them using colors.
I went ahead and uploaded a crude idea of what I'm trying to create so I could show you guys.
http://imgur.com/lPJLuqE
I can get the first large square to show but not the other ones, can anyone shed some insight?
#row-one {
padding-top: 1em;
}
#left-block {
float: left;
width: 45%;
height: 25em;
background-color: black;
}
#right-block {
float: right;
width: 45%;
}
#block-one {
width: 100%;
height: 12em
background-color: black;
vertical-align: top;
}
<div id="row-one">
<div id="left-block">
<!--PLACEHOLDER-->
</div>
<div id="right block">
<div id="block-one"></div>
<div id="block-two"></div>
</div>
</div>

You were missing the semicolon ; after height: 12em and there were no styles specified for #block-two. Also, you specified the styles for the right-block div but were also missing the - in <div id="right block">.
#row-one {
padding-top: 1em;
}
#left-block {
float: left;
width: 45%;
height: 25em;
background-color: black;
}
#right-block {
float: right;
width: 45%;
}
#block-one, #block-two {
width: 100%;
height: 12em;
background-color: black;
vertical-align: top;
margin-bottom: 10px;
}
<div id="row-one">
<div id="left-block">
<!--PLACEHOLDER-->
</div>
<div id="right-block">
<div id="block-one"></div>
<div id="block-two"></div>
</div>
</div>

Related

Images and text do not align up properly in CSS for template

This is the portion of my template, CSS is inline for demo purposes only:
.header {
background-color: #333;
color: #FFF;
padding: 30px;
}
.content {
width: 750px;
}
.mc-info {
height: auto;
border: 2px solid;
width: 800px;
height: auto;
margin-top: 20px;
margin-bottom: 20px;
}
.mc-info-image {
width: 240px;
}
.mc-info-image img {
margin-right: 29px;
height: 340px;
float: left;
}
.description {
font-size: 16px;
float: right;
}
.vehiname {
font-size: 18px;
color: green;
}
.price {
color: red;
}
footer {
color: #333;
background-color: blue;
}
It's been causing problems with getting text and images to align properly, as images and DIV overrun, as seen at https://jsfiddle.net/r7podhq6/- the div does not resize with the content, even though a standard image is set.
I'm trying to do something like this for my layout, although with the bordered DIV's I'm using and keeping class mc-info at the width set.
Should I convert to flex or grid for this? If not, how could I improve this?
My problem is getting text and images to align for this basic template for a car dealer platform.
Looking for help and constructive criticism./
You should really consider learning CSS flex and grid. using float to align divs is not the best practice in 2021.
I have added display: flex to .mc-info and removed all the float properties and max-width:100% to auto scale.
.mc-info {
display: flex;
}
.mc-info-image {
max-width: 800px;
}
img {
max-width: 100%;
}
.info-wrapper {
padding-left: 20px;
}
And lastly wrapped the car information in <div class="info-wrapper"> </div>
Final code
<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<head>
<body>
<title>YourLeisure Motorhomes & Caravans</title>
<style>
.header {
background-color: #333;
color: #FFF;
padding: 30px;
}
.content {
width: 750px;
}
.mc-info {
display: flex;
height: auto;
border: 2px solid;
max-width: 800px;
height: auto;
margin-top: 20px;
margin-bottom: 20px;
}
.mc-info-image {
max-width: 800px;
}
.mc-info-image img {
margin-right: 29px;
height: 340px;
}
.description {
font-size: 16px;
float: right;
}
.vehiname {
font-size: 18px;
color: green;
}
.price {
color: red;
}
footer {
color: #333;
background-color: blue;
}
img {
max-width: 100%;
}
.info-wrapper {
padding-left: 20px;
}
</style>
</head>
<body>
<div class="header">
<h1>YOURLEISURE MOTORHOMES</h1>
<h2>49 High Street, Northtown</h2>
</div>
<div class="content">
<div class="mc-info">
<div class="mc-info-image">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/VW_T5_California_front_20071215.jpg/800px-VW_T5_California_front_20071215.jpg">
</div>
<div class="info-wrapper">
<div class="vehiname">
<h2>VOLKSWAGEN CALIFORNIA 2.0 BITDI 180</h2>
</div>
<div class="price">
<h2>£45,000</h2>
</div>
<div class="description">
This example has all the equipment you could want
</div>
</div>
</div>
<div class="mc-info">
<div class="mc-info-image">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Ford_Transit_FT_130_Camper_%2818418440689%29.jpg/1024px-Ford_Transit_FT_130_Camper_%2818418440689%29.jpg">
</div>
<div class="info-wrapper">
<div class="vehiname">
<h2>FORD TRANSIT CAMPERVAN 2.0</h2>
</div>
<div class="price">
<h2>£1,000</h2>
</div>
<div class="description">
red/white
</div>
</div>
</div>
<footer>
Content to come
</footer>
</body>
</html>
The answer given by Josh answers your question.
Moreover, i'd recommend you to use flexbox/grid over float. They have a lot of properties that could be really helpful in making a responsive design.

Large empty space at the bottom of the scroll

I want to have divs (.ra) whose content is:
a fixed .header
a .rcs div that contains a few or many .box divs
As one can have many of these .box divs, we need a scroll. The scroll leaves the header fixed.
It seems to be Ok, BUT I have a large empty space at the bottom of the scroll. I don't understand why.
Full code : https://jsfiddle.net/yannn/n4dk2znh/1/
HTML :
<div class="ra">
<div class="header">
<div class="ra_name">Martin, John William Harry Slobodan Junior</div>
</div>
<div class="rcs" id="ra1_rcs">
<div class="box">titre</div>
<div class="box">titre</div>
...
<div class="box">titre</div>
<div class="box">titre</div>
<div class="box">titre</div>
</div>
</div>
CSS :
.ra {
width: 28%;
height: 200px;
float: left;
border-style: solid;
margin-left: 1%;
overflow: auto;
}
.header {
background-color: white;
color: black;
height: 50px;
width: 26%;
position: absolute;
}
.rcs {
margin-top: 50px;
margin-bottom: : -50px;
height: 150px;
}
.box {
width: 60px;
height: 40px;
float: left;
background-color: black;
border-radius: 3px;
font-size:80%;
color: white;
margin: 1px;
padding: 1px;
text-align: left;
text-overflow: ellipsis;
}
There's text there:
try adding:
.box {
overflow: hidden;
}

Confused on Horizontal Card

I've been really struggling making a horizontal card. I don't want to use flexbox, because I'm not very experienced with it. I want something to look like this:
I've already tried making the card and I'm able to get it to look similar although it doesn't adjust correctly to the text inputted in it.
I would recommend you learn some basic CSS in order to do simple layouts. Anyway here's a simple draft:
.container {
margin: auto;
width: 650px;
height: 150px;
padding: 0px;
text-align: center;
}
.leftbox,
.rightbox {
display: inline-block;
width: 200px;
height: 150px;
vertical-align: middle;
text-align: left
}
.leftbox {}
.rightbox {
border: 2px dashed pink;
background-color: pink;
width: 300px;
height: 146px;
}
.header {
margin: 10px 5px;
}
.data>p {
margin: 5px;
margin-left: 8px;
}
.leftbox {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/4/45/A_small_cup_of_coffee.JPG');
background-size: contain;
background-repeat: no-repeat;
}
<div class="container">
<div class="leftbox">
</div><div class="rightbox">
<div class="header">CARAMEL MACCHIATO</div>
<div class="data">
<p>SIZE</p>
<p>TOPPINGS</p>
<p>DELIVEERY</p>
<p>AMOUNT</p>
</div>
</div>
</div>

Center text between two divs

I'm trying to center a text between two floating divs. The problem is, that the text does not center properly, even though I followed every step I could find online.
Here's the code I used to try to accomplish my goal:
.EditingApp-head {
background-color: #222;
width: 100%;
overflow: auto;
}
.EditingApp-head-logo {
float: left;
overflow: auto;
width: 10%;
}
.EditingApp-head-logo-image {
height: 40px;
margin-top: 4px;
float: left;
clear: none;
}
.EditingApp-head-logo-text {
float: left;
margin-left: 5px;
color: white;
}
.EditingApp-head-title {
text-align: center;
color: white;
margin-left: auto;
margin-right: auto;
}
.EditingApp-head-end {
float: right;
width: 10%;
}
<div className="EditingApp">
<div className="EditingApp-head">
<div className="EditingApp-head-logo">
<img src={logo} className="EditingApp-head-logo-image" alt="logo" />
<p className="EditingApp-head-logo-text">SyncPad</p>
</div>
<div className="EditingApp-head-end" />
<p className="EditingApp-head-title">Title</p>
</div>
<div>
<p style={{textAlign: "center"}}>center</p>
</div>
</div>
The text 'Title' centers slightly to the right, so it somehow ignores the right div.
Does anyone see the problem?
Put <center></center> around your paragraph and if i understand well it will help.
After some playing around, I got it to work. Thanks to all who tried to help me. Here's the final CSS:
.EditingApp-head {
background-color: #222;
width: 100%;
display: flex;
flex-flow: row wrap;
}
.EditingApp-head-logo {
float: left;
overflow: auto;
width: 10%;
}
.EditingApp-head-logo-image {
height: 40px;
margin-top: 4px;
float: left;
}
.EditingApp-head-logo-text {
margin-left: 5px;
color: white;
}
.EditingApp-head-title {
text-align: center;
color: white;
margin-left: auto;
margin-right: auto;
}
.EditingApp-head-end {
float: right;
width: 10%;
}
It's because of the floated content. The inline content in your p is going to wrap around the floated content, which will offset it depending on the width of the floated content. To center the title p, apply margin: 0 10% so that the inline content in the p isn't affected by the surrounding floated content.
.EditingApp-head {
background-color: #222;
width: 100%;
overflow: auto;
}
.EditingApp-head-logo {
float: left;
overflow: auto;
width: 10%;
}
.EditingApp-head-logo-image {
height: 40px;
margin-top: 4px;
float: left;
clear: none;
}
.EditingApp-head-logo-text {
float: left;
margin-left: 5px;
color: white;
}
.EditingApp-head-title {
text-align: center;
color: white;
width: 80%;
float: left;
}
<div class="EditingApp">
<div class="EditingApp-head">
<div class="EditingApp-head-logo">
<img src={logo} class="EditingApp-head-logo-image" alt="logo" />
<p class="EditingApp-head-logo-text">SyncPad</p>
</div>
<p class="EditingApp-head-title">Title</p>
</div>
</div>

Specific order of inline-block elements on mobile and desktop devices

I'm trying to add two square ads to the right of the image on the web-site. The idea is to make this responsive like this:
http://s9.postimg.org/pdecyqi8f/div.png
Is this possible to achieve using CSS?
I use inline-block to position ads to the right and max-width: 100% to scale the image. I need the support of IE 9+ and mobile browsers.
I tried different approaches, don't even know which code example to show. It is relatively easy to position ads to the right of the image using inline-block:
div{
border: 2px solid;
}
#img,#container{
display: inline-block;
vertical-align: middle;
}
#ad1, #ad2{
width: 30px;
height: 30px;
color: red;
}
#img{
width: 100px;
height: 150px;
max-width: 100%;
color: purple;
}
<div id="img"> </div>
<div id="container">
<div id="ad1">ad1</div>
<div id="ad2">ad2</div>
</div>
http://jsfiddle.net/w7zfj1ju/
Yet in this case I won't get desired view on narrow screens. Also, since max-width: 100%; is used for #img this div would cover #ad1 and #ad2 on narrow screens.
To achieve desired mobile view I had to change HTML to the following:
div{
border: 2px solid;
display: inline-block;
}
#ad1, #ad2{
width: 30px;
height: 30px;
color: red;
vertical-align: top;
}
#img{
width: 100px;
height: 150px;
max-width: 100%;
color: purple;
}
<div id="ad1">ad1</div>
<div id="img"> </div>
<div id="ad2">ad2</div>
http://jsfiddle.net/gxnqo8da/
In this case I didn't really know how to position #ad1 to the right of the #img. I gave a try to absolute positioning, it did not work. Flex also seemed not to be an option due to compatibility reasons.
I also tried to use direction:rtl; like this:
div{
border: 2px solid;
display: inline-block;
}
#container{
direction:rtl;
border: 0px;
}
#ad1, #ad2{
width: 30px;
height: 30px;
color: red;
vertical-align: top;
}
#img{
width: 100px;
height: 150px;
max-width: 100%;
color: purple;
}
<div id="container">
<div id="ad1">ad1</div>
<div id="img"> </div>
<div id="ad2">ad2</div>
</div>
http://jsfiddle.net/n1mo76bv/
and this:
div{
border: 2px solid;
text-align: left;
}
#container{
direction:rtl;
border: 0px;
}
#ad1, #ad2{
width: 30px;
height: 30px;
color: red;
vertical-align: top;
}
#img{
width: 100px;
height: 150px;
max-width: 100%;
color: purple;
display: inline-block;
}
#ad1{
display: inline-block;
}
<div id="container">
<div id="ad1">ad1</div>
<div id="img"> </div>
</div>
<div id="ad2">ad2</div>
http://jsfiddle.net/w7sknehL/
didn't help much since I could not position #ad2.
So, I don't ask to write any code. I'm just desperate for an advice.
If you don't need to support Android 2 and Opera Mini you can still use flexbox to achieve this result via media query. Example below:
.img {
width: 100%;
max-width: 100%;
height: 300px;
background: blue;
}
.ad {
background: red;
width: 100px;
height: 100px;
}
#media (min-width : 801px) {
.wrapper {
padding-right: 110px;
}
.img {
float: left;
}
.ad {
clear: right;
float: right;
margin-right: -110px;
margin-bottom: 10px;
}
}
#media (max-width : 800px) {
.wrapper {
display: flex;
flex-direction: column;
}
.img {
order: 2;
margin: 10px auto;
}
.ad {
margin: 0 auto;
}
.ad1 {
order: 1;
}
.ad2 {
order: 3;
}
}
<div class="wrapper">
<div class="img"> </div>
<div class="ad ad1">ad1</div>
<div class="ad ad2">ad2</div>
</div>
Also:
I didn't use browser prefixes for flexbox, so it will not work in all browsers. Add prefixes or use autoprefixer to make it work there.
Fix media query parameters for you needs, I only inserted width 800 as example value, real query to detect mobile will differ.