How do I center an image alongside multiple paragraphs - html

I have been at this for a while and I haven't really found a clear fix besides using Grids or Flexbox where I have an image in one column and paragraphs in the other, though surely that is not the best way to do it, is it? Ideally what I want to achieve is have my image and paragraphs dead in the middle, image on the left and the paragraphs on the right. I also tried using floats, but that gets me nowhere, the closest I got to the result that I want was with Flexbox, though by using flexbox the image would not scale down with screen size, so I am looking for another solution or for someone more knowledgeable to help me. I looked around online and some people bring up using span instead of paragraph, is that a good solution, common practice?
h3 {
font-family: 'Raleway';
font-weight: 700;
color: #979b9e;
}
.wrapper {
background-color: black;
margin-top: 5%;
text-align: left;
}
.aboutme {
float: left;
background-size: cover;
height: auto;
width: 5%;
display: block;
}
p {
color: #000;
display: inline-block;
font-family: 'Raleway';
font-weight: 400;
color: #979b9e;
text-align: left;
font-size: 1em;
float: right;
}
<div class="wrapper">
<img class="aboutme" src="img/aboutme.jpg">
<h3>x</h3>
<p>x</p>
<p>x</p>
<p>x</p>
<p>x</p>
<p>x</p>
</div>

Flexbox is most certainly a clean alternative to laying out content. Simply set up a parent element with a display: flex value (I changed 'wrapper' to 'row' for learning purposes). The immediate children can have a predefined width if you intend to use a grid system.
.row {
display: flex;
background-color: #f1f1f1;
}
.col-3 { width: 25%; }
.col-9 { width: 75%; }
.aboutme {
max-width: 100%;
}
h3 {
font-family: 'Raleway';
font-weight: 700;
margin: 0;
color: #979b9e;
}
p {
color: #000;
margin: 0;
display: block;
font-family: 'Raleway';
font-weight: 400;
}
<div class="row">
<div class="col-3">
<img class="aboutme" src="https://via.placeholder.com/100">
</div>
<div class="col-9">
<h3>Title</h3>
<p>Paragraph</p>
</div>
</div>

Your questions is very broad but does this achieve what you're after?
It doesn't use grids or flexboxes. You can condense this code even further too but this is just to give you a rough idea
.half {
float: left;
display: inline-block;
width: 50%;
}
.half img {
float: left;
display: inline-block;
width: 100%;
}
h3 {
display: inline-block;
width: 100%;
font-family: 'Raleway';
font-weight: 700;
color: #979b9e;
}
p {
color: #000;
display: inline-block;
display: block;
width: 100%;
font-family: 'Raleway';
font-weight: 400;
color: #979b9e;
text-align: left;
font-size: 1em;
float: right;
}
<div class="half">
<img class="aboutme" src="https://images.homedepot-static.com/productImages/22b7f2be-265e-4572-8246-bea85069604a/svn/costa-farms-house-plants-6zz-64_1000.jpg">
</div>
<div class="half">
<h3>Texttttt</h3>
<p>Texttttt</p>
<p>x</p>
<p>x</p>
<p>x</p>
<p>x</p>
</div>

Related

How to display container that is centered with content that is in the far left and far right of it

I would like to display the price of an object on my html website. This is what I would like it to look like:
Dynamic
The container is centered on the page with a max width of 400px
The "price" string is on the far left while the actual price is on the right of the centered content
This is what my html looks like:
<div class="price-container">
<div class="price">price:</div>
<div class="price-number">{{ event.price }}.00</div>
</div>
This is what my css looks like:
.price-container{
font-family: Montserrat;
text-transform: uppercase;
color: white;
font-weight: 700;
font-size: 20px;
width: 90%;
max-width: 400px;
}
.price{
float: left;
}
.price-number{
float: right;
}
If you want to center it horizontally, you need to add margin:auto. I also cleared the floats for you.
.price-container{
font-family: Montserrat;
text-transform: uppercase;
color: black;
font-weight: 700;
font-size: 20px;
width: 90%;
max-width: 400px;
margin: auto;
border: 1px solid red;
}
.price{
float: left;
}
.price-number{
float: right;
}
<div class="price-container">
<div class="price">price:</div>
<div class="price-number">{{ event.price }}.00</div>
<div style="clear:both"></div>
</div>
We can also write like this:
<div class="price-container">
<div class="price">price:</div>
<div class="price-number">{{ event.price }}.00</div>
</div>
CSS:
.price-container{
font-family: Montserrat;
text-transform: uppercase;
color: black;
font-weight: 700;
font-size: 20px;
width: 90%;
margin: 0 auto;
max-width: 400px;
border: 1px solid red;
display: flex;
justify-content: space-between;
}

How can I align component to be center in whole page?

I'm making this site and working on second page. However, I have trouble for centering component in the whole viewport. I searched lots of solutions including position, display:table, etc. But, I couldn't know how to use for this situation.
.header {
background-color: #F7F7F7;
padding: 15px;
}
.header h1 {
float: left;
}
.header h1 img {
display: block;
}
.header__nav {
float: right;
}
.header__nav li {
float: left;
display: flex;
align-items: center;
height: 38px;
}
.header__nav li a {
margin-right: 39px;
display: inline-block;
font-size: 20px;
font-weight: bold;
transition: all 0.5s;
}
.header__nav li a::after {
content: '';
width: 0;
height: 2px;
background-color: black;
transition: 0.3s;
display: block;
}
.header__nav li a:hover::after {
width: 100%;
}
.header__nav li button:hover::before {
width: 100%;
}
.contents {
padding: 150px 100px;
}
.contents__inside {
font-family: 'Playfair Display', serif;
text-align: center;
font-size: 1rem;
}
.contents__inside strong {
font-style: italic;
font-size: 1rem;
}
.contents__inside h2 {
margin-bottom: 10px;
font-size: 6rem;
font-weight: bold;
line-height: 1;
}
.contents__inside img {
width: 100%;
}
.contents__inside p {
max-width: 860px;
font-size: 1.7rem;
font-weight: 400;
margin: 0 auto;
}
.info__inside {
font-family: 'Playfair Display', serif;
text-align: center;
font-size: 1rem;
}
.info__inside h2 {
margin-bottom: 30px;
font-size: 4rem;
font-weight: bold;
line-height: 1;
}
.info__inside p {
max-width: 860px;
font-size: 1.7rem;
font-weight: 400;
margin: 0 auto 100px;
}
.info__inside img {
width: 100%;
}
.footer {
background-color: blue;
}
<header class="header clearfix">
<div class="l-wrapper">
<h1><img src="https://pixelicons.com/wp-content/themes/pexelicons/assets/pic/site-logo/logo.png" alt="Logo"></h1>
<nav class="header__nav">
<ul class="clearfix">
<li>View icons</li>
<li>Buy now</li>
<li><button class="menu">menu</button></li>
</ul>
</nav>
</div>
</header>
<section class="contents">
<div class="l-main">
<div class="contents__inside">
<strong>Top quality</strong>
<h2>ICONS</h2>
<p>6,500 unique icons in different categories.
Drawn by hand and designed for perfection.</p>
<img src="https://pixelicons.com/wp-content/uploads/2018/01/Home_slide_space.png" alt="">
</div>
</div>
</section>
<section class="info">
<div class="l-main">
<div class="info__inside">
<h2>Thousands of icons</h2>
<p>6,500 unique icons in 3 style color, line and solid.</p>
<img src="https://pixelicons.com/wp-content/uploads/2018/01/Preview_rd_2.png" alt="">
</div>
</div>
</section>
<footer class="footer">
</footer>
Is there an any proper method to solve this issue? How can I implement like original design of website?
EDIT
I don't wanna solve by using CSS3 property to practice CSS2
IMAGE that I wanna fix
If i understand you, You want to center your items in your div
To do that you can
.yourDivClassName{
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-items:center;
justify-content: center;
}
<body>
<div class="yourDivClassName">
<button>example button</button>
<p>example text</p>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFU7U2h0umyF0P6E_yhTX45sGgPEQAbGaJ4g&usqp=CAU" alt="example image">
</div>
</body>

How to float image in div with centered text and correct background

This is what my header bar currently looks like: https://i.imgur.com/Hx67zu6.png
However, I want the text to be centered horizontally and have the image all the way to the left.
When I tried adding float: left to the image's css, it completely messed it up, like this: https://i.imgur.com/UtLC3xk.png
As you can see, the title is not aligned horizontally or vertically, and the bar doesn't stretch to accommodate the image.
HTML:
<div class="EA-header-bar">
<img src="~/Images/EA Icons/YoungDriver_white.png" class="EA-header-image" />
<p class="EA-header-text">
<b>YOUNG DRIVERS</b>
</p>
</div>
CSS:
.EA-header-bar {
background-color: rgb(206,33,39);
text-align: center;
}
.EA-header-image {
margin: 1%;
margin-left: 3%;
height:150px;
float: left;
}
.EA-header-text {
text-align: center;
color: white;
font-size: 6vmin;
display: inline-block;
vertical-align: middle;
font: bolder;
font-family: kalinga;
}
When doing this kind of positioning work try to use flexbox, coding is fast and nifty. Also put tags like <img>,<p> or related inline tags inside <div> just to look pro, but those are just recomendations always look for ways to improve your css.
.EA-header-bar {
display: flex;
background-color: rgb(206,33,39);
text-align: center;
justify-content: center;
align-items: center;
}
.EA-col-img {
padding-left: 20px;
}
.EA-col-txt {
flex:1
}
.EA-header-image {
height:150px;
}
.EA-header-text {
color: white;
font-size: 6vmin;
font: bolder;
font-family: kalinga;
}
<div class="EA-header-bar">
<div class="EA-col-img">
<img src="https://image.flaticon.com/icons/svg/75/75804.svg" class="EA-header-image" />
</div>
<div class="EA-col-txt">
<p class="EA-header-text">
<b>YOUNG DRIVERS</b>
</p>
</div>
</div>
Another example using absolute positionining
I think this one is more accured to your needs
.EA-header-bar {
position: relative;
display: flex;
background-color: rgb(206,33,39);
text-align: center;
justify-content: center;
align-items: center;
}
.EA-col-img {
position: absolute;
left: 5vw;
}
.EA-col-txt {
flex:1
}
.EA-header-image {
height:20vh;
}
.EA-header-text {
color: white;
font-size: 6vmin;
font: bolder;
font-family: kalinga;
}
<div class="EA-header-bar">
<div class="EA-col-img">
<img src="https://image.flaticon.com/icons/svg/75/75804.svg" class="EA-header-image" />
</div>
<div class="EA-col-txt">
<p class="EA-header-text">
<b>YOUNG DRIVERS</b>
</p>
</div>
</div>

HTML CSS Banner Alignment

Can someone please help me out why my "desc" content is not right under my title in the banner? I have posted my CSS and HTML code. I have also posted the photo of how the outcome looks.
#bannerBottom {
border: 5px #0087dd solid;
margin-top: 30px;
margin-bottom: 50px;
}
#bannerImg {
width: 150px;
margin-top: 7px;
margin-left: 10px;
display: inline-block;
}
#bannerContent {
display: inline-block;
vertical-align: top;
margin-left: 20px;
}
#bannerContent>span {
font-size: 20px;
font-weight: bold;
font-family: arial;
color: steelblue;
display: inline-block;
}
#desc {
font-family: arial;
display: inline-block;
margin-left: 190px;
}
<div id="bannerBottom">
<img id="bannerImg" src="http://www.placehold.it/100x100">
<p id="bannerContent">
<span>The Big 3 - HTML, CSS, JavaScript</span>
</p>
<p id="desc">While the server can process information in many different languages, the file that they serve to the client are always going to be some combination of HTML, CSS, and JavaScript!<br>Learn more about the Big 3 here!</p>
</div>
You can float your image left instead of making it an inline-block element. Also there'd be no need to make the paragraph an inline-block either.
#bannerBottom {
border: 5px #0087dd solid;
margin-top: 30px;
margin-bottom: 50px;
}
#bannerImg {
width: 150px;
margin-top: 7px;
margin-left: 10px;
float: left;
}
#bannerContent {
display: inline-block;
vertical-align: top;
margin-left: 20px;
}
#bannerContent>span {
font-size: 20px;
font-weight: bold;
font-family: arial;
color: steelblue;
display: inline-block;
}
#desc {
font-family: arial;
margin-left: 190px;
}
<div id="bannerBottom">
<img id="bannerImg" src="http://www.placehold.it/100x100">
<p id="bannerContent">
<span>The Big 3 - HTML, CSS, JavaScript</span>
</p>
<p id="desc">While the server can process information in many different languages, the file that they serve to the client are always going to be some combination of HTML, CSS, and JavaScript!<br>Learn more about the Big 3 here!</p>
</div>
Surely it is because you have:
#desc {
margin-left: 190px;
}
... which means the box isn't fitting under the title, so it is getting shunted underneath. Either way, float the image left and don't have margin-left.
try this:
<div id="bannerBottom">
<div class="container-banner-img">
<img id="bannerImg" src="http://www.placehold.it/100x100">
</div>
<div class="container-banner-content">
<p id="bannerContent">
<span>The Big 3 - HTML, CSS, JavaScript</span>
</p>
<p id="desc">While the server can process information in many different languages, the file that they serve to the client are always going to be some combination of HTML, CSS, and JavaScript!<br>Learn more about the Big 3 here!
</p>
</div>
</div>
CSS
#bannerBottom {
border: 5px #0087dd solid;
margin-top: 30px;
margin-bottom: 50px;
}
#bannerImg {
width: 150px;
margin-top: 7px;
margin-left: 10px;
display: inline-block;
}
#bannerContent {
display: inline-block;
vertical-align: top;
margin-left: 20px;
}
#bannerContent>span {
font-size: 20px;
font-weight: bold;
font-family: arial;
color: steelblue;
display: inline-block;
}
#desc {
font-family: arial;
display: inline-block;
margin-left: 190px;
}
.container-banner-img {
float: left; /* <- pay attention on this line */
width:25%;
}
.container-banner-content{
width: 70%;
}
}
If you don't want to go the flexbox route you can float the image and keep your heading and description block level.
I took a few liberties with the markup and CSS selectors, changing them from IDs to classes and other improvements to streamline everything.
.entry {
font-family: Arial, sans-serif;
border: 5px solid #0087dd;
margin: 30px 0;
}
.entry-img {
float: left;
max-width: 150px;
margin: 10px;
}
.entry-title {
font-size: 20px;
color: steelblue;
}
.entry-desc {
margin: 10px;
}
<div class="entry">
<img class="entry-img" src="http://www.placehold.it/100x100">
<h2 class="entry-title">The Big 3 - HTML, CSS, JavaScript</h2>
<p class="entry-desc">While the server can process information in many different languages, the file that they serve to the client are always going to be some combination of HTML, CSS, and JavaScript!<br>Learn more about the Big 3 here!</p>
</div>

How do I center each element with the element above it? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have attached the HTML and CSS I have so far but I am new to front end so I'm not sure what the best approach is.
I just want each text element to be aligned with the respective numbers underneath them.
h1 {
font-family: 'Biryani', sans-serif;
font-size: 20px;
font-weight: bold;
text-align: center;
padding: 50px;
}
ul {
text-align: justify;
}
ul:after {
content: '';
display: inline-block;
width: 100%;
}
ul:before {
content: '';
display: block;
margin-top: 0em;
}
li1 {
font-family: 'Biryani', sans-serif;
font-size: 14px;
font-weight: light;
color: #929292;
display: inline-block;
margin-left: 10em;
margin-right: 13em;
position: relative;
top: 1.25em;
}
li2 {
font-family: 'Biryani', sans-serif;
font-size: 16px;
font-weight: light;
color: #929292;
display: inline-block;
margin-left: 10em;
margin-right: 13em;
position: relative;
top: 1.25em;
}
<!DOCTYPE HTML>
<html>
<head>
<title> REALSURF</title>
<link rel="stylesheet" type="text/css" href="realsurfcss.css">
<link href="https://fonts.googleapis.com/css?family=Biryani:300,400,800" rel="stylesheet">
</head>
<body>
<h1>
REALSURF
</h1>
<ul>
<li1>Wind</li1>
<li1>Wave Height</li1>
<li1>Tide</li1>
</ul>
<ul>
<li2>6</li2>
<li2>3-4</li2>
<li2>1.8^</li2>
</ul>
</body>
</html>
Simply, wrap each columns of elements in the same block and set it's property text-align to center in CSS.
Here is an approach using CSS's flex (https://css-tricks.com/snippets/css/a-guide-to-flexbox/)
.container {
display: flex;
width: 100%;
}
.column {
text-align: center;
flex-grow: 1;
}
<div class="container">
<div class="column">Text<br />Number</div>
<div class="column">Text<br />Number</div>
<div class="column">Text<br />Number</div>
</div>
You can also do that with tables, take a look:
table {
width: 100%;
}
td {
text-align: center;
}
<table>
<tr>
<td>Text<br/>Number</td>
<td>Text<br/>Number</td>
<td>Text<br/>Number</td>
</tr>
</table>
You asked about styling of each rows, all you need to do is wrap each row in each element like below:
.container {
display: flex;
width: 100%;
}
.column {
text-align: center;
flex-grow: 1;
}
.text {
font-weight: bold;
font-family: Helvetica;
color: red;
}
.number {
font-size: 18px;
margin-top: 16px;
color: green;
}
<div class="container">
<div class="column">
<div class="text">Text</div>
<div class="number">Number</div>
</div>
<div class="column">
<div class="text">Text</div>
<div class="number">Number</div>
</div>
<div class="column">
<div class="text">Text</div>
<div class="number">Number</div>
</div>
</div>
Easiest with Ruby annotations, but it'll only work in more modern browsers:
body {
font-size: 30px;
}
<ruby>
5<rp>(</rp><rt>text</rt><rp>)</rp>
</ruby>
<ruby>
1-2<rp>(</rp><rt>text</rt><rp>)</rp>
</ruby>
<ruby>
8<rp>(</rp><rt>text</rt><rp>)</rp>
</ruby>
using pseudo element after JSFiddle
li{
display: inline-block;
padding: 0 20px;
font-size: 50px;
position: relative;
line-height: 90px;
}
li:before{
content: 'text';
position: absolute;
left: 0;
right: 0;
top: 0;
margin: auto;
font-size: 12px;
line-height: 12px;
text-align: center;
}