How to make item cards in a line by 3 - html

I'm trying to make an online shop. I need 3 items in a row. I tried to do it by function but I see the cards under each other. How can I make a row of cards by 3 elements?
When I use flex the card doesn't look with the same design as now.
I think that the problem is with .product-item
Help me, please.
MY CSS:
* {
box-sizing: border-box;
border: 1px #e2e2e2;
}
.product-item {
width: 300px;
height:205px;
text-align: center;
border: 1px #e2e2e2;
background: white;
font-family: "Roboto";
}
.product-item img {
display: inline-block;
width: 100%;
border: 1px #e2e2e2;
}
.product-list {
background: #fafafa;
padding: 15px 0;
}
.product-list h3 {
font-size: 20px;
font-family: "Roboto";
text-align: left;
margin: 25px;
font-weight: 400;
color: #333333;
}
.product-list h4 {
font-size: 15px;
font-family: "Roboto";
text-align: left;
margin: 25px;
font-weight: 400;
color: #666666;
}
.sell {
font-size: 20px;
font-family: "Roboto";
color: #333333;
margin: 65px;
}
.price {
font-size: 35px;
text-align: left;
font-family: "Roboto";
color: #333333;
margin: -65px;
}
.cart img
{margin-top:-60px;
margin-left:200px;
width: 15%;
}
My HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Card set</title> <!-- Задаем заголовок документа -->
<link rel="stylesheet" type="text/css" href="cardset.css">
<script src="script.js"></script>
</head>
<body>
<div class="product-item">
<img src="boots.png">
<div class="product-list">
<h3>Ботинки женские</h3>
<h4>Модные ботинки из натурального нубука. Согреют Ваши ноги во время зимних морозов.</h4>
<p><span class = 'price'>1999</span><span class = 'sell'>руб.</span><div class="cart"><img a href="" src="cart.png">
</div>
</div>
<div class="product-item">
<img src="boots.png">
<div class="product-list">
<h3>Ботинки женские</h3>
<h4>Модные ботинки из натурального нубука. Согреют Ваши ноги во время зимних морозов.</h4>
<p><span class = 'price'>1999</span><span class = 'sell'>руб.</span><div class="cart"><img a href="" src="cart.png">
</div>
</div>
</body>
</html>

Try adding this to product-item class:
Width:33%;
Display:inline-block;

There are a lot of typography errors in your code (look at the class you are defining, look at the extra spaces, unclosed code sections in your CSS etc.)
To align three items, you can simply use flexbox display. Like in the example below.
section {
display:flex;
}
.itemmm img {
width:100px;
height:100px;
margin:25px;
}
<html>
<head>
<meta charset="UTF-8">
<title>Card set</title>
<!-- Задаем заголовок документа -->
<link rel="stylesheet" type="text/css" href="cardset.css">
<script src="script.js"></script>
</head>
<body>
<section class="items-container">
<div class="itemmm">
<img src="https://cdn.pixabay.com/photo/2015/03/26/09/41/chain-690088_960_720.jpg">
</div>
<div class="itemmm">
<img src="https://cdn.pixabay.com/photo/2015/03/26/09/41/chain-690088_960_720.jpg">
</div>
<div class="itemmm">
<img src="https://cdn.pixabay.com/photo/2015/03/26/09/41/chain-690088_960_720.jpg">
</div>
</section>
</body>
</html>

Related

CSS/HTML image not responding to the width and text-align

So I've been trying to make myself a personal portfolio, however I've run into issues regarding that. Whenever I try to resize my image using the width thing in CSS3, my image does not respond. I've tried resizing it to 25%, 50%, 75%, and nothing works!
Here's my code:
body {
margin: 0px;
background-color: white;
}
.container {
display: grid;
grid-template-columns: 1fr;
}
/*Nav Styles*/
.brand {
font-family: 'Titillium Web';font-size: 15px;
}
.nav-wrapper {
display: flex;
justify-content: space-between;
padding: 38px;
}
.left-side {
display:flex;
}
.nav-wrapper > .left-side > div {
margin-right: 20px;
font-size: 0.9em;
text-transform: uppercase;
}
.nav-link-wrapper {
font-family: 'Titillium Web';font-size: 15px;
height: 22px;
border-bottom: 1px solid transparent;
transition: border-bottom 0.5s;
}
.nav-link-wrapper a {
color: #8a8a8a;
text-decoration: none;
transition: color 0.5s
}
.nav-link-wrapper:hover {
border-bottom: 1px solid black;
}
.nav-link-wrapper a:hover {
color:black
}
/*About Page Styles*/
.profile-image-wrapper {
text-align: center;
width: 50%;
}
.profile-content-wrapper {
padding: 30px;
text-align: center;
}
.profile-content-wrapper h1 {
color: black;
font-family: 'Titillium Web';font-size: 22px;
}
.profile-content-wrapper p {
color: black;
font-family: 'Titillium Web';font-size: 15px;
}
.profile-content-wrapper h4 {
color: black;
font-family: 'Titillium Web';font-size: 15px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mika's Portfolio</title>
<link href='https://fonts.googleapis.com/css?family=Titillium Web' rel='stylesheet'>
</head>
<body>
<div class = "container">
<div class="nav-wrapper">
<div class = "left-side">
<div class="nav-link-wrapper">
Home
</div>
<div class="nav-link-wrapper">
Projects
</div>
<div class="nav-link-wrapper">
About
</div>
</div>
<div class = "right-side">
<div class="brand">
<div>
MIKA TAN
</div>
</div>
</div>
</div>
<div class="profile-image-wrapper">
<img src="https://cdn.pixabay.com/photo/2020/09/16/20/30/lighthouse-5577451_1280.jpg">
</div>
<div class="profile-content-wrapper">
<h1>
Hey there!
</h1>
<p>
Now you've got a quick look around my website, think about hiring me to make you your own website!
</p>
<p>
Thanks, have a great day.
</p>
<h4>
GMAIL:
</h4>
<p>
mikayxtan#gmail.com
</p>
</div>
</div>
</body>
</html>
My image called mika.png is in a class called profile-image-wrapper, and also does not respond to the text-align: center; thing.
I have tried in-line style coding, which works to an extent (however I prefer to not have to use in-line style so I can create a media query later), and I have used the !important attribute for CSS which only works for text-align and not the width.
To make your image responsive you should give it a max-width: 100% right now it follows the width of the container and it stays inside of it. So add this new piece of code.
.profile-image-wrapper img {
max-width: 100%;
}
now the image fills 50% of the width as you wanted to do. Now if you want your image to be in the middle with 50% width just add margin: 0 auto; to the image wrapper and you should be good to go.
.profile-image-wrapper {
text-align: center;
width: 50%;
margin: 0 auto;
}
if you want the image to be fill width you can remove the width 50% from the wrapper.
with 50% width applied to the wrapper
without the 50% width on the wrapper, it would look something like this.
Note that in both cases the image is responsive duo to the fact you added max-width:100% to the img tag.
That's not what you are looking for? please let me know and show me a screenshot of the desired output.
Try it:
.profile-image-wrapper img{
width:15%
}
Please set margin: 0 auto; for .profile-image-wrapper selector to make center horizontally.
Please set display: inline-block; CSS in .profile-image-wrapper img selector
Updated snippet :-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mika's Portfolio</title>
<link href='https://fonts.googleapis.com/css?family=Titillium Web' rel='stylesheet'>
</head>
<style>
body {
margin: 0px;
background-color: white;
}
.container {
display: grid;
grid-template-columns: 1fr;
}
/*Nav Styles*/
.brand {
font-family: 'Titillium Web';font-size: 15px;
}
.nav-wrapper {
display: flex;
justify-content: space-between;
padding: 38px;
}
.left-side {
display:flex;
}
.nav-wrapper > .left-side > div {
margin-right: 20px;
font-size: 0.9em;
text-transform: uppercase;
}
.nav-link-wrapper {
font-family: 'Titillium Web';font-size: 15px;
height: 22px;
border-bottom: 1px solid transparent;
transition: border-bottom 0.5s;
}
.nav-link-wrapper a {
color: #8a8a8a;
text-decoration: none;
transition: color 0.5s
}
.nav-link-wrapper:hover {
border-bottom: 1px solid black;
}
.nav-link-wrapper a:hover {
color:black
}
/*About Page Styles*/
.profile-image-wrapper {
text-align: center;
width: 50%; margin:0 auto;
}
.profile-image-wrapper img{ width:50%; display: inline-block;}
.profile-content-wrapper {
padding: 30px;
text-align: center;
}
.profile-content-wrapper h1 {
color: black;
font-family: 'Titillium Web';font-size: 22px;
}
.profile-content-wrapper p {
color: black;
font-family: 'Titillium Web';font-size: 15px;
}
.profile-content-wrapper h4 {
color: black;
font-family: 'Titillium Web';font-size: 15px;
}
</style>
<body>
<div class = "container">
<div class="nav-wrapper">
<div class = "left-side">
<div class="nav-link-wrapper">
Home
</div>
<div class="nav-link-wrapper">
Projects
</div>
<div class="nav-link-wrapper">
About
</div>
</div>
<div class = "right-side">
<div class="brand">
<div>
MIKA TAN
</div>
</div>
</div>
</div>
<div class="profile-image-wrapper">
<img src="https://i.imgur.com/HPrl3u8.jpg">
</div>
<div class="profile-content-wrapper">
<h1>
Hey there!
</h1>
<p>
Now you've got a quick look around my website, think about hiring me to make you your own website!
</p>
<p>
Thanks, have a great day.
</p>
<h4>
GMAIL:
</h4>
<p>
mikayxtan#gmail.com
</p>
</div>
</body>
</html>

Bootstrap 3 grid - images overlapping

I'm new to web development and I'm trying to build a site using bootstrap 3. I want to use the grid layout for a section with three points but whenever I add it, the images overlap and are not centered when the browser is below the SM breakpoint.
Here is the HTML.
<!DOCTYPE html>
<html>
<head lang="en">
<!--Meta Data-->
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="Luke Bouch">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Always Ready Power</title>
<!--Styles-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> <!--BootStrap CDN-->
<link rel="stylesheet" href="styles/styles.css">
</head>
<body>
<nav class="topNav">
<div class="container">
<img class="navLogo centerMobile" src="assets/20200811-ARLogo-White.png" alt="two kids looking out the window">
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="hero col-xs-12">
<h1>Keep your family safe<br/><span class="newLine">with a whole house generator</span></h1>
</div>
</div>
<div class="horizonralLayout row">
<div class="col-sm-4">
<img src="assets/point1.png">
<h2>It's only a matter of time<span class="newLine">before your stuck without power</span></h2>
</div>
<div class="col-sm-4">
<img src="assets/point2.png">
<h2>It's only a matter of time<span class="newLine">before your stuck without power</span></h2>
</div>
<div class="col-sm-4">
<img src="assets/point3.png">
<h2>It's only a matter of time<span class="newLine">before your stuck without power</span></h2>
</div>
</div>
</div>
<!--Scripts-->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</body>
</html>
And here is the CSS.
/* --- IMPORT --- */
#import url("https://use.typekit.net/ptx4dws.css");
/* --- MOBILE ---*/
/* Global */
h1 {
font-family: proxima-nova, sans-serif;
font-weight: 800;
font-style: normal;
text-transform: uppercase;
font-size: 4rem;
font-weight: 800;
}
h2 {
font-family: proxima-nova, sans-serif;
font-weight: 800;
font-style: normal;
text-transform: uppercase;
font-size: 3rem;
font-weight: 800;
}
.newLine {
display: block;
font-size: 2.2rem;
font-weight: 500;
}
p {
font-family: proxima-nova, sans-serif;
font-weight: 500;
font-style: normal;
}
a {
text-decoration: none;
color: black;
}
.break {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
.centerMobile {
display: block;
margin-left: auto;
margin-right: auto;
}
/* NavBar */
.topNav {
background-color: rgb(232, 19, 35);
}
.navLogo {
height: 80px;
margin: 10px auto 10px auto;
align-content: center;
}
.menuList {
list-style: none;
}
.topNav li {
padding: 5px 5px 5px 5px;
}
.topNav a {
color: white;
font-size: 1.7em;
}
.topNav a:hover {
text-decoration: none;
font-weight: 600;
}
/* Hero */
.hero {
padding: 25vw 5vw 25vw 5vw;
background-image: url(/assets/heroBG.png);
background-position: center;
background-size: cover;
}
.hero h1 {
text-transform: uppercase;
font-size: 4rem;
font-weight: 800;
}
.hero .newLine {
display: block;
font-size: 2.2rem;
font-weight: 500;
}
/* Horizontal Layout*/
.horizontalLayout .item {
padding: 10px 10px 10px 10px;
}
I really appreciate any help!
Two issues - first - you are not applying any styling for the xs- class -so it will be taking up the entire width (if you do not apply a column designation - the element will be at 100% of the width - as if you had col-xs-12.
If you still want the 3 images across - then you will need to apply a col-xs-4 to the divs with col-sm-4. Alternatively - you might want them to be different porpotional widths on the xs size - so you might want col-xs-6 col-sm-4" and have the images on two lines.
And second - you have a discrepancy in the code between the html class and the associatd styling - horizontalLayout needs to be updated in the html
//html
<div class="horizonralLayout row">
/css
/* Horizontal Layout*/
.horizontalLayout .item {
padding: 10px 10px 10px 10px;
}
And a suggestion - investigate the element for your images - its the right tool for displaying the content you are showing here.
<div class="col-xs-4">
<figure>
<img src="assets/point3.png">
<figcaption>
It's only a matter of time<span class="newLine">before your stuck without power</span>
</figcaption>
</figure>
</div>

pdfkit generates small scaled pdfs

I am using pdfkit in order to generate pdfs from html strings, rendered by my Django's views.
For some reason, the output pdf is small.
My pdfkit option dictionary is -
options = {
'quiet': '',
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'disable-smart-shrinking': ''
}
and the output file is here
Html code is -
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="pdfkit-orientation" content="Portrait"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Dribble</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<!-- Google Font -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700,800" rel="stylesheet">
<!-- Custom Font -->
<style>
body {
font-family: 'Open Sans', sans-serif;
}
p, a {
color: #002f54;
}
.nav {
background: #002f54;
color: #FFFFFF;
border-radius: 5px;
}
.ico {
padding-right: 5px;
top: 3px;
}
.nav > li p {
text-align: center;
font-size: 36px;
font-weight: 800;
}
.right-align {
float: right;
}
.pad-mar {
font-size: 18px;
padding-top: 10px;
padding-bottom: 10px;
margin-left: 30px !important;
margin-right: 30px;
}
.pad-mar-middle {
font-size: 18px;
padding-top: 78px;
padding-bottom: 25px;
margin-left: 30px !important;
margin-right: 30px;
}
.pad-mar-bottom {
font-size: 18px;
padding-top: 10px;
padding-bottom: 90px;
margin-left: 30px !important;
margin-right: 30px;
}
.pad-mar-footer {
padding-top: 20px;
margin-left: 30px !important;
margin-right: 30px;
}
.bor-bottom {
border-bottom: 2px solid #ccc;
}
.no-pad {
padding-left: 0;
}
.section {
margin-top: 20px;
margin-bottom: 20px;
}
.bold {
font-weight: 700;
color: #002f54;
}
.small {
font-size: 14px;
}
.bolder {
color: #002f54;
font-weight: 800;
font-size: 22px;
}
.normal {
color: #002f54;
font-weight: 700;
}
.smaller {
font-size: 14px;
font-weight: 700;
}
h3 .bold {
margin-top: 0;
}
.neg-mar {
margin-top: -25px;
}
.cus-img {
max-width: 85px;
margin-bottom: 10px;
}
.nav-stacked.mob > li {
font-size: 16px;
margin-left: 0px !important;
margin-right: 0px;
margin-bottom: 10px;
padding-top: 5px;
border: 1px solid #EB6C6D;
border-radius: 5px;
font-weight: 300;
text-align: center;
color: #EB6C6D;
}
.nav-stacked.mob > li p {
color: #002f54;
}
.nav.mob {
background: #FFFFFF;
}
.pad-mar-bottom.mob {
margin-left: 0px !important;
padding-bottom: 10px;
}
.pad-mar-footer.mob {
margin-left: 0px !important;
text-align: center;
padding-top: 10px;
}
.l-mar {
margin-left: 40px;
}
.titl {
color: #EB6C6D;
font-size: 16px;
}
.bot-mar {
margin-bottom: 20px;
}
.container {
max-width: 575px;
}
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<section class="section">
<div class="container">
<div class="row bor-bottom bot-mar">
<div class="col-xs-6 ">
<img src="https://api.figo.me/assets/images/accounts/north_channel_bank_144.png"
class="img-responsive cus-img"/>
<p> Commerzbank Service-BZ</p>
<p>First line</p>
</div>
<div class="col-xs-6">
<div class="right-align neg-mar">
<h3 class="bold">First line</h3>
<p class="bold">First line</p>
<p class="bold">First line</p>
</div>
</div>
</div>
<div class="row">
<div class="">
<ul class="nav nav-stacked mob">
<li><span class="glyphicon glyphicon glyphicon-user ico"></span>From<p>Rewe GmbH</p></li>
<li><span class="glyphicon glyphicon glyphicon-credit-card ico"></span>Amount<p>$ 32,10 USD</p></li>
<li><span class="glyphicon glyphicon glyphicon-calendar ico"></span>Payment Date<p>Nov 5, 2017</p>
</li>
</ul>
</div>
</div>
<div class="row pad-mar-bottom mob bor-bottom">
<p class="titl"><span class="glyphicon glyphicon-tag ico"></span>Payment Reference</p>
<div class="l-mar">
<p class="normal">Hello Ennio,</p>
<p class="normal">You sent a payment of <span class="bolder">$20.00 USD</span> to Dribble. (paypal#dribble.com)</p>
<div class="no-pad">
<p class="smaller">It may take a few moments for this transaction to appear in your account.</p>
</div>
</div>
</div>
<footer>
<div class="row pad-mar-footer mob">
<a class="smaller" href="#">This document was automatically generated by Koryo</a>
</div>
</footer>
</div><!-- Container -->
</section>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
The problem was about setting the dpi parameter for pdfkit.
So if you encounter the same problem, just set the dpi according to your need. For me, this what I was needed
options = {
'page-size': 'A4',
'dpi': 400
}
I had this same issue. I just changed the default configuration:
PDFKit.configure do |config|
config.default_options = {
page_size: 'A4',
print_media_type: true,
dpi: 400
}
end
you can try to disable shrinking through the options as below
options = { 'disable-smart-shrinking': ''}

text inside button not centered

Here I'm creating a button but for some odd reason the text is a little off and isn't centered even though I have used display: block; and text-align: center; inside my css file.
Line 30 is where my button starts here is my html and custom css code.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="bootstrap/js/jquery-2.2.3.min.js" type="text/javascript"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href='https://fonts.googleapis.com/css?family=Bree+Serif' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<title>Proto X Media - Home</title>
</head>
<body>
<div class="bg1">
<div class="container">
<div class="row">
<div class="col-md-6">
<img class="lgsize" src="logo.gif" alt="Logo">
</div>
<div class="col-md-6">
</div>
</div>
<div class="row">
<div class="pushdown">
<div class="col-md-6 col-md-offset-3">
<span class="text-center title">Proto X Media</span>
<p class="text-center subtext">Professional Media Production & Hardware Consultation.</p>
<div class="buttonpad">
<div class="button">
<span>Explore</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
And here is my css on line 39 is where the code for my button is
.title {
font-family: 'Bree Serif', serif;
font-weight: 800;
font-size: 500%;
color: 373d44#;
display: block;
text-align: center;
}
.bg1 {
background-image: url("bg2.jpg");
background-size: cover;
}
.lgsize {
width: 120px;
height: 110px;
}
.pushdown {
padding-top: 100px;
padding-bottom: 250px;
}
.menu {
font-size: 100%
font-family: 'Bree Serif', serif;
}
a {
color:inherit;
text-decoration: none;
}
a:hover {
background-color: transparent;
text-decoration: none;
}
.subtext {
text-align: center;
font-family: 'Raleway', sans-serif;
font-size: 18px;
display: block;
}
.button {
width: 82.61px;
height: 37.65px;
box-sizing: border-box;
background-color: white;
font-weight: 700px;
box-shadow: 0px .2em 0px 0px #ebebeb;
display: block;
text-align: center;
background-position: center;
border: none;
margin: auto;
font-family: 'Bree Serif', serif;
}
.buttonpad {
padding-top: 10px;
}
Thank you very much ! Also if you haven't noticed I'm using Bootstrap for my grid.
For centering horizontal, change your markup to this and you should be fine
<div class="button"><span>Explore</span></div>
When breaking line using an inline element, that line break cause a white space at the end pushing the text slightly to the left
For centering vertical, use line height, like this
.button {
width: 82.61px;
height: 37.65px;
line-height: 37.65px; /* added property */
box-sizing: border-box;
background-color: white;
font-weight: 700px;
box-shadow: 0px .2em 0px 0px #ebebeb;
display: block;
text-align: center;
background-position: center;
border: none;
margin: auto;
font-family: 'Bree Serif', serif;
}
Try to use padding like this;
padding: 6px 12px;
OR
.button{
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: 400;
line-height: 1.42857;
padding: 6px 12px;
text-align: center;
vertical-align: middle;
white-space: nowrap;
}
One simple fix is to use line-height as the height of the containing div, as in this jsfiddle :
.button span
{
display: block;
line-height: 37px;
}
https://jsfiddle.net/az2vs6y3/1/
Or you could also use negative margin and absolute positionning, but it would be slightly less flexible.
Why are you using div as button, use html button for hyperlink and css looks fine
<input type="submit" value="Explore">

How do I center a button using CSS?

I am trying to add a button to my simple web page. The button itself looks great, but I am not quite sure how to position it. I would like for it to be centered and positioned below the main text. It currently sits off to the left side. Any idea on how to do so?
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="spiekermann.css">
<title></title>
<style>
#logo {
width: 100%;
text-align: center;
padding: 10em 0 0.2em 0;
font-family: lato;
}
#sub {
color: #fff;
font-family: lato;
text-align: center;
word-spacing: 5em;
}
.button {
background-color: #3b3d45;
border: 6px solid #fff080;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 12px;
padding: 15px 20px;
text-decoration: none;
margin: auto;
text-align: center;
}
.button:hover {
background-color: #707488;
}
</style>
</head>
<body>
<div class id="logo">
<h1>ERIK SPIEKERMANN</h1>
</div>
<div class id="sub">
<p>Designer Typographer Entrepreneur </p>
</div>
Learn More
</body>
</html>
Any help would be greatly appreciated. Thanks!
You don't necessarily need a container. Try the following:
.button {
background-color: #3b3d45;
border: 6px solid #fff080;
display: block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 12px;
padding: 15px 20px;
text-decoration: none;
margin: auto;
text-align: center;
width: 62px;
}
Auto margins don't apply to inline-block elements.
You can add a container to the buttons and align them to center . see example below
also when you are trying to create a style . try to make them reusable as they can be. One advantage of this is you can write lesser css.
#logo {
width: 100%;
text-align: center;
padding: 10em 0 0.2em 0;
font-family: lato;
}
#sub {
color: #fff;
font-family: lato;
text-align: center;
word-spacing: 5em;
}
.button {
background-color: #3b3d45;
border: 6px solid #fff080;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 12px;
padding: 15px 20px;
text-decoration: none;
margin: auto;
text-align: center;
}
.button:hover {
background-color: #707488;
}
.text-center {
text-align: center;
}
<div class id="logo">
<h1>ERIK SPIEKERMANN</h1>
</div>
<div class id="sub">
<p>Designer Typographer Entrepreneur </p>
</div>
<div class="text-center">
Learn More
</div>
Try putting the Button in a <div> and make text-align:center
<div class="btnContainer ">
Learn More
</div>
<style>
.btnContainer {
text-align:center;
}
</style>
Without extra markup adding the following rules to .button will do the trick
left: 50%;
position: absolute;
transform: translate(-50%, 0);
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="spiekermann.css">
<title></title>
<style>
#logo {
width: 100%;
text-align: center;
padding: 10em 0 0.2em 0;
font-family: lato;
}
#sub {
color: #fff;
font-family: lato;
text-align: center;
word-spacing: 5em;
}
.button {
background-color: #3b3d45;
border: 6px solid #fff080;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 12px;
padding: 15px 20px;
text-decoration: none;
margin: auto;
}
.button:hover {
background-color: #707488;
}
#button {
text-align: center;
}
</style>
</head>
<body>
<div class id="logo">
<h1>ERIK SPIEKERMANN</h1>
</div>
<div class id="sub">
<p>Designer Typographer Entrepreneur </p>
</div>
<div class id="button">
Learn More
</div>
</body>
</html>
how do you think this way?