I'm trying to put the blue div at the bottom of this picture, and I'm stuck for some reason.
My CSS:
.boxes {
margin-left: 4%;
margin-right: -4px;
height: 345px;
padding: 5px;
font-size: 12px;
}
.box-one{
background-image: url("uploadir.com/u/nxa8310f");
background-repeat: no-repeat;
background-size: cover;
}
.index-image-text {
padding-bottom: 0;
margin-bottom: 0;
font-weight: bold;
color: white;
background-color: #2E3192;
}
HTML:
<div class="boxes img-rounded box-one grid-20">
<h1>Pottery Painting</h1>
<p class="index-image-text">
Testing<br>
</p>
</div>
It shows the little gap on both sides, but i want it all the way at the bottom of the div, and without the gap.
This is what it's showing:
https://sc-cdn.scaleengine.net/i/b4a1b72231a52f3a4977f68b76c0a7ad.png
this is what I want it to show:
https://sc-cdn.scaleengine.net/i/c66fe095c68250837b4b320c87bf72f0.png
any ideas? here's a fiddle: jsfiddle.net/kzaLx2vb/
May be this help.
HTML:
<div class="boxes img-rounded box-one grid-20">
<h1>Pottery Painting</h1>
<p class="index-image-text">Testing</p>
</div>
CSS:
body {
width: 300px;
}
.boxes {
margin-left: 4%;
margin-right: -4px;
height: 345px;
font-size: 12px;
}
.box-one{
background-image: url("http://uploadir.com/u/nxa8310f");
background-repeat: no-repeat;
background-size: cover;
}
.index-image-text {
padding-bottom: 0;
margin-bottom: 0;
position:relative;
top:75%;
font-weight: bold;
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
color: white;
background-color: #2E3192;
text-align: center;
padding-top: 10px;
}
h1 {
padding-top: 30px;
text-align: center;
color:#FFF;
}
JSFiddle: http://jsfiddle.net/5q354m3h/
A good way to achieve what you want is to give the box a relative style:
.box-one{
position:relative;
}
and then absolutely position your index-image-text
.index-image-text {
position:absolute;
bottom: 0;
left:0;
right:0;
}
http://jsfiddle.net/kzaLx2vb/11/
CSS:
.boxes {
margin-left: 4%;
margin-right: -4px;
height: 345px;
font-size: 12px;
/* addition code */
padding: 0; /*change your padding from 5px to 0*/
position: relative; /* set to relative to be the reference outter box */
border-radius: 10px; /* rounded corner based on the reference image */
overflow: hidden; /* to cut out for the bottom rounded corner */
max-width: 320px; /* this line not required*/
}
.box-one{
background-image: url("http://uploadir.com/u/nxa8310f");
background-repeat: no-repeat;
background-size: cover;
}
h1 {
color: #fff;
text-align: center;
}
.index-image-text {
padding-bottom: 0;
margin-bottom: 0;
font-weight: bold;
color: white;
background-color: #2E3192;
/* addition code */
margin: 0; /* override default padding value on "p" tag */
padding-top: 10px; /* spacing based on the reference image */
position: absolute; /* set to absolute to position within relative outter box */
bottom: 0; /* make the inner box stick to the bottom of outter box */
width: 100%; /* stretch the inner box to fill up outter box */
text-align: center; /* position based on the reference image */
font-family: verdana; /* font fammily based on the image */
}
Related
I am creating a website with a login and sign in feature, and want to place the buttons over a solid dark blue background above the gradient but below the buttons. When I try to create a shape, the buttons move down on the website to accommodate room for it, but I want the shape to be on a layer below the buttons but still visible. Is there any way of doing this in CSS?
If so, how? Thanks :)
Here is my CSS and HTML so far:
HTML:
html {
height: 100%;
background-size: cover;
background: #a5fcff;
background-repeat:no-repeat;
background: linear-gradient(#00033a, #a5fcff);
}
.signinbutton {
background-color: #458af9;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
display: block;
font-size: 75px;
margin: 4px 2px;
cursor: pointer;
transition-duration: 0.5s;
margin-left: auto;
margin-right: auto;
margin-top: 225px;
}
.signinbutton:hover {
background-color: #a7acb7;
}
.createaccbutton {
background-color: #458af9;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
display: block;
font-size: 75px;
margin: 4px 2px;
cursor: pointer;
transition-duration: 0.5s;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
}
.createaccbutton:hover {
background-color: #a7acb7;
}
<html>
<head>
<title>Debate Website</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class = "square"></div>
<button class = "signinbutton">SIGN IN</button>
<button class = "createaccbutton">SIGN UP</button>
</body>
</html>
UPDATE:
Sorry, I want the website screen to look like this:
Login Screen mock-up
But it currently looks like this:
Actual login screen so far
Use position: absolute; as mentioned above. If you end up with something on top of another (covering up the thing underneath) then you can use z-index: [number]; to specify what is on top of what.
You can position the element absolute relative to the html or another container.
example style:
.square {
position: absolute;
top: 0;
margin-left: auto;
height: 200px;
width: 200px;
background: #f00;
margin-right: auto;
left: 0;
right: 0;
}
Working example
1) First, edit your html, body style.
html {
height:100%
}
body {
background: #a5fcff;
background: linear-gradient(#00033a, #a5fcff); /* background first, followed by the other options */
background-size: cover;
background-repeat:no-repeat;
background-attachment: fixed /* for repeating gradient */
}
2) Customize .square element if you want.
.square {
position: absolute;
top:0; /* above the gradient */
left:0;margin-left:auto;right:0;margin-right:auto; /* center position:absolute element */
height: 200px;
width: 200px;
background: #0000ff
}
4) Add one margin line for buttons and remove others.
.signinbutton {
margin: 225px auto 0 auto; /* 225px for top, auto for right&left, 0px for bottom */
}
.createaccbutton {
margin: 100px auto 0 auto; /* 100px for top, auto for right&left, 0px for bottom */
}
I am building a navigation bar that has a lot of options and special sections.
I worked with Twitter Bootstrap, but it is difficult to develop.
The nav html tag has 3 sections grouped in 3 divs (left, center, right).
I am having difficulty in centring horizontally the text and logo of the company in left div, anchors with navigation items in the right div.
I need the height of navigation bar to be set in the CSS and not the calculate the height based of the child elements.
This is the html:
.navbar {
overflow: hidden; /* Clips from content if it is bigger than the parent element */
background-color: #333;
position: fixed; /* Position of the navbar is fixed */
top: 0;
width: 100%;
height: 50px;
}
.left-navbar {
float: left;
background: cadetblue;
width: 230px;
height: 100%;
text-align: center;
}
.right-navbar {
float: right;
background: maroon;
height: 100%;
/* float: right;
position: absolute;
top: 50%; right: 0%;
transform: translate(-50%,-50%);
background: gold;
padding: 1.5rem; */
}
.center-navbar {
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%,-50%);
background: gold;
padding: 1rem;
}
.left-navbar strong {
color: red;
padding: 10px 10px;
display:inline-block;
text-align: center;
vertical-align: center;
}
.left-navbar img {
width: 32px;
height: 32px;
padding: 10px 10px;
}
.navbar a {
float: right; /* Orientation of the element in the parent element */
display: block; /* All over top left right bottom it is a block - element has block/padding all over the embedded element */
color: #f2f2f2;
text-align: center;
padding: 14px 16px; /* 14px top and bottom, 16px right and left */
text-decoration: none; /* Could be underline, overline, line-through */
font-size: 17px;
}
/* Apply only for anchors inside the navbar class */
.navbar a:hover {
background: #ddd;
color: black;
}
input[type="text"]{ padding: 5px 5px; line-height: 28px; }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<nav class="navbar">
<div class="left-navbar">
<strong>Company</strong>
<img src="https://cdn0.iconfinder.com/data/icons/social-flat-rounded-rects/512/newsvine-512.png"></p>
</div>
<div class="center-navbar">
<input type="text" id="name" name="name" required height="45px;"
minlength="4" maxlength="40" size="40">
</div>
<div class="right-navbar">
Home
News
Contact
</div>
</nav>
Any working fiddle with best practices is ideal for me.
Thank you!
You can use flexbox to achieve this
.right-navbar, .left-navbar{
display: flex;
justify-content: center;
align-items: center;
}
Here you have a codepen, let me know if that help!
Give .left-navbar - horizontal and vertical centering with display:flex;
.left-navbar {
display: flex;
float: left;
background: cadetblue;
width: 230px;
height: 100%;
text-align: center;
justify-content: center;
align-items: center;
}
Also, how do you want the right part of the navbar?
Flex-box is what you'll want to use here. Add display: flex to the .navbar and then add flex-grow: 1; to the center piece. This essentially says 'make this element span the remaining space in the flex container. Also, your height: 100% were unnecessary, so I removed them.
.navbar {
overflow: hidden; /* Clips from content if it is bigger than the parent element */
background-color: #333;
position: fixed; /* Position of the navbar is fixed */
top: 0;
width: 100%;
height: 50px;
display: flex;
}
.left-navbar {
background: cadetblue;
width: 230px;
text-align: center;
}
.right-navbar {
background: maroon;
}
.center-navbar {
background: gold;
padding: 1rem;
flex-grow: 1;
}
input[type="text"]{
padding: 5px 5px;
line-height: 28px;
width: 100%;
box-sizing: border-box;
}
I want the text to shrink as the image shrinks. e.g. maintain the same ratio in size relative to the image. I've tried making the text disappear but it simply isn't what I want.
The CSS:
.header{
padding: 0.16px 16px;
position: relative;
box-sizing: inherit;
display: block;
font-size: 15px;
line-height: 1.5;
text-size-adjust: 100%;
content: "";
display: table;
clear: both;
font-family: "Montserrat", sans-serif;
}
.top-left{
padding: 24px 48px;
margin-left: 16%;
position: absolute;
left: 0px;
top: 0px;
box-sizing: inherit;
display:block;
font-size: 15px;
line-height: 22.5px;
text-size-adjust:100%;
}
.header-image{
vertical-align:middle;
border-style: none;
box-sizing: border-box;
width:65%;
height:auto;
margin:30px 250px;
}
#media screen and (max-width: 600px) {
.header-image {
margin-left: auto;
margin-right: auto;
display: block;
width:65%;
}
}
.new-arrivals{
position: absolute;
display:block;
left: 0;
top: 0;
margin:10px 5px 10px 0;
font-size: 4vw !important;
color:black;
padding: 50px 100px;
font-weight: 400;
line-height: 60px;
}
.shop-now{
border:none;
display:inline-block;
padding:12px 24px;
margin: 260px 50px;
vertical-align:middle;
overflow:hidden;
text-decoration:none;
color:white;
background-color:black;
text-align:center;
white-space: nowrap;
font-size: 18px
}
.shop-now:hover{
background-color: #ccc;
color: black;
border-style: ridge;
border-color: black;
border-width: 1px;
}
.designs{
position: absolute;
left: 0;
top: 0;
font-size: 20px !important;
font-family: "Montserrat", sans-serif;
margin: 150px 0;
color:black;
padding: 24px 100px;
font-weight: 400;
}
The HTML:
<div class="header">
<img class="header-image" src="img/jeans.jpg" alt="Jeans">
<div class="top-left">
<h1 class="new-arrivals">New arrivals</h1>
<p><h3 class="designs">Our new season collection is here</h3> </p>
<p>SHOP NOW</p>
</div>
</div>
If you want the text to be responsive as the image, you need to set h1 element style in your CSS file. For example:
.new-arrivals {
font-size:clamp(2em, 4vw, 4em); /* set min, ideal value, max */
}
I was trying to do the same thing for my portfolio. And I end up putting my text imbedded inside the image by using the ms paints. The text inside image can't be responsive if it's not of part of image. I hope that help.
You can accomplish this by setting both the width of the image and the font-size based on the width of the screen. Below is an example of that.
This question is similar, and the answers there may be helpful to you as well.
body {
margin: 0;
}
.container {
position: relative;
color: white;
width: fit-content;
}
.top-left {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 3vw;
}
img {
width: 100vw;
}
<div class="container">
<img src="https://html.com/wp-content/uploads/flamingo.jpg">
<div class="top-left">
<h1 class="new-arrivals">New arrivals</h1>
<h3 class="designs">Our new season collection is here</h3>
<p>SHOP NOW</p>
</div>
</div>
If you don't need the image to scale with the screen width, you can simply set a fixed pixel size for both the image and the text.
CSS for the Text:
.text {
font-size: 15vw;
}
CSS for the Image
img {
width: 10vw;
max-width: /* Set this to 10-15cm if you want to show you page on
mobiles too */
min-width: /* Set this to 8-10cm if you want to show you page on
mobiles too */
}
try these and adjust
font-size: clamp(1rem, 3vw, 2rem)
font-size: max(1rem, 3vw)
font-size: calc(200% + 2vw)
Have a div (really a header element) and I've seen many sites these days display text content perfectly centered within the container. So I'm trying it out, but so far, it's too far to the top of the div than the center. The example is here: http://jsfiddle.net/nuoxpmrk/
HTML:
<header class="entry-header" style="background: url(https://thecleverroot.com/wp-content/uploads/header-hudson-valley-foie-gras.jpg ) no-repeat top center!important; background-size: cover!important;">
<section class="entry-caption">
<h1 class="entry-title">Title Goes Here</h1><p class="entry-subtitle">This is a Subtitle</p> <p class="entry-credits">Written by: JS Fiddle</p>
</section>
</header>
CSS:
.entry-header { position: relative; width: 100%; height: 640px; color: #FFF; }
.entry-caption { margin: 15% auto 0; padding: 32px; text-align: center; width: 100%; }
.entry-caption p.entry-subtitle { font-size: 18px; line-height: 1.25; text-transform: none; }
.entry-caption h1.entry-title { font-size: 38px; line-height: 1.25; }
.entry-caption p.entry-credits { font-size: 14px; line-height: 1; margin-bottom: 1em; text-transform: uppercase; }
Your margin: 15% auto 0; is what is making it top. You need to wrap everything inside a <div> and give the following styles to this:
.entry-header {
position: relative;
width: 100%;
height: 640px;
color: #FFF;
}
.entry-caption {
padding: 32px;
text-align: center;
width: 100%;
}
.entry-caption p.entry-subtitle {
font-size: 18px;
line-height: 1.25;
text-transform: none;
}
.entry-caption h1.entry-title {
font-size: 38px;
line-height: 1.25;
}
.entry-caption p.entry-credits {
font-size: 14px;
line-height: 1;
margin-bottom: 1em;
text-transform: uppercase;
}
.center {
width: 100%;
height: 180px;
position: absolute;
top: 50%;
left: 0;
margin-top: -90px;
overflow: hidden;
}
<header class="entry-header" style="background: url(https://thecleverroot.com/wp-content/uploads/header-hudson-valley-foie-gras.jpg ) no-repeat top center!important; background-size: cover!important;">
<section class="entry-caption">
<div class="center">
<h1 class="entry-title">Title Goes Here</h1>
<p class="entry-subtitle">This is a Subtitle</p>
<p class="entry-credits">Written by: JS Fiddle</p>
</div>
</section>
</header>
You can keep this very simple with CSS Flexbox. You just need to add three lines of code, and you can get rid of a bunch of code, as well.
Regardless of screen re-sizing vertically or horizontally, the centered items will remain centered.
HTML (no changes)
CSS
.entry-header {
display: flex; /* establish flex container */
justify-content: center; /* center child element (<section>) horizontally */
align-items: center; /* center child element (<section>) vertically */
/* No further changes */
position: relative;
width: 100%;
height: 640px;
color: #FFF;
}
.entry-caption {
/* margin: 15% auto 0; don't need this */
/* padding: 32px; don't need this */
text-align: center;
/* width: 100%; don't need this */
}
DEMO: http://jsfiddle.net/nuoxpmrk/2/
Note that flexbox is supported by all major browsers, except IE < 10.
I am trying to align a horizontal rule with the white line in my menu. And I want that alignment to stay when viewed on different screens. What's my best option for doing that? Image of what it needs to look like:
* {
margin: 0;
}
#font-face {
font-family: jaapokkisubtract;
src: url('jaapokkisubtract.ttf');
}
body {
background-color: #ca3600;
}
#head {
height: 65px;
border-bottom: 3px solid white;
float: right;
width: 51%;
}
h1 {
color: white;
margin: 10px 0 0 10px;
font-family: jaapokkisubtract;
font-size: 50px;
float: left;
}
#work_btn {
display: block;
width: 96px;
height: 68px;
background: url(http://i.imgur.com/7m1Eh9j.gif) no-repeat 0 0;
overflow: hidden;
text-indent: -9999px;
float: right;
}
#work_btn:hover {
background-position: 0 -68px;
}
#resume_btn {
display: block;
width: 125px;
height: 68px;
background: url(http://i.imgur.com/x2eaW4T.gif) no-repeat 0 0;
overflow: hidden;
text-indent: -9999px;
float: right
}
#resume_btn:hover {
background-position: 0 -68px;
}
<h1>Alexander</h1>
<div id="menu">
<a id="resume_btn" href="resume.html" title="Resume">Resume</a>
<a id="work_btn" href="index.html" title="Work">Work</a>
<div id="head"></div>
</div>
You can achieve this by modifying slightly the CSS and HTML code, and using translation to move the menu items to the center of the screen.
To do this you need to:
Wrap everything in div with the border-bottom (e.g.: #head)
Float the page title (h1) to the left (although maybe it would be better to change its position to absolute or it may affect the menu links)
Wrap all the navigation elements in a div (e.g.: #menu) with absolute position positioned in the center of the #head (left:50%)
Transform the #menu div to translate it 50% of its width to the left. This could be achieved by adding this to its style:
transform:translate(-50%, 0%)
You can see a demo working here: http://jsfiddle.net/o4ff4thc/ or below:
* {
margin: 0;
}
#font-face {
font-family: jaapokkisubtract;
src: url('jaapokkisubtract.ttf');
}
body {
background-color: #ca3600;
}
#head {
height: 65px;
border-bottom: 3px solid white;
}
h1 {
color: white;
margin: 10px 0 0 10px;
font-family: jaapokkisubtract;
font-size: 50px;
float: left;
}
#work_btn {
display: inline-block;
width: 96px;
height: 68px;
background: url(http://i.imgur.com/7m1Eh9j.gif) no-repeat 0 0;
overflow: hidden;
text-indent: -9999px;
}
#work_btn:hover {
background-position: 0 -68px;
}
#resume_btn {
display:inline-block;
width: 125px;
height: 68px;
background: url(http://i.imgur.com/x2eaW4T.gif) no-repeat 0 0;
overflow: hidden;
text-indent: -9999px;
}
#resume_btn:hover {
background-position: 0 -68px;
}
#menu {
position:absolute;
left:50%;
transform:translate(-50%,0%);
height:20px;
width:245px;
}
<div id="head">
<h1>Alexander</h1>
<div id="menu">
<a id="resume_btn" href="resume.html" title="Resume">Resume</a>
<a id="work_btn" href="index.html" title="Work">Work</a>
</div>
</div>