Centering div in CSS (WP theme development and PHP) - php

I'm currently developing a wordpress theme with PHP, but my problem is with the css. I have tree divs, which i have inside a parent div. The parents div is by default 100%, so i want to specify the parent div (class: "single-general-sec1"). I've tried to calculate how wide the parent div should be in order for me to center it, but my calculations do not work. Please help.
Parent div should, by my calculation, be: 61% + 425px, but that dosen't work.
.single-general-sec1 {
margin-top: 150px;
margin-bottom: 150px;
height: auto;
width: calc(61% + 425px);
background-color: red;
}
.single-btype-div {
width: 250px;
display: inline-block;
float: left;
}
.single-gen-header {
font-size: 14px;
color: #D9D9D9;
font-family: "Roboto";
font-weight: 700;
text-transform: uppercase;
letter-spacing: 3px;
margin: 0;
width: auto;
}
.single-gen-desc {
color: #000;
font-family: "Roboto";
font-size: 28px;
font-weight: 300;
letter-spacing: 3px;
margin: 0;
width: auto;
margin-top: 5px;
}
.single-description-div {
width: 55%;
display: inline-block;
margin-left: 3%;
float: left;
}
.single-description-desc {
color: #000;
font-family: "Roboto";
font-size: 20px;
font-weight: 300;
letter-spacing: 1px;
margin: 0;
width: auto;
margin-top: 5px;
}
.single-live-button {
margin-top: 5px;
width: 175px;
height: 40px;
background-color: #8AA6B6;
border-radius: 8px;
border: none;
color: #fff;
font-size: 15px;
font-family: "Roboto";
font-weight: 300;
letter-spacing: 2px;
text-transform: uppercase;
}
.single-live-div {
width: 100px;
display: inline-block;
margin-left: 3%;
}
<div class="single-general-sec1">
<div class="single-btype-div">
<p class="single-gen-header"> - Typ av projekt </p>
<p class="single-gen-desc">
<?php the_field('project-type'); ?> </p>
</div>
<div class="single-description-div">
<p class="single-gen-header"> - Beskrivning </p>
<p class="single-description-desc">
<?php the_field('description'); ?> </p>
</div>
<div class="single-live-div">
<p class="single-gen-header"> - Se live </p>
<a href="<?php the_field('page-url') ?>"><button class="single-live-button">
Besök sida > </button></a>
</div>
</div>

You cannot center a div using % values for width. Also the calculation is wrong: 250px + 175px + 100px = 525px so, the parent div should be 525px in order to fit nested divs. But you should normalize HTML first. Or just use bootstrap.css.
Another thing. For center a div you can use display:inline-block then on his parent use text-align:center.
Or when you have a fixed width, margin:50px auto;

Related

Whole div a clickable link [duplicate]

This question already has answers here:
Make a div into a link
(30 answers)
Closed 2 years ago.
I am trying to get my whole div a clickable link but I am not sure the correct way to do it. Would anyone be able to help me with this, it would be greatly appreciated. I am new to coding so I am still learning proper coding. Thanks.
.container {
display: flex;
margin: auto;
width: 1052px;
}
.container>div {
background-color: #ffffff;
border: 1px solid #aaaaaa;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
flex: 1;
/*grow*/
height: 210px;
margin: 45px 10px 0px 10px;
width: 231px;
}
.container img {
height: 140px;
width: 241px;
}
.container>div a {
color: #353748;
display: block;
font-family: Netflix Sans, Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 20px;
padding: 5px 10px 5px 10px;
text-decoration: none;
text-overflow: ellipsis;
text-transform: initial;
}
.container>div a:hover {
color: #353748;
display: block;
font-family: Netflix Sans, Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 20px;
padding: 5px 10px 5px 10px;
text-decoration: underline;
text-overflow: ellipsis;
text-transform: initial;
}
<div class="container">
<div>
<img src="https://capebretonstartpage.com/1/wire-31023566-1595346165-638_636x382.jpg">
About vAdd An Image Add An Image
</div>
<div>
<img src="https://capebretonstartpage.com/1/wire-31023566-1595346165-638_636x382.jpg">
About vAdd An Image Add An Image
</div>
<div>
<img src="https://capebretonstartpage.com/1/wire-31023566-1595346165-638_636x382.jpg">
About vAdd An Image Add An Image
</div>
</div>
You can put the div inside an <a> tag

How to add space between menu elements (in wordpress)?

I am working in wordpress and I have this menu with 4 menu items.
The problem is that they are touching each other and there is 0
space between which makes it ugly in my opinion.
Now this problem only
occurs in wordpress. So I have to find a solution how to put some space between.
Maybe you guys know a solution without having to install something on WP.
(the codes in the body is exactly as in my wordpress to demonstrate how it looks like. You can enter it and that will put some space between, but unfortunately that doesn't work in wordpress.)
<style>
.smallmenu {
margin: 0 auto;
max-width: 436px;
width: 100%;
}
.Capital {
margin: 0px 0 -5px 0;
line-height: 63px;
font-size: 60px;
font-weight: ligter;
}
.smalltext {
text-align: center;
margin-top: 0px !important;
font-weight: 100px;
font-size: 14px;
}
.smalltextpub {
text-align: center;
margin-top: 0px !important;
font-weight: 100px;
font-size: 14px;
margin-left: -5px;
}
.cornermenu {
display: inline-block;
margin: auto;
border-radius: 25px;
background: #769DBD;
padding: 20px;
width: 100px;
height: 100px;
text-align: center;
color: #fff;
font-family: Arial;
padding-top: 10px;
text-decoration: none;
}
#hoverr:hover {
border-radius: 25px;
background: #464646;
padding: 20px;
width: 100px;
height: 100px;
text-align: center;
color: #fff;
font-family: Arial;
padding-top: 10px;
text-decoration: none;
}
* {
box-sizing: border-box;
}
</style>
<div class="smallmenu"><a id="hoverr" class="cornermenu" href="#methods"><span class="Capital">M</span>
<span class="smalltext">Methods</span></a><a id="hoverr" class="cornermenu" href="#background"><span class="Capital">B</span>
<span class="smalltextpub">Background</span></a><a id="hoverr" class="cornermenu" href="#results"><span class="Capital">R</span>
<span class="smalltext">Results</span></a><a id="hoverr" class="cornermenu" href="#publications"><span class="Capital">P</span>
<span class="smalltextpub">Publications</span></a></div>
Just set a fixed margin on .cornermenu.
Something like margin: 2px
JSFiddle link
.cornermenu {
...
margin: 2px;
...
}

Text inside of link aligns incorrectly in WordPress but is fine in HTML

As you can see in the images, the text "English" isn't vertically centered in the WordPress version of the site I'm building but with the same code as I used in the HTML version it works perfectly. Any ideas why?
HTML
<div class="right-bar">
<a class="language">
<img src="img/flags/EN-us.png" alt="English / US">
<span>English</span>
</a>
<a class="search-btn">
<i class="fa fa-search"></i>
</a>
</div>
SASS
.right-bar {
background: #1f1f1f;
float: right;
height: 100%;
padding: 32px 20px 0;
position: relative;
&::after {
position: absolute;
top: 0;
right: 100%;
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 0 98px 83px;
border-color: transparent transparent #1f1f1f;
}
.language {
border: 1px solid #363636;
border-radius: 40px;
color: #898989;
display: block;
float: left;
height: 34px;
font-size: 10px;
font-weight: 700;
line-height: 30px;
padding: 0 20px;
position: relative;
text-transform: uppercase;
z-index: 99;
}
.search-btn {
float: left;
display: block;
margin: 0 0 0 30px;
color: #fff;
font-size: 26px;
font-weight: 400;
transition: color .2s;
&:active {
color:#8eb82f;
}
}
}
SCSS
.language{
img{
vertical-align:middle;
}
}
This may help you.

How to add 2 to the current value at every one minute?

My HTML and CSS code is here. Every no. is in diffrent span tag.
I need like 152,242 after 1 minute, 152,244 after 2 minutes and so on. I was trying to do it with jquery but i did not get the perfect output.
#hp_header .number{
display: inline-block;
width: 100%;
text-align: center;
margin-top: 40px;
}
#hp_header .number .number_inner{
display: inline-block;
text-align: center;
color: #282828;
font-family: SourceSansPro-Regular !important;
font-size: 32px;
}
#hp_header .number .count{
font-family: SourceSansPro-Regular !important;
font-size: 32px;
color: #f0f1b4;
padding: 5px 10px;
background-color: #282828;
margin: 0px 5px;
}
#hp_header .number .members_count {
width: 100%;
float: left;
margin-top: 10px;
color: #282828;
font-family: SourceSansPro-Regular !important;
text-transform: uppercase;
letter-spacing: 5px;
}
<div id="hp_header">
<span class="number">
<span class="number_inner">
<span class="count">1</span>
<span class="count">5</span>
<span class="count">2</span>
,
<span class="count">2</span>
<span class="count">4</span>
<span class="count">2</span>
</span>
</span>
</div>
Thanks in advance.
Hope below code will help you. For testing i put 2 seconds interval(2000). You can make it (60000) for each minute
setInterval(oneSecondFunction, 2000);
function oneSecondFunction() {
total = document.getElementsByClassName('count').length;
values = document.getElementsByClassName('count');
current_value='';
for(i=0;i<total;i++)
{
current_value+=values[i].innerHTML;
}
new_value = parseInt(current_value)+2;
new_value_string=new_value.toString();
for(j=0;j<new_value_string.length;j++)
{
values[j].innerHTML = new_value_string[j];
}
}
#hp_header .number{
display: inline-block;
width: 100%;
text-align: center;
margin-top: 40px;
}
#hp_header .number .number_inner{
display: inline-block;
text-align: center;
color: #282828;
font-family: SourceSansPro-Regular !important;
font-size: 32px;
}
#hp_header .number .count{
font-family: SourceSansPro-Regular !important;
font-size: 32px;
color: #f0f1b4;
padding: 5px 10px;
background-color: #282828;
margin: 0px 5px;
}
#hp_header .number .members_count {
width: 100%;
float: left;
margin-top: 10px;
color: #282828;
font-family: SourceSansPro-Regular !important;
text-transform: uppercase;
letter-spacing: 5px;
}
<div id="hp_header">
<span class="number">
<span class="number_inner">
<span class="count">1</span>
<span class="count">5</span>
<span class="count">2</span>
,
<span class="count">2</span>
<span class="count">4</span>
<span class="count">2</span>
</span>
</span>
</div>

Previously i have added color: red to my code, however i have deleted it, but it still shows on my web

Previously i have added color red to my css code. However, i have deleted the code. But the red still remain on the web. What should i do? This is the html on my php file.
echo " <div class='toship-info'>
<div class='toship-header'>Deliver to: </div>
<div class='toship-content'>
<div class='toship-att'>Name : </div>
<div class='toship-data'>$ship_name</div>
<div class='toship-att'>Address : </div>
<div class='toship-data'>$ship_address</div>
<div class='toship-att'>Contact No : </div>
<div class='toship-data'>$ship_contact</div>
<div class='toship-att'>Email : </div>
<div class='toship-data'>$ship_email</div>
<br><strong>*If there is any inquiries please contact our Apex Store at
+6(04)-3901025. </strong></br>
</div>
</div>
";
This is my css file. How should i change it?
.toship-info{
width: 600px;
margin: auto;
}
.toship-header{
background: rgb(63,63,63);
color: white;
font-size: 14px;
font-weight: bold;
height: 24px;
line-height: 24px;
padding-left: 15px;
}
.toship-content{
background: rgb(238,238,238);
height: 130px;
padding-top: 10px;
}
.toship-att{
width: 100px;
text-align: left;
font-size: 12px;
font-weight: bold;
padding: 3px;
float: left;
box-sizing: border-box;
}
.toship-data{
width: 500px;
padding: 3px;
font-weight: bold;
font-size: 12px;
float: left;
box-sizing: border-box;
}
.toship-item{
width: 600px;
margin: auto;
margin-bottom: 20px;
}
.toship-item-header{
background: rgb(63,63,63);
color: white;
font-size: 14px;
font-weight: bold;
height: 24px;
line-height: 24px;
margin-bottom: 0px;
padding: 0;
margin: 0;
[![enter image description here][1]][1]}
Try to open in other browser, or if you are using any framework or cms then clear view cache.
Your browser probably cached the page. Try to clean your history/cache. How to do this depends on the browser you are using. For example, in Chrome you will go to History > History > Clear navigation data... > Image and files stored in cache. Also, as #rrd said in comments, in most browsers (Chrome included) Ctrl+R will reload the actual page and not the cached one.
Ctrl-F5 will do the trick. It's in the browser cache. Ctrl-F5 will ask for a complete new request and hence avoid the cache.
When i use the below code i don't see any red text
<style>
.toship-info {
width: 600px;
margin: auto;
}
.toship-header {
background: rgb(63, 63, 63);
color: white;
font-size: 14px;
font-weight: bold;
height: 24px;
line-height: 24px;
padding-left: 15px;
}
.toship-content {
background: rgb(238, 238, 238);
height: 130px;
padding-top: 10px;
}
.toship-att {
width: 100px;
text-align: left;
font-size: 12px;
font-weight: bold;
padding: 3px;
float: left;
box-sizing: border-box;
}
.toship-data {
width: 500px;
padding: 3px;
font-weight: bold;
font-size: 12px;
float: left;
box-sizing: border-box;
}
.toship-item {
width: 600px;
margin: auto;
margin-bottom: 20px;
}
.toship-item-header {
background: rgb(63, 63, 63);
color: white;
font-size: 14px;
font-weight: bold;
height: 24px;
line-height: 24px;
margin-bottom: 0px;
padding: 0;
margin: 0;
</style>
</head>
<body>
<div class='toship-info'> "
<div class='toship-header'>Deliver to: </div>
<div class='toship-content'>
<div class='toship-att'>Name : </div>
<div class='toship-data'>$ship_name</div>
<div class='toship-att'>Address : </div>
<div class='toship-data'>$ship_address</div>
<div class='toship-att'>Contact No : </div>
<div class='toship-data'>$ship_contact</div>
<div class='toship-att'>Email : </div>
<div class='toship-data'>$ship_email</div>
<br>
<strong>*If there is any inquiries please contact our Apex Store at
+6(04)-3901025. </strong>
<br />
</div>
</div>
</body>
Please make sure you markup your HTML properly..
was incorrectly marked up

Categories