So I've read about a hundred questions and answers on this and clearly I'm doing something wrong here... (Ignore the seriousness of the text, I'm making a loan calculator as an ability test)
I want my image, next to my text on the same line, this is how it currently looks
Here is my relevant code
.topContainer {
background-color: #0f3759;
overflow: hidden;
padding: 20px;
width: 100%;
}
.topContainer p {
width: 60%;
float: left;
}
.topContainer img {
margin-left: 35%;
width: 40%;
}
<div class="topContainer">
<h2 id="headline">Personal Loans</h2>
<p id="headlineText">18.9% APR Representative on loans between £100,000 to £1,000,000 over 1 to 10 years.</p>
<p id="headlineDesc">Other loan amounts and terms are available, at different rates. Our loans start at £100,000.
<br><br>Thinking about a big bet or buying an asset? Need some extra cash to pay off some debts? A Nub Bank personal loan can help make it happen.
<br><br>Lending and rate are subject to our assessment of your circumstances. Available to UK residents aged 18 and over.</p>
<img id="cash" src="https://cdn1.iconfinder.com/data/icons/flat-world-currency-1/432/Flat_Currency_Pound-512.png" width="300" height="300">
</div>
As PaulieD suggested, removing your image margin puts it all on one line.
Your problem is that you are asking for the text to take up 60% of the width, the image to take up 40% of the width, and the image margin to take up a further 35% of the width. Obviously this takes up more than 100% of the page so it shunts the extra stuff below. Here's what it looks like without the margin:
.topContainer {
background-color: #0f3759;
overflow: hidden;
padding: 20px;
width: 100%;
}
.topContainer p {
width: 60%;
float: left;
}
.topContainer img {
width: 40%;
}
<div class="topContainer">
<h2 id="headline">Personal Loans</h2>
<p id="headlineText">18.9% APR Representative on loans between £100,000 to £1,000,000 over 1 to 10 years.</p>
<p id="headlineDesc">Other loan amounts and terms are available, at different rates. Our loans start at £100,000.
<br><br>Thinking about a big bet or buying an asset? Need some extra cash to pay off some debts? A Nub Bank personal loan can help make it happen.
<br><br>Lending and rate are subject to our assessment of your circumstances. Available to UK residents aged 18 and over.</p>
<img id="cash" src="https://cdn1.iconfinder.com/data/icons/flat-world-currency-1/432/Flat_Currency_Pound-512.png" width="300" height="300">
</div>
Just as a "best practices with modern HTML/CSS" thing, an easier way to add gaps between elements is to use something like flex or grid. Below is an example using grid, with a gap in between the elements:
.topContainer {
background-color: #0f3759;
overflow: hidden;
padding: 20px;
width: 100%;
}
.mainBody {
display: grid;
grid-template-columns: 3fr 2fr;
grid-column-gap: 50px;
}
<div class="topContainer">
<h2 id="headline">Personal Loans</h2>
<div class="mainBody">
<div class="text">
<p id="headlineText">18.9% APR Representative on loans between £100,000 to £1,000,000 over 1 to 10 years.</p>
<p id="headlineDesc">Other loan amounts and terms are available, at different rates. Our loans start at £100,000.
<br><br>Thinking about a big bet or buying an asset? Need some extra cash to pay off some debts? A Nub Bank personal loan can help make it happen.
<br><br>Lending and rate are subject to our assessment of your circumstances. Available to UK residents aged 18 and over.</p>
</div>
<img id="cash" src="https://cdn1.iconfinder.com/data/icons/flat-world-currency-1/432/Flat_Currency_Pound-512.png" width="300" height="300">
</div>
Use bootstrap its very easy and save you from lot of css coding...
...but if you dont want to use I would say use flex box for it. :)
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
You can see my solution for you here
.topContainer { display: flex; }
try this:
.topContainer {
background-color: #0f3759;
overflow: hidden;
padding: 20px;
width: 100%;
}
.contain{
display: flex;
}
.topContainer .text_block {
float: left;
}
.topContainer img {
width: 40%;
height: auto;
float: right;
}
<div class="topContainer">
<h2 id="headline">Personal Loans</h2>
<div class="contain">
<div class="text_block">
<p id="headlineText">18.9% APR Representative on loans between £100,000 to £1,000,000 over 1 to 10 years.</p>
<p id="headlineDesc">Other loan amounts and terms are available, at different rates. Our loans start at £100,000.
<br><br>Thinking about a big bet or buying an asset? Need some extra cash to pay off some debts? A Nub Bank personal loan can help make it happen.
<br><br>Lending and rate are subject to our assessment of your circumstances. Available to UK residents aged 18 and over.</p>
</div>
<img id="cash" src="https://cdn1.iconfinder.com/data/icons/flat-world-currency-1/432/Flat_Currency_Pound-512.png" width="300" height="300">
</div>
</div>
I've put the two paragraph tags in a container div, then utilised flex box to put both the paragraph container and the image container on the same line - you can then set any padding or margin on their. As you've set the image width to a percentage, I've also set it's height to auto to allow it to keep it's ratio.
Related
What am i doing wrong with this? I'm trying to centre align the header image. It keeps aligning left. I'm also trying to get the profile pic below the header image to float over it so that about 30% of the bottom half is hanging off. I'm a beginner...
<html>
<head>
<meta charset="UTF-8">
<meta name="toy-story"
content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="Toy Story 4 style.css">
<img id="#header" src="toy story 4.jpg">
<img id="#profile" src="toy story profile pic.jpg">
<title> Toy Story 4</title>
</head>
body {
background-color : rgb(14, 173, 225);
}
h1,h2,h3 {
color : rgb(161, 29, 0);
margin : 0px auto;
}
h1:hover, h2:hover, h3:hover, a:hover {
color : rgb(255, 0, 0);
}
.header {
display : block;
width : 100%;
margin-left : auto;
margin-right : auto;
margin-top : 0px;
}
.profile {
display : block;
margin-left : auto;
margin-right : auto;
width : 500px;
margin-top : 10px;
}
img {
display : block;
margin : 0 px auto;
}
<h1>Toy Story 4</h1>
<img src="" controls width="500">
<div>
<h2>Synopsis</h2>
<p>Woody, Buzz Lightyear and the rest of the gang embark on a road trip with Bonnie and a new toy named Forky. The adventurous journey turns into an unexpected reunion as Woody's slight detour leads him to his long-lost friend Bo Peep. As Woody and Bo
discuss the old days, they soon start to realize that they're worlds apart when it comes to what they want from life as a toy.</p>
</div>
<div>
<h2>Characters</h2>
<h3>Woody</h3>
<p>Played by Tom Hanks</p>
<p>Woody is a smart, determined, and passionate man, and would do anything for his nearest and dearest friends. He considers his friends as family and he tries his best to keep them together at all times. Yet, he is a flawed character.</p>
</div>
<h3>Buzz Lightyear</h3>
<p>Played by Tim Allen</p>
<p>Buzz is a toy from a science fiction franchise of the same name. In his fictional backstory, Buzz is a universal space ranger from the Intergalactic Alliance and the captain of the Alliance's team. Buzz is trained in several forms of martial arts and
is a highly skilled warrior in hand to hand combat.</p>
<h3>Forky</h3>
<p>Played by Tony Hale</p>
<p>Forky is a white plastic spork outfitted with a pair of different sized googly eyes; a mouth made out of blue plasticine; two halves of a popsicle stick for feet, stuck on with modelling clay; arms and hands made out of a red pipe cleaner; and a unibrow
made out of red plasticine.</p>
<h3>Bo Peep</h3>
<p>Played by Annie Potts</p>
<p>"Little" Bo Peep is a character in the Toy Story franchise and a main character of the fourth film. She is a porcelain shepherdess figurine and Sheriff Woody's girlfriend in the films. Bo Peep and her sheep were originally adornments of Molly Davis' bedside
lamp.</p>
<p>Top five countries where Toy Story 4 grossed the highest during opening week:</p>
<ol>
<li>United States</li>
<li>Canada</li>
<li>Brazil</li>
<li>India</li>
<li>Nigeria</li>
</ol>
<!-- First Fieldset -->
<fieldset>
<legend>Comments</legend>
<div>
<label for="comments">Leave a comment!</label>
<input type="text" id="comments" name="comments" required />
</div>
</fieldset>
I'm trying to get the image of the header to centre align. I googled videos and it still keeps aligning left
Your images are not working properly for two reasons
1. You've added a hashtag in the id names
<img id="#header" src="toy story 4.jpg">
<img id="#profile" src="toy story profile pic.jpg">
Remove the hashtags from the html so it's id="header" and id="profile"
2. Your CSS has the elements listed as classes, instead of id.
.header { ... }
.profile { ... }
In your CSS, change the elements to #header { ... } and #profile { ... }
<img id="#header" src="toy story 4.jpg">
<img id="#profile" src="toy story profile pic.jpg">
.header {
display : block;
width : 100%;
margin-left : auto;
margin-right : auto;
margin-top : 0px;
}
.profile {
display : block;
margin-left : auto;
margin-right : auto;
width : 500px;
margin-top : 10px;
}
you have to use like this because "." for class and "#"for id
#header {
display : block;
width : 100%;
margin-left : auto;
margin-right : auto;
margin-top : 0px;
}
#profile {
display : block;
margin-left : auto;
margin-right : auto;
width : 500px;
margin-top : 10px;
}
I need to create an information section that includes an image and content next to it.
It should look like this:
I have already written a little bit of code, but it does not seem to be the best solution: everything works fine, but code is not graceful.
Please, have a look:
/* Simple reset */
img {
display: block;
max-width: 100%;
}
body {
background-color: black;
}
.information {
display: flex;
gap: clamp(5rem, 10vw, 8rem);
}
.information > * {
width: 50%; /* Using the 'width' property. */
}
.information-content {
align-self: center;
color: white;
}
.information-image {
align-self: flex-start;
object-fit: cover;
aspect-ratio: 1 / 1.10;
border-radius: 5px;
}
<section>
<div class="container">
<div class="information">
<img
class="information-image"
alt="Products for companies & Startups"
src="https://s3-alpha-sig.figma.com/img/6630/3672/40959a0086f9fbb8418c0829b277dd93?Expires=1670198400&Signature=gpQ5NqRXp9omRHkjCl718I9WPLqfx4xPKp1CQSMKbEnRCU7izmQIXkcn6zI6Z17p8Q7Li-wBAXb3P2Jg9qEuJauFeKqErbl4jgW950K35-LeX394hN7fJ7UEPmkgGSqB-drY1QdU7NZVV4QKTrZ0QBuw47xVBPOOfJMQO8NPOpZkx43UbbkS1yGgnxN5tELyriz9e8pH6pXO8AnJx7zvGz4mm3InyHOySUcb3ibVPa9XKJ8fyxPnkBeVoYFvwpiVddEs7uVNqCkCRuN2dJIIQg78FB-6TYX13nQ~NxvhG2059ks2q52a9p0N-DSmSYE-Yt-jedbJ1fEt3cZVnIfzUw__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
/>
<div class="information-content">
<h2>
My main goal is to keep my customers satisfied.
</h2>
<p>
Even with skills that are primarily mental, such as
computer programming or speaking a foreign language.
</p>
<p>
Even with skills that are primarily mental, such as
computer programming or speaking a foreign language.
</p>
</div>
</div>
</div>
</section>
My concern is the width property set on each child of my flex parent. As far as I know, using width inside flexbox is not the best idea? However, when I try to use the flex-basis property, everything breaks.
Note: I cannot use display: grid because the image can be after the content - with grid I will have to change the order and the code will become more complicated.
I'm trying to get a background color for class="imgd" but nothing shows up.
.portrait {
border: #C7C7C7 solid 1px;
}
.circular--square {
border-radius: 50%;
padding-right: 10%;
padding-bottom: 10%;
}
.imgd {
text-align: center;
border: solid px G7G7G7;
background-color: gggggg;
}
<div class="lgcontainer">
<h1>Aristotle Onassis</h1>
<h2>1906 - 1975</h2>
<h3>One of the richest people in the 20th century</h3>
<div class="description">Aristotle Socrates Onassis (Aristotelis Onasis; 20th January 1906 - 15th March 1975), [1] commonly called Ari or Aristo Onassis, was a Greek-Argentine shipping magnate, who amassed the world's largest privately owned shipping fleet and was one of the world's richest and most famous men.</div>
<div class="portrait">
<img class="circular--square" src="https://upload.wikimedia.org/wikipedia/commons/4/46/Aristotle_Onassis.JPG" alt="Rich Boi">
<span class="imgd">The most well-known portrait of Onassis.</span>
</div>
<br>
<h4><strong>The following list is a timeline of Onassis Life</strong></h4>
</div>
According to the pictures you are missing a number or pixels, also color format is incorrect, it looks similar to HEX but # is missing at the beginning and G is not a valid hex digit:
border: solid [number] px [#][AAAAAA]
I saw your HTML file it is not linked with CSS
link your .CSS file in HTML, then you are go
you can include this and change the href as per your CSS file name
keep the below code after
We have a two column layout where image is on one side with text on the other. We want the image to be the same height as the content. We are having an issue when the text column reaches a certain height, then it will not make the image go full height. Although not added, this .flex__wrapper is surrounded by an outer <div class="container"> element so that we can handle larger screens where we may want to limit the width.
How can we achieve this? Our current solution uses flexbox, but we have also tried the following solutions but none resolves the problem.
Goal:
As the right column containing the text increases in height, i want the image to also take up the same amount of height.
Solutions we tried, but they didn't work. They seem to work well with text and text, but not text and image.
Make two columns the same height (using Flexbox)
Keep columns with same height
(using Tables)
.flex__wrapper {
display: flex;
position: relative;
align-items: center;
background-color: #eee;
}
[class*=col--] {
box-sizing: border-box;
}
.col--m-s-12 {
width: 100%;
}
.col--t-s-6 {
width: 50%;
}
img {
display: block;
height: auto;
}
<div class="flex__wrapper">
<div class="col--m-s-12 col--t-s-6">
<img src="https://thumb1.shutterstock.com/display_pic_with_logo/422872/1024946740/stock-photo-large-group-of-business-people-standing-with-folded-hands-togeth-1024946740.jpg">
</div>
<div class="col--m-s-12 col--t-s-6">
<div>Distinctively engineer timely benefits before leading-edge technology. </div>
<div>Quickly brand strategic web-readiness whereas global relationships. Credibly underwhelm interdependent e-markets via plug-and-play value. Professionally maximize emerging partnerships rather than equity invested information. Objectively morph intuitive applications rather than multimedia based best practices. Competently innovate covalent infrastructures after premium relationships.
Globally conceptualize holistic sources and leveraged synergy. Distinctively maintain stand-alone content without market-driven niche markets. Completely orchestrate seamless channels after high-quality synergy. Rapidiously scale cutting-edge niche markets with reliable innovation. Intrinsicly productize multifunctional manufactured products without high standards in e-tailers.</div>
</div>
</div>
Current issue:
Additional issue:
Desired result:
You need to apply max-width:100% on your image. Now even after applying the following style your image will not take whole place in full screen(1600*900px), this is happening because your original image is of less size(450*274) and the container where your are trying to fit is 792px approx. Try using a bigger image then it will be solved.
.flex__wrapper {
display: flex;
position: relative;
background-color: #eee;
flex-wrap: wrap;
}
#media screen and (min-width: 1024px) {
.flex__wrapper {
max-width: 56%;
}
}
[class*=col--] {
box-sizing: border-box;
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.col--m-s-12 {
width: 100%;
}
.col--t-s-6 {
width: 50%;
}
img {
height: 100%;
width: 100%;
object-fit:cover;
}
<div class="flex__wrapper">
<div class="col--m-s-12 col--t-s-6" style="border:solid 1px;">
<img src="https://thumb1.shutterstock.com/display_pic_with_logo/422872/1024946740/stock-photo-large-group-of-business-people-standing-with-folded-hands-togeth-1024946740.jpg" class="img-fluid">
</div>
<div class="col--m-s-12 col--t-s-6">
<div>Distinctively engineer timely benefits before leading-edge technology. </div>
<div>Quickly brand strategic web-readiness whereas global relationships. Credibly underwhelm interdependent e-markets via plug-and-play value. Professionally maximize emerging partnerships rather than equity invested information. Objectively morph intuitive
applications rather than multimedia based best practices. Competently innovate covalent infrastructures after premium relationships. Globally conceptualize holistic sources and leveraged synergy. Distinctively maintain stand-alone content without
market-driven niche markets. Completely orchestrate seamless channels after high-quality synergy. Rapidiously scale cutting-edge niche markets with reliable innovation. Intrinsicly productize multifunctional manufactured products without high standards
in e-tailers.</div>
</div>
</div>
html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test3</title>
<link rel="stylesheet" type="text/css" href="test.css">
</head>
<body>
<main class="holder">
<section class="left-div">
<h1 class="flat-invisible">test-3</h1>
<img src="https://thumb1.shutterstock.com/display_pic_with_logo/422872/1024946740/stock-photo-large-group-of-business-people-standing-with-folded-hands-togeth-1024946740.jpg" alt="stock photo large group of business people standing with folded hands together">
</section>
<aside class="right-div">
<div>Distinctively engineer timely benefits before leading-edge technology. </div>
<div>Quickly brand strategic web-readiness whereas global relationships. Credibly underwhelm interdependent e-markets via plug-and-play value. Professionally maximize emerging partnerships rather than equity invested information. Objectively morph intuitive applications rather than multimedia based best practices. Competently innovate covalent infrastructures after premium relationships.
Globally conceptualize holistic sources and leveraged synergy. Distinctively maintain stand-alone content without market-driven niche markets. Completely orchestrate seamless channels after high-quality synergy. Rapidiously scale cutting-edge niche markets with reliable innovation. Intrinsicly productize multifunctional manufactured products without high standards in e-tailers.</div>
</aside>
</main>
</body>
</html>
css:
.left-div {
float: left;
grid-area: section;
max-width: 100%;
max-height: 100%;
}
.flat-invisible {
margin: 0em;
padding: 0em;
line-height: 0em;
height: 0em;
visibility: hidden;
}
.left-div > img {
object-fit: cover;
top: 0px;
height: 100%;
max-width: 120%;
}
.right-div {
padding-top: 2em;
padding-bottom: 2em;
padding-left: 150px;
max-width: 50%;
grid-area: aside;
max-height: 100%;
}
.holder {
max-width: 90%;
background-color: #eee;
display: grid;
grid-template:
'section aside';
}
I'm still in the process of mastering css.
So I've made my portfolio website from scratch. as you scroll you'll see the main content is made up of a two column layout. My columns are fixed, wrapped in a relative div that takes up 100% width. the two fixed divs inside take up 50% width. Then I put content inside of the fixed divs -- like my portfolio.
But sometimes the fixed divs height don't expand to the height of the content within it. Especially when you resize. Why?
Here's a link to my website so you can see what I mean.
http://parkhargravedesigns.com/
if ($(window).width() > 768) {
$('.f, .fixedContainer').css('height', $('.text').height());
$(window).resize(function() {
$('.f, .fixedContainer').css('height', $('.text').height());
});
$('.f2,.fixedContainer2').css('height', $('.text2').height());
$(window).resize(function() {
$('.f2,.fixedContainer2').css('height', $('.text2').height());
});
$('.f3, .fixedContainer3').css('height', $('.text3').height());
$(window).resize(function() {
$('.f3, .fixedContainer3').css('height', $('.text3').height());
});
}
.fixedContainer,
.fixedContainer2,
.fixedContainer3 {
position: relative!important;
width: 100%!important;
}
.headerEle2 {
display: block!important;
}
.f,
.f2,
.f3 {
background-color: #293553;
background-size: cover!important;
width: 50%!important;
position: absolute!important;
top: 0;
left: 0;
color: black;
font-size: 70px;
}
.f2 {
background-color: #e7384c!important;
}
.text,
.text2,
.text3 {
background-color: white!important;
background-size: cover!important;
color: black;
position: absolute!important;
right: 0!important;
top: 0!important;
width: 50%!important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fixedContainer">
<div class="f">
<div id="aboutStuff">
<p class="fTitle">
About
</p>
<div class="headerEle2 NavDiv"></div>
</div>
</div>
<div id="profilePic">
<img src="album/profilePic2.png" alt="oops">
</div>
<div class="text">
<h1>I'M A WEB & GRAPHIC DESIGNER FROM B.C, CANADA.</h1>
<p>
A strong interest in art and design was my gateway to the creative industry, which led to taking my first steps in the digital world. During my time at North Island College I fell inlove with web design because it allowed me to express my creativity while
developing the skills necessary to create functionable websites.
</p>
<h1>SERVICES:</h1>
<p>
<b>Website Design and Development Logo Design</b>
</p>
<h1>QUALIFICATIONS:</h1>
<p>
<b>HTML
CSS
JavaScript
JQuery
Illustrator
Photoshop
</b>
</p>
<h1>EDUCATION:</h1>
<p>
<b>Program:</b> Web Design & Interactive Media Certificate
<b>Where:</b> North Island College, Comox Valley, BC In this program I gained skills in HTML,<br> CSS, Javascript, PHP and Adobe CC.
</p>
<h1>DESIGN PROCESS</h1>
<p>
A user-centered mindset and sensitivity for design are <br> key concepts I carry throughout the design process.<br><br> This rough framework outlines my process of<br> developing digital experiences: 1. RESEARCH and gather the present state 2. STRUCTURE
setup and content of the project 3. CONCEPT AND STRATEGY <br> 4. CREATE, evaluate and iterate deliverables like -Site maps -User flow -Sketches and Infographics -Wireframes
</p>
<!--
<img src = "album/homeFixed.png" alt = "oops" id = "text1Logo">
-->
</div>
</div>