creating a wrapper of similar to ID card - html

I am struggling with creation of a collection of elements wrapped inside a single one. I made a sketch of what i was trying to create.
The HTML would look like this:
<div class="wrapper-1">
<div class="image"></div>
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
What would be the best way to create such a wrapper?

I would prefer to create two columns as .left-side and .right-side inside the main wrapper and add the contents to the these columns as following:
<div class="wrapper-1">
<div class="left-side">
<div class="image"></div>
</div>
<div class="right-side">
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
</div>
Here is the fully implemented version:
.wrapper-1 {
width: 400px;
height: 100px;
}
.left-side {
float: left;
width: 100px;
height: 100px;
margin-right: 15px;
}
.left-side > .image {
background: url(http://placehold.it/100x100) no-repeat center center;
width: 100px;
height: 100px;
margin-right: 10px;
}
.right-side {
float: left;
width: 285px;
height: 100px;
}
.right-side > .title {
margin: 0;
}
<div class="wrapper-1">
<div class="left-side">
<div class="image"></div>
<img src="" alt="">
</div>
<div class="right-side">
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
</div>

How about this, using flexbox
.wrapper-1 {
display: flex;
}
.wrapper-2 {
display: flex;
flex-direction: column
}
.wrapper-1 .image {
width: 100px;
height: 100px;
background: url(http://placehold.it/100/00f);
margin-right: 10px;
}
<div class="wrapper-1">
<div class="image"></div>
<div class="wrapper-2">
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
</div>
And if you can't change markup, use position: absolute
.wrapper-1 {
padding-left: 110px;
box-sizing: border-box;
}
.wrapper-1 .image {
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 100px;
background: url(http://placehold.it/100/00f);
}
<div class="wrapper-1">
<div class="image"></div>
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>

Here is a complete solution:
HTML:
<div class="wrapper clearfix">
<div class="left">
<img src="img.png">
</div>
<div class="right">
<h3>text</h3>
<p>text text</p>
</div>
</div>
CSS:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
.wrapper {
box-sizing: border-box; /* makes padding go on the inside */
padding: 10px; /* gives interior padding */
width: 1170px; /* whatever width you want the container to be */
margin: 0 auto; /* center it */
background-color: #fff;
}
.left {
width: 20%; /* whatever width you want the left side to be, stick to percentages */
float: left;
}
.left img {
width: 100%;
height: auto;
}
.right {
width: 77%; /* whatever width you want the right side to be, stick to percentages, notice that 77% and 20% dont add up to 100%, this is to account for the small gap inbetween the divs */
float: right;
}
Note: "clearfix" is used when floating things left and right. It prevents the common error where the div collapses in itself when child divs are being floated.
working jsfiddle: here

Related

3 column layout will not fill width of screen

I'm fairly new to html/css and I'm having a problem with a project. I am trying to create a 3 column layout for the bottom portion of my page. What I have right now is close to what I want, but it does not fill the width of the screen. It's all bunched on the left side and does not stretch to match the screen. I went back and followed the example from w3schools and it still didn't work. What am I missing?
HTML
<div class="row">
<div class="column">
<h1>FOLLOW ME ON <br> INSTAGRAM</h1>
</div>
<div class="column">
<h2>contact me</h2>
</div>
<div class="column">
<h1>SUBSCRIBE</h1>
</div>
</div>
CSS
.column {
float: left;
padding: 10px;
height: 300px;
text-align: center;
position: relative;
}
.column.side {
width: 25%;
}
.column.middle {
width: 50%;
}
.row:after {
content: "";
display: table;
clear: both;
}
If you wanna have padding "inside" element, then you need to set box-sizing: border-box.
.row {
width: 100%;
}
.column {
float: left;
padding: 10px;
height: 300px;
text-align: center;
box-sizing: border-box;
}
.column.side {
width: 25%;
}
.column.middle {
width: 50%;
}
<div class="row">
<div class="column side">
<h1>FOLLOW ME ON <br> INSTAGRAM</h1>
</div>
<div class="column middle">
<h2>contact me</h2>
</div>
<div class="column side">
<h1>SUBSCRIBE</h1>
</div>
</div>
Two things:
1.) As #chojnicki wrote in a comment, you need to add the classes defined in the CSS (.side, .middle) to your HTML
2.) To include the padding in the width in order to get a sum of exactly 100% overall (and not more than that to avoid the last column to go under the second one) for the added widths (25% + 50% + 25%), you need to add box-sizing: border-box; to everything (using the *selector):
* {
box-sizing: border-box;
}
.column {
float: left;
padding: 10px;
height: 300px;
text-align: center;
position: relative;
}
.column.side {
width: 25%;
}
.column.middle {
width: 50%;
}
h1 {
font-size: 24px;
}
h2 {
font-size: 18px;
}
<div class="row">
<div class="column side">
<h1>FOLLOW ME ON <br> INSTAGRAM</h1>
</div>
<div class="column middle">
<h2>contact me</h2>
</div>
<div class="column side">
<h1>SUBSCRIBE</h1>
</div>
</div>
Why you don't use .col-xs-4?
and you shouldn't use width to your cols so why do you use col?

How to split web page screen horizontally into 3 equal pieces?

I am trying to split the screen horizontally into 3 equal pieces so I can place separate images into each piece. I have split the screen somewhat equally, but I am running into some issues with a white space and not being split equally.
Here is what I have:
HTML:
<div class="split left">
<div class="centered">
<img src="img_avatar2.png" alt="Avatar woman">
</div>
</div>
<div class="split center">
<div class="centered">
<img src="img_avatar.png" alt="Avatar man">
</div>
</div>
<div class="split right">
<div class="centered">
<img src="golf_course.jpg" alt="Finished Terrain Golf Course">
</div>
</div>
CSS:
/* Split the screen into thirds*/
.split {
height: 100%;
width: 33.3333%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
/* Control the left side */
.left {
left: 0;
background-color: #111;
}
/* Control the right side */
.right {
right: 0;
background-color: red;
}
.center {
right:auto;
left:auto;
background-color:wheat;
}
/* If you want the content centered horizontally and vertically */
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
/* Style the image inside the centered container, if needed */
.centered img {
width: 150px;
border-radius: 50%;
}
Image:
You can use flexbox:
.container {
display: flex;
justify-content: space-between;
}
.container div {
width: 100%;
padding: 5px;
border: 1px solid black;
}
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
You can use grid :
https://css-tricks.com/snippets/css/complete-guide-grid/
in grid you can divide your grid.
*doesn"t work with older browsers like ie11
First, width: available is not valid property. if you want to use all available space you should set width: 100%. anyway, for solving your issue you should use height: 100% also for body and html. see this example:
body, html {
width: 100%;
height: 100%;
margin: 0;
}
.container {
width: 100%;
height: 100%;
}
.leftpane {
width: 33%;
height: 100%;
float: left;
background-color: rosybrown;
border-collapse: collapse;
}
.middlepane {
width: 33%;
height: 100%;
float: left;
background-color: royalblue;
border-collapse: collapse;
}
.rightpane {
width: 33%;
height: 100%;
position: relative;
float: right;
background-color: yellow;
border-collapse: collapse;
}
<div class="container">
<div class="leftpane">
<h1>Test Page</h1></div>
<div class="middlepane">Test Page</div>
<div class="rightpane">
<h1>Test Page</h1></div>
</div>

How to make responsive 3 image which has different scale?

I'm working in Wordpress and i need to insert 3 image in a row.
I'm using default editor because of my client ask that.
Insert the 3 image html for the page and then give this a little CSS with simple CSS plugin :
It's okay, the 3 image appear in a row, which has 170px height, but when i open this in mobile or tablet the scale isn't responsive.
I try to make container which has 170px height, and put the image them but wasn't working. I try to make #media query but that wasn't work.
Anyone can help me ?
I want if these 3 picture is got ca. 170px and being responsive.
* {
box-sizing: border-box;
}
.tanfolyam-kepek {
float: left;
width: 33.33%;
padding: 10px;
height: 170px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
<div class="clearfix">
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1-226x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2-300x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek"src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3-300x243.jpg" alt=""/>
</div>
</div>
Responsive images on a row. Verttical and horizontal alignment. No use of clearfix. Cross browser.
<div class="box-container">
<div class="box">
<a href="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1.jpg">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1-226x300.jpg" alt=""/>
</a>
</div>
<div class="box">
<a href="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2.jpg">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2-300x300.jpg" alt=""/>
</a>
</div>
<div class="box">
<a href="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3.jpg">
<img class="tanfolyam-kepek"src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3-300x243.jpg" alt=""/>
</a>
</div>
</div>
with css
* {
box-sizing: border-box;
}
.box-container {
height: 170px; /* height you asked for */
outline: thin dotted grey; /* this outline for test only */
}
#media (max-width: 575.9px) {
.box-container {
height: ...px; /* for mobile, for example 140px */
}
}
.box {
float: left;
width: 33.333%;
height: 100%;
text-align: center; /* horizontal alignment */
}
.box a {
display: block;
/* 5 lines below for vertical alignment */
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.box img {
max-width: 100%;
height: auto; /* responsive image */
max-height: 170px; /* no overflow */
border: 10px solid #fff; /* border used as padding */
}
you can use bootstrap grid to make your images responsive. all you have to do is
<div class="row">
<div class="col-sm-4 col-xs-4>
//your image here
</div>
<div class="col-sm-4 col-xs-4>
//your image here
</div>
<div class="col-sm-4 col-xs-4>
//your image here
</div>
</div>
And avoid using px to specify the size since it is not responsive. Use vh and vw which stand for viewport height and viewport width respectively
.box{
display: inline-block;
width: 31.3%;
height: 200px;
text-align: center;
border: 1px solid #ddd;
padding: 20px 0;
margin: 10px;
}
.box img{
vertical-align: middle;
display: inline-block;
height: 100%;
max-width: none;
width: auto;
}
You can have something like this for have always tree picters in a row.
* {
box-sizing: border-box;
}
.tanfolyam-kepek {
float: left;
width: 33.33%;
padding: 10px;
height: 170px;
object-fit: cover;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
<div class="clearfix">
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1-226x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2-300x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek"src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3-300x243.jpg" alt=""/>
</div>
</div>

Two boxes, side by side, 50% each, but both are slighty longer and not on same line?

I'm trying to get two side-by-side boxes to take up the entire width of the screen. However, when setting the width at 50%, each of the boxes wants to extend about 10px wider than 50%. What am I doing wrong?
#sides {
padding-top: 40px;
padding-bottom: 40px;
background-color: white;
}
#leftside {
width: 50%;
background-color: grey;
padding: 20px;
margin: 0px;
position: relative;
}
#rightside {
width: 50%;
display: inline-table;
background-color: #018DCA;
float: left;
padding: 20px;
margin-left: 50%;
position: relative;
}
.
.
.
<div id="sides">
<div id="leftside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
<div id="rightside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
</div>
Both sides need to be floated and make sure that you're using box-sizing: border-box; to ensure that the width is 50% regardless of padding and border size.
I realise that your question has already been solved, but another option to TylerH's solution would be to use flex. Like so:
#sides {
display:flex;
padding: 40px 0px;
background-color: white;
}
.side {
flex:1;
padding: 20px;
margin: 0;
}
#left{background-color: grey;}
#right{background-color: #018DCA;}
<div id="sides">
<div class="side" id="left">
<h1>text</h1>
<h2>text</h2>
</div>
<div class="side" id="right">
<h1>text</h1>
<h2>text</h2>
</div>
</div>
As TylerH rightly pointed out, this does require more modern browsers. Take a look at this website for more information on compatibility.
You don't need to use float (in fact it's not really the right tool for overall document layout; it's more for breaking up text with images without destroying the document flow).
You can achieve this with less CSS by using display: inline-block; and commenting out the white-space between your left and right <div>s. JSFiddle
html, body {
margin: 0;
}
#sides {
padding-top: 40px;
padding-bottom: 40px;
background-color: white;
}
#leftside {
width: 50%;
background-color: grey;
padding: 20px 0;
display: inline-block;
}
#rightside {
width: 50%;
display: inline-block;
background-color: #018DCA;
padding: 20px 0;
}
<div id="sides">
<div id="leftside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div><!--
--><div id="rightside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
</div>
Use display:inline-blockAdd font-size:0 to the parent div,this must do. Also try adding vertical-align:top to right div
#sides {
padding-top: 40px;
padding-bottom: 40px;
background-color: white;
}
#leftside {
width: 47%;
background-color: grey;
float: left;
padding:5px;
}
#rightside {
width: 47%;
background-color: #018DCA;
float: right;
padding:5px;
}
<div id="sides">
<div id="leftside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
<div id="rightside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
</div>

Using clearfix to cancel floating

During learning CSS I tried to make the exact example as you can see on the link below using clearfix (sorry for non-English text, but I have no other)
http://htmlbook.ru/files/images/layout2/3-41.png
I need to make it using float and clearfix hack
My code is:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Learning float</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="float.css">
</head>
<div class="col1 clearfix"><h3>Menu</h3>
<p>Best photo</p>
<p>By ages</p>
<p>Rate</p>
<p>By comments</p>
</div>
<div class="col2">
<div class="photo">
<p><img src="http://churchs.kiev.ua/images/stories/Hrams/Myzej/Sofia_kievsk_1.jpg" alt="" /></p>
<p class="caption">Софийский собор</p>
</div>
<div class="photo clearfix">
<p><img src="http://rybinsk.go2all.ru/imgs/92/1/85222.jpg" alt="" /></p>
<p class="caption">Польский костёл</p>
</div>
<p>This text should be below photos</p>
</div>
<p>This text should go below the columns</p>
<div class="footer">Подвал</div>
</body>
</html>
CSS
.col1 {
background-color: #BDBDBD;
width: 250px;
margin-right: 10px;
float: left;
}
.col2 {
background-color: #A9F5F2;
float: left;
width: 500px;
}
.photo {
float: left;
margin-right: 10px;
width: 170px;
}
img {
width: 150px;
height: 150px;
}
.clearfix:after {
content: " ";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
background-color: green;
text-align: center;
}
What's wrong with using of clearfix.
Will appreciate any answer!
the clearfix:after 'method' is used to wrap floatting child when the container is not in position absolute or fixed, floatting or in display:inline-block,inline-table or table.
In your case, the element you want to clear stands after a floatting element, you only need to clear them. both, left or right.
http://www.w3.org/wiki/CSS/Properties/clear
.col1 {
background-color: #BDBDBD;
width: 250px;
margin-right: 10px;
float: left;
}
.col2 {
background-color: #A9F5F2;
float: left;
width: 500px;
}
.photo {
float: left;
margin-right: 10px;
width: 170px;
}
img {
width: 150px;
height: 150px;
}
.clearfix {
clear: both;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: green;
text-align: center;
}
/* add some space to clear the footer */
body {
padding-bottom:2em;/* average height of current footer: tune it if needed */
min-width:800px;
}
<div class="col1 "><h3>Menu</h3>
<p>Best photo</p>
<p>By ages</p>
<p>Rate</p>
<p>By comments</p>
</div>
<div class="col2">
<div class="photo">
<p><img src="http://churchs.kiev.ua/images/stories/Hrams/Myzej/Sofia_kievsk_1.jpg" alt="" /></p>
<p class="caption">Софийский собор</p>
</div>
<div class="photo clearfix">
<p><img src="http://rybinsk.go2all.ru/imgs/92/1/85222.jpg" alt="" /></p>
<p class="caption">Польский костёл</p>
</div>
<p class="clearfix">This text should be below photos</p>
</div>
<p class="clearfix">This text should go below the columns</p>
<div class="footer">Подвал</div>